Skip to content

Commit

Permalink
implements caching
Browse files Browse the repository at this point in the history
  • Loading branch information
LGD-Fr committed Oct 10, 2015
1 parent a1362b5 commit 476ad9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 10 additions & 2 deletions modular_blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ class TemplateTagBlock(object):
name = None
module = None

def __init__(self, name=None, cache_time=None, library=None, tag=None,
kwargs={}):
def __init__(
self,
name=None,
cache_time=3,
library=None,
tag=None,
personal=True,
kwargs={}
):
self.name = name
self.cache_time = cache_time
self.library = library
self.tag = tag
self.kwargs = kwargs
self.personal = personal

def title(self):
try:
Expand Down
13 changes: 11 additions & 2 deletions modular_blocks/templatetags/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ def render(self, context):
kwargs = ' '.join(
'{!s}={!s}'.format(key, val) for key, val in block.kwargs.items()
)
tpl = template.Template(
'{{% load {library} %}}{{% {tag} {kwargs} %}}'.format(
if block.personal:
string = '{{% load cache %}}{{% load {library} %}}\
{{% cache {cache_time} {slug} request.user.username %}}\
{{% {tag} {kwargs} %}}{{% endcache %}}'
else:
string = '{{% load cache %}}{{% load {library} %}}\
{{% cache {cache_time} {slug} %}}\
{{% {tag} {kwargs} %}}{{% endcache %}}'
tpl = template.Template(string.format(
library=block.library,
cache_time=block.cache_time,
slug=block.tag,
tag=block.tag,
kwargs=kwargs,
)
Expand Down

0 comments on commit 476ad9d

Please sign in to comment.