Skip to content

Instantly share code, notes, and snippets.

@chronossc
Last active September 10, 2018 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chronossc/7b54567ff8b6f1835cd0272c38b4c12d to your computer and use it in GitHub Desktop.
Save chronossc/7b54567ff8b6f1835cd0272c38b4c12d to your computer and use it in GitHub Desktop.
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _
class MessageryConfig(AppConfig):
name = 'messagery'
label = 'messagery'
verbose_name = _("Messages and E-mails management")
In [34]: settings.INSTALLED_APPS
Out[34]:
['django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'rest_framework',
'mongo_sync',
'movies',
'messagery']
In [39]: !ls /app/manage.py /app/messagery/templates/email/base_email_template.html
/app/manage.py /app/messagery/templates/email/base_email_template.html
In [40]: settings.TEMPLATES
Out[40]:
[{'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {'context_processors': ['django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages']}}]
❯ tatu-manage shell -i python
Python 3.6.6 (default, Aug 22 2018, 20:48:31)
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.template import Engine, Context
>>> from messagery.models import Email
>>> from movies.models import Film
>>> email = Email.objects.get(name='confirm_screening_date')
>>> film = Film.objects.get(title='DETOX SP')
>>> html = email.get_html_for_film(film)
>>> html
'{% extends "email/base_email_template.html" %}\r\n{% block text %}\r\n<p>Oi, {{ambassador.profile.name}},</p>\r\n<p>Como estão os preparativos para a sua sessão do {{movie.title}} no dia {{screening.date|date:"d/m/Y"}}? Ela está de fato confirmada?</p>\r\n<p>Por favor, confira se todas as informações estão corretas. Se houver qualquer alteração, você pode editá-la na sua própria página na plataforma: <a href="{{absoluteurl}}ambassador">{{absoluteurl}}ambassador</a></p>\r\n<p>Abraços,</p>\r\n<p>Equipe Taturana</p>\r\n{% endblock %}'
>>> Engine().from_string(html).render(Context())
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py", line 127, in render
compiled_parent = self.get_parent(context)
File "/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py", line 124, in get_parent
return self.find_template(parent, context)
File "/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py", line 104, in find_template
template_name, skip=history,
File "/usr/local/lib/python3.6/site-packages/django/template/engine.py", line 130, in find_template
raise TemplateDoesNotExist(name, tried=tried)
django.template.exceptions.TemplateDoesNotExist: email/base_email_template.html
In [26]: from django.template import Engine, Context
In [27]: email = Email.objects.get(name='confirm_screening_date')
In [28]: film = Film.objects.get(title='DETOX SP')
In [29]: html = email.get_html_for_film(film)
In [30]: html
Out[30]: '{% extends "email/base_email_template.html" %}\r\n{% block text %}\r\n<p>Oi, {{ambassador.profile.name}},</p>\r\n<p>Como estão os preparativos para a sua sessão do {{movie.title}} no dia {{screening.date|date:"d/m/Y"}}? Ela está de fato confirmada?</p>\r\n<p>Por favor, confira se todas as informações estão corretas. Se houver qualquer alteração, você pode editá-la na sua própria página na plataforma: <a href="{{absoluteurl}}ambassador">{{absoluteurl}}ambassador</a></p>\r\n<p>Abraços,</p>\r\n<p>Equipe Taturana</p>\r\n{% endblock %}'
In [31]: Engine().from_string(html).render(Context())
---------------------------------------------------------------------------
TemplateDoesNotExist Traceback (most recent call last)
<ipython-input-31-a294f767064e> in <module>()
----> 1 Engine().from_string(html).render(Context())
/usr/local/lib/python3.6/site-packages/django/template/base.py in render(self, context)
169 with context.bind_template(self):
170 context.template_name = self.name
--> 171 return self._render(context)
172 else:
173 return self._render(context)
/usr/local/lib/python3.6/site-packages/django/template/base.py in _render(self, context)
161
162 def _render(self, context):
--> 163 return self.nodelist.render(context)
164
165 def render(self, context):
/usr/local/lib/python3.6/site-packages/django/template/base.py in render(self, context)
935 for node in self:
936 if isinstance(node, Node):
--> 937 bit = node.render_annotated(context)
938 else:
939 bit = node
/usr/local/lib/python3.6/site-packages/django/template/base.py in render_annotated(self, context)
902 """
903 try:
--> 904 return self.render(context)
905 except Exception as e:
906 if context.template.engine.debug and not hasattr(e, 'template_debug'):
/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py in render(self, context)
125
126 def render(self, context):
--> 127 compiled_parent = self.get_parent(context)
128
129 if BLOCK_CONTEXT_KEY not in context.render_context:
/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py in get_parent(self, context)
122 # parent is a django.template.backends.django.Template
123 return parent.template
--> 124 return self.find_template(parent, context)
125
126 def render(self, context):
/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py in find_template(self, template_name, context)
102 )
103 template, origin = context.template.engine.find_template(
--> 104 template_name, skip=history,
105 )
106 history.append(origin)
/usr/local/lib/python3.6/site-packages/django/template/engine.py in find_template(self, name, dirs, skip)
128 except TemplateDoesNotExist as e:
129 tried.extend(e.tried)
--> 130 raise TemplateDoesNotExist(name, tried=tried)
131
132 def from_string(self, template_code):
TemplateDoesNotExist: email/base_email_template.html
In [32]: !ls -l /app/messagery/templates/email/base_email_template.html
-rw-rw-r-- 1 1000 1000 869 Sep 10 00:43 /app/messagery/templates/email/base_email_template.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment