-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.template.loaders.cached import Loader | ||
from .templatetags.djedi_tags import DjediNode | ||
|
||
|
||
class DjediRefresherMixin(object): | ||
""" | ||
This mixin automatically refreshes each Djedi node for every | ||
loaded template. Comes very handy in combination with caching template | ||
loaders (ie `django.template.loaders.cached.Loader`). | ||
""" | ||
def load_template(self, template_name, template_dirs=None): | ||
template, origin = super(DjediRefresherMixin, self).load_template( | ||
template_name, template_dirs) | ||
djedi_nodes = template.nodelist.get_nodes_by_type(DjediNode) | ||
map(lambda n: n.reload_node(), djedi_nodes) | ||
return template, origin | ||
|
||
|
||
class DjediCachedLoader(DjediRefresherMixin, Loader): | ||
""" | ||
Standard Django cached template loader with support for Djedi nodes. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters