16 |
16 |
|
17 |
17 |
from contextlib import contextmanager
|
18 |
18 |
|
19 |
|
from quixote import get_request, get_publisher
|
|
19 |
from quixote import get_publisher
|
20 |
20 |
from quixote.html import htmltext, TemplateIO
|
21 |
21 |
|
22 |
22 |
|
... | ... | |
25 |
25 |
try:
|
26 |
26 |
return func(*args, **kwargs)
|
27 |
27 |
finally:
|
28 |
|
Substitutions.invalidate_cache()
|
|
28 |
get_publisher().substitutions.invalidate_cache()
|
29 |
29 |
return f
|
30 |
30 |
|
31 |
31 |
|
... | ... | |
92 |
92 |
self.sources = orig_sources
|
93 |
93 |
self.invalidate_cache()
|
94 |
94 |
|
95 |
|
@classmethod
|
96 |
|
def invalidate_cache(cls):
|
97 |
|
request = get_request()
|
|
95 |
def invalidate_cache(self):
|
98 |
96 |
for value in (True, False):
|
99 |
|
if hasattr(request, '_cache_context_variables%r' % value):
|
100 |
|
delattr(request, '_cache_context_variables%r' % value)
|
|
97 |
if hasattr(self, '_cache_context_variables%r' % value):
|
|
98 |
delattr(self, '_cache_context_variables%r' % value)
|
101 |
99 |
|
102 |
100 |
def get_context_variables(self, mode=None):
|
103 |
101 |
if self._forced_mode:
|
104 |
102 |
mode = self._forced_mode
|
105 |
103 |
lazy = mode in get_publisher().get_lazy_variables_modes() if mode else False
|
106 |
|
request = get_request()
|
107 |
|
d = getattr(request, '_cache_context_variables%r' % lazy, None)
|
|
104 |
d = getattr(self, '_cache_context_variables%r' % lazy, None)
|
108 |
105 |
if d is not None:
|
109 |
106 |
return d
|
110 |
107 |
d = CompatibilityNamesDict()
|
... | ... | |
112 |
109 |
d.update(source.get_substitution_variables())
|
113 |
110 |
if not lazy and hasattr(source, 'get_static_substitution_variables'):
|
114 |
111 |
d.update(source.get_static_substitution_variables())
|
115 |
|
if request:
|
116 |
|
setattr(request, '_cache_context_variables%r' % lazy, d)
|
|
112 |
setattr(self, '_cache_context_variables%r' % lazy, d)
|
117 |
113 |
return d
|
118 |
114 |
|
119 |
115 |
@classmethod
|
120 |
|
-
|