Skip to content

Commit

Permalink
listing all template viariables AA-730
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoor committed Jan 26, 2015
1 parent 1a4f716 commit 1ae5509
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions basic_email/views.py
Expand Up @@ -2,6 +2,7 @@
import os
import tempfile
import shutil
import re

from django.template.loader import render_to_string
from django.views.generic import TemplateView
Expand Down Expand Up @@ -54,7 +55,6 @@ def get_template_names(self, *args, **kwargs):
return [self.get_template()]

def content_encode(self, content):
content = content.replace('{{', '{##_')
to_replace = "{{% extends '{dir}/".format(dir=settings.BASIC_EMAIL_DIRECTORY)
replacer = "{{#_extends '{dir}/".format(dir=self.sub_tmp_dir)
content = content.replace(to_replace, replacer)
Expand All @@ -65,7 +65,7 @@ def content_encode(self, content):
content = content.replace('{% block ', '{#_block ')
content = content.replace('{% endblock ', '{#_endblock ')
content = content.replace('{%', '{#_')
content = content.replace('{{', '{##_')
content = content.replace('{{', '{##_ ')
content = content.replace('{#_extends', '{% extends')
content = content.replace('{#_block ', '{% block ')
content = content.replace('{#_endblock ', '{% endblock ')
Expand Down Expand Up @@ -95,8 +95,10 @@ def list_template_variables(self):
self.prepare_tmp_files(tmp_dir)
file_name = self.get_template().replace(settings.BASIC_EMAIL_DIRECTORY, self.sub_tmp_dir)
content = render_to_string(file_name)
print (content)
regexp = re.compile('(?<={##_ )\w+')
variables = regexp.findall(content)
shutil.rmtree(tmp_dir) # careful! removes whole tree.
return variables


class PreviewEmailView(ListEmailVariables):
Expand Down

0 comments on commit 1ae5509

Please sign in to comment.