Esempio n. 1
0
 def test_django():
     c = DjangoContext(context)
     c['navigation'] = [('index.html', 'Index'), ('downloads.html', 'Downloads'),
                        ('products.html', 'Products')]
     # recompile template each rendering because that's what django
     # is doing in normal situations too.  Django is not thread safe
     # so we can't cache it in regular apps either.
     DjangoTemplate(django_template).render(c)
 def render_template(self, context={}, file_type='pdf'):
     t = DjangoTemplate(template_string=self.html)
     c = DjangoContext(context)
     rendered = t.render(c)
     Render.objects.update_or_create(full_text=rendered,
                                     file_type=file_type,
                                     template=self)
     return rendered
Esempio n. 3
0
    def commprev(self, request, tl, one, two, module, extra, prog):
        from esp.users.models import PersistentQueryFilter
        from django.conf import settings

        filterid, listcount, subject, body = [request.POST['filterid'],
                                              request.POST['listcount'],
                                              request.POST['subject'],
                                              request.POST['body']    ]
        sendto_fn_name = request.POST.get('sendto_fn_name', MessageRequest.SEND_TO_SELF_REAL)

        # Set From address
        if request.POST.get('from', '').strip():
            fromemail = request.POST['from']
        else:
            # String together an address like [email protected]
            fromemail = '%s@%s' % (request.user.username, settings.SITE_INFO[1])

        # Set Reply-To address
        if request.POST.get('replyto', '').strip():
            replytoemail = request.POST['replyto']
        else:
            replytoemail = fromemail

        try:
            filterid = int(filterid)
        except:
            raise ESPError("Corrupted POST data!  Please contact us at [email protected] and tell us how you got this error, and we'll look into it.")

        userlist = PersistentQueryFilter.getFilterFromID(filterid, ESPUser).getList(ESPUser)

        try:
            firstuser = userlist[0]
        except:
            raise ESPError("You seem to be trying to email 0 people!  Please go back, edit your search, and try again.")

        MessageRequest.assert_is_valid_sendto_fn_or_ESPError(sendto_fn_name)

        #   If they were trying to use HTML, don't sanitize the content.
        if '<html>' not in body:
            htmlbody = body.replace('<', '&lt;').replace('>', '&gt;').replace('\n', '<br />')
        else:
            htmlbody = body

        contextdict = {'user'   : ActionHandler(firstuser, firstuser),
                       'program': ActionHandler(self.program, firstuser) }

        renderedtext = Template(htmlbody).render(DjangoContext(contextdict))

        return render_to_response(self.baseDir()+'preview.html', request,
                                              {'filterid': filterid,
                                               'sendto_fn_name': sendto_fn_name,
                                               'listcount': listcount,
                                               'subject': subject,
                                               'from': fromemail,
                                               'replyto': replytoemail,
                                               'body': body,
                                               'renderedtext': renderedtext})
Esempio n. 4
0
 def render(self, context):
     name = self.name.resolve(context)
     type = 'text'
     value = ''
     if self.type is not None:
         type = self.type.resolve(context)
     if self.value is not None:
         value = self.value.resolve(context)
     tmpl = django_loader.get_template('_input_field.html')
     return tmpl.render(DjangoContext({
         'name':     name,
         'type':     type,
         'value':    value
     }))
Esempio n. 5
0
 def render(self, context):
     body = self.body.render(context)
     action = ''
     method = 'post'
     if self.action is not None:
         action = self.action.resolve(context)
     if self.method is not None:
         method = self.method.resolve(context)
     tmpl = django_loader.get_template('_form.html')
     return tmpl.render(DjangoContext({
         'body':     body,
         'action':   action,
         'method':   method
     }))
Esempio n. 6
0
 def render(self, context):
     name = self.name.resolve(context)
     rows = 10
     cols = 40
     value = ''
     if self.rows is not None:
         rows = int(self.rows.resolve(context))
     if self.cols is not None:
         cols = int(self.cols.resolve(context))
     if self.value is not None:
         value = self.value.resolve(context)
     tmpl = django_loader.get_template('_textarea.html')
     return tmpl.render(DjangoContext({
         'name':     name,
         'rows':     rows,
         'cols':     cols,
         'value':    value
     }))
Esempio n. 7
0
    def render(self, context=None):
        """Differs from Django's own render() slightly in that makes the
        ``context`` parameter optional. We try to strike a middle ground
        here between implementing Django's interface while still supporting
        Jinja's own call syntax as well.
        """
        dict_ = {}

        if isinstance(context, dict):
            dict_ = context

        if isinstance(context, DjangoContext):
            dict_ = dict_from_django_context(context)

        if isinstance(context, _Jinja2Context):
            dict_ = context.get_all()

        # It'd be nice to move this only into the test env
        signals.template_rendered.send(sender=self,
                                       template=self,
                                       context=DjangoContext(dict_))
        return super(Template, self).render(**dict_)
Esempio n. 8
0
 def render_template(self, template_name, **kwargs):
     """Loads the django template for `template_name`"""
     template = django_template_loader.get_template(template_name)
     return template.render(DjangoContext(kwargs))
Esempio n. 9
0
 def test_django():
     """Django template"""
     context = DjangoContext({'table': table})
     django_tmpl.render(context)
Esempio n. 10
0
 def test_django():
     c = DjangoContext(context)
     c['navigation'] = [('index.html', 'Index'), ('downloads.html', 'Downloads'),
                        ('products.html', 'Products')]
     django_template.render(c)
Esempio n. 11
0
 def render_template(self, template_name, **kwargs):
     return django_template_loader.get_template(template_name).render(
         DjangoContext(kwargs))
Esempio n. 12
0
 def render(self, ctx_dict):
     ctx = DjangoContext(ctx_dict)
     return (self.subject.render(ctx), self.body.render(ctx), self.log_tpl.render(ctx))