Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't render templates if the template tag is blank #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scribbler/templatetags/scribbler_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
TOKEN_BLOCK = template_base.TOKEN_BLOCK
TOKEN_COMMENT = template_base.TOKEN_COMMENT

wrapper_template = template.loader.get_template('scribbler/scribble-wrapper.html')
blank_scribble = wrapper_template.render({})

register = template.Library()

Expand Down Expand Up @@ -71,10 +73,7 @@ def render(self, context):
else:
scribble_template = template.Template(self.raw)
scribble_context = build_scribble_context(scribble)
content = scribble_template.render(scribble_context, request)
wrapper_template = template.loader.get_template('scribbler/scribble-wrapper.html')
context['scribble'] = scribble
context['rendered_scribble'] = content
user = context.get('user', None)
show_controls = False
can_edit = False
Expand All @@ -92,6 +91,10 @@ def render(self, context):
context['can_edit_scribble'] = can_edit
context['can_delete_scribble'] = can_delete
context['raw_content'] = self.raw
if not bool(scribble.content.strip()) and not (can_edit or can_add):
return blank_scribble # Don't bother to render blank scribble
content = scribble_template.render(scribble_context, request)
context['rendered_scribble'] = content
# render() takes a dict, so we have to extract the context dict from the object
context_data = context.dicts[-1]
return wrapper_template.render(context_data, request)
Expand Down