def _template(self, content): context = Context({}) context.autoescape = self.filetype == 'html' return DjangoTemplate(content).render(context)
else: django_template = DjangoTemplate("""\ <!doctype html> <html> <head> <title>{{ page_title }}</title> </head> <body> <div class="header"> <h1>{{ page_title }}</h1> </div> <ul class="navigation"> {% for href, caption in navigation %} <li><a href="{{ href }}">{{ caption }}</a></li> {% endfor %} </ul> <div class="table"> <table> {% for row in table %} <tr> {% for cell in row %} <td>{{ cell }}</td> {% endfor %} </tr> {% endfor %} </table> </div> </body> </html>\ """)
def send_email_message(self, recipient_email, category, message_context={}, html_base_template=None): category_settings = get_category_settings_for_user( recipient_email, category) if category_settings.can_email() == False: #User has opted out return receipt_model = get_model_by_label(settings.EMAIL_RECEIPT_MODEL) receipt = receipt_model.create_receipt(recipient_email, category) message_context['email'] = recipient_email message_context['receipt'] = receipt message_context['category'] = category message_context['subscription_settings'] = category_settings.parent message_context['category_subscription_settings'] = category_settings message_context['settings'] = settings message_context['site'] = Site.objects.get_current() message_context['site_url'] = 'https://%s' % (Site.objects.get_current( )) if settings.USE_SSL else 'http://%s' % (Site.objects.get_current()) if html_base_template == None: model = get_model_by_label(settings.TEMPLATE_MODEL) try: html_base_template_object = model.objects.get( slug=settings.DEFAULT_EMAIL_TEMPLATE_SLUG) html_base_template = DjangoTemplate( html_base_template_object.get_content()) except: raise ImproperlyConfigured( "Default Email template not found. Please check your DEFAULT_EMAIL_TEMPLATE setting." ) # -- Render the Subject of the Email subject_template = DjangoTemplate(self.subject_template) subject = subject_template.render(Context(message_context)) subject = ' '.join(subject.split()) #Remove whitespace, newlines, etc # -- Render the Body of the Email body_template = DjangoTemplate(self.body_template) body = body_template.render(Context(message_context)) message = _totext(body) # -- Render the Template message_context['subject'] = subject message_context['body'] = body message_html = html_base_template.render(Context(message_context)) receipt.rendered(subject, message_html) # -- Send Message try: _send(recipient_email, subject, message, unicode(message_html)) except smtplib.SMTPException: print "WARNING: ERROR SENDING EMAIL MESSAGE" receipt.record_error(traceback.format_exc())
def body(self): ctx = Context(self.get_template_vars()) s = DjangoTemplate(self.alarm_class.body_template).render(ctx) return s
def format_subject(self, context): t = DjangoTemplate(html.unescape(self.get_subject())) return t.render(Context(context))
def format_body(self, context={}): template = DjangoTemplate(self.body) return template.render(Context(context))
def render_body(self, LANG=None, **kwargs): return DjangoTemplate(self.body).render(Context(kwargs))
def render(self, context): return DjangoTemplate(self.content).render(context)
def __init__(self, sbj, body, log_tpl): self.subject = DjangoTemplate(sbj) self.body = DjangoTemplate(body) self.log_tpl = DjangoTemplate(log_tpl)
def render_subject(self, LANG=None, **kwargs): return DjangoTemplate(self.subject).render(Context(kwargs))
def populate_feed(self, feed, items, request): """Populates a :class:`django.utils.feedgenerator.DefaultFeed` instance as is returned by :meth:`get_feed` with the passed-in ``items``.""" if self.item_title_template: title_template = DjangoTemplate(self.item_title_template.code) else: title_template = None if self.item_description_template: description_template = DjangoTemplate( self.item_description_template.code) else: description_template = None node = request.node try: current_site = Site.objects.get_current() except Site.DoesNotExist: current_site = RequestSite(request) if self.feed_length is not None: items = items[:self.feed_length] for item in items: if title_template is not None: title = title_template.render( RequestContext(request, {'obj': item})) else: title = self.__get_dynamic_attr('item_title', item) if description_template is not None: description = description_template.render( RequestContext(request, {'obj': item})) else: description = self.__get_dynamic_attr('item_description', item) link = node.construct_url(self.reverse(obj=item), with_domain=True, request=request, secure=request.is_secure()) enc = None enc_url = self.__get_dynamic_attr('item_enclosure_url', item) if enc_url: enc = feedgenerator.Enclosure( url=smart_unicode( add_domain(current_site.domain, enc_url, request.is_secure())), length=smart_unicode( self.__get_dynamic_attr('item_enclosure_length', item)), mime_type=smart_unicode( self.__get_dynamic_attr('item_enclosure_mime_type', item))) author_name = self.__get_dynamic_attr('item_author_name', item) if author_name is not None: author_email = self.__get_dynamic_attr('item_author_email', item) author_link = self.__get_dynamic_attr('item_author_link', item) else: author_email = author_link = None pubdate = self.__get_dynamic_attr('item_pubdate', item) if pubdate and not pubdate.tzinfo: ltz = tzinfo.LocalTimezone(pubdate) pubdate = pubdate.replace(tzinfo=ltz) feed.add_item( title=title, link=link, description=description, unique_id=self.__get_dynamic_attr('item_guid', item, link), enclosure=enc, pubdate=pubdate, author_name=author_name, author_email=author_email, author_link=author_link, categories=self.__get_dynamic_attr('item_categories', item), item_copyright=self.__get_dynamic_attr('item_copyright', item), **self.item_extra_kwargs(item))
def render(self, context): if DjangoTemplate is not None: return DjangoTemplate(self.s).render(context=context) else: assert JinjaTemplate is not None return JinjaTemplate(self.s).render(**context.flatten())
def render(self, message, lang, context=None): title_tpl = DjangoTemplate(f"{message.template.get_subject(lang)}") title_html = title_tpl.render(Context(context)) body_tpl = DjangoTemplate(f"{message.template.get_body(lang)}") body_html = body_tpl.render(Context(context)) return title_html, body_html
genshi_tmpl2 = MarkupTemplate(""" <table xmlns:py="http://genshi.edgewall.org/">$table</table> """) genshi_text_tmpl = NewTextTemplate(""" <table> {% for row in table %}<tr> {% for c in row.values() %}<td>{c}</td>{% end %} </tr>{% end %} </table> """) if DjangoTemplate: django_tmpl = DjangoTemplate("""<table> {% for row in table %}<tr> {% for col in row.values %}<td>{{ col|escape }}</td>{% endfor %} </tr>{% endfor %} </table> """) def test_django(): """Django template""" context = DjangoContext({'table': table}) django_tmpl.render(context) from moya.template.moyatemplates import Template moya_tmpl = Template("""<table> {%- for row in table %}<tr> {% for col in values:row %}<td>${col}</td>{% endfor %} </tr>{%- endfor %}
def benchmark_django(): DjangoTemplate(django_html).render(Context(context))
def __init__(self, template_string): self.template = DjangoTemplate(template_string=template_string)
def __init__(self, sbj, body): self.subject = DjangoTemplate(sbj) self.body = DjangoTemplate(body)