コード例 #1
0
ファイル: bench.py プロジェクト: furoka/ailadder
 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)
コード例 #2
0
 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
コード例 #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})
コード例 #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
     }))
コード例 #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
     }))
コード例 #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
     }))
コード例 #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_)
コード例 #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))
コード例 #9
0
ファイル: bigtable.py プロジェクト: ui-frontend/moya
 def test_django():
     """Django template"""
     context = DjangoContext({'table': table})
     django_tmpl.render(context)
コード例 #10
0
ファイル: jinja2_benchmarks.py プロジェクト: break2017/lunar
 def test_django():
     c = DjangoContext(context)
     c['navigation'] = [('index.html', 'Index'), ('downloads.html', 'Downloads'),
                        ('products.html', 'Products')]
     django_template.render(c)
コード例 #11
0
ファイル: runtime.py プロジェクト: komeic/XBlock
 def render_template(self, template_name, **kwargs):
     return django_template_loader.get_template(template_name).render(
         DjangoContext(kwargs))
コード例 #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))