Mercurial > piecrust2
annotate piecrust/data/piecrustdata.py @ 730:8c3c2b949b82
routing: Fix problems with route functions.
Instead of using merged functions with multiblog sites, use different
functions. Add some options to customize the function names.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Wed, 01 Jun 2016 22:10:47 -0700 |
| parents | 93b656f0af54 |
| children | f71d576835ee |
| rev | line source |
|---|---|
|
440
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import logging |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from piecrust import APP_VERSION |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from piecrust.data.debug import build_debug_info |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 logger = logging.getLogger(__name__) |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 class PieCrustData(object): |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 debug_render = ['version', 'url', 'branding', 'debug_info'] |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 debug_render_invoke = ['version', 'url', 'branding', 'debug_info'] |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 debug_render_redirect = {'debug_info': '_debugRenderDebugInfo'} |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 def __init__(self): |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 self.version = APP_VERSION |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 self.url = 'http://bolt80.com/piecrust/' |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 self.branding = 'Baked with <em><a href="%s">PieCrust</a> %s</em>.' % ( |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 'http://bolt80.com/piecrust/', APP_VERSION) |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 self._page = None |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 @property |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 def debug_info(self): |
|
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
440
diff
changeset
|
23 if self._page is not None: |
|
440
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 try: |
|
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
440
diff
changeset
|
25 return build_debug_info(self._page) |
|
440
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 except Exception as ex: |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 logger.exception(ex) |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 return ('An error occured while generating debug info. ' |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 'Please check the logs.') |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 return '' |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 |
|
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
440
diff
changeset
|
32 def enableDebugInfo(self, page): |
|
440
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 self._page = page |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 def _debugRenderDebugInfo(self): |
|
32c7c2d219d2
performance: Refactor how data is managed to reduce copying.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 return "The very thing you're looking at!" |
