def assert_can_render(self, template_response): """ Asserts that a template can be rendered. It raises an Exception otherwise :param template_response: a TemplateResponse instance :return: """ render(template_response.template_path, template_response.context)
def try_render(suffix): if template_path == '/': return '/home.html', template.render('/home.html', context) try: template_file = template_path + suffix return template_file, template.render(template_file, context) except TemplateNotFound: return template_file, None
def render_by_namespace(template_path, context={}): ns = get_namespace() if not ns: return template.render(template_path, context) try: return template.render('/'.join([ns, template_path]), context) except TemplateNotFound: return template.render(template_path, context)
def contabilizar(total='0.00', cursor=None): total = Decimal(total) contabilizar_cmd = contabilizar_venda_cmd(cursor) venda = contabilizar_cmd() if venda: total += venda.preco params = {'total': '%s' % total, 'cursor': contabilizar_cmd.cursor.urlsafe()} proximo_passo_path = to_path(contabilizar) task_cmd = TaskQueueCommand('rapida', proximo_passo_path, params=params) task_cmd() else: class TotalForm(Form): nome = StringField() valor = DecimalField() data = DateField() form = TotalForm() dados = form.localize(valor=total, nome='Renzo', data=date.today()) corpo_email = render('vendas/contabilizacao.txt', dados) mail.send_mail(settings.SENDER_EMAIL, '*****@*****.**', 'Contabilização de Vendas', corpo_email)
def contagem(total='0.00', cursor=None): busca_cmd = venda_facade.contabilizar_venda_cmd(cursor) venda = busca_cmd() corpo = render('vendas/email.txt', {'total': total}) if venda is None: logging.info(total) mail.send_mail(settings.SENDER_EMAIL, '*****@*****.**', 'Contabilização de vendas', corpo) else: total = Decimal(total) total += venda.preco cmd = TaskQueueCommand('rapida', to_path(contagem), params={'total': str(total), 'cursor': busca_cmd.cursor.urlsafe()}) cmd()
def set_up(self): fcn_response = self.dependencies['_fcn_response'] fcn = self.dependencies['_fcn'] if isinstance(fcn_response, TemplateResponse): context = fcn_response.context or {} for key in ('_logged_user', '_login_path', '_logout_path'): context[key] = self.dependencies[key] if '_csrf_code' in self.dependencies: context['_csrf_code'] = self.dependencies['_csrf_code'] template_path = fcn_response.template_path if template_path is None: tmpl_rendered = render_by_convention(fcn, context) else: tmpl_rendered = template.render(template_path, context) self.handler.response.write(tmpl_rendered) return True # after response, there is no need to look for more middlewares
def contagem(total='0.00', cursor=None): busca_cmd = venda_facade.contabilizar_venda_cmd(cursor) venda = busca_cmd() corpo = render('vendas/email.txt', {'total': total}) if venda is None: logging.info(total) mail.send_mail(settings.SENDER_EMAIL, '*****@*****.**', 'Contabilização de vendas', corpo) else: total = Decimal(total) total += venda.preco cmd = TaskQueueCommand('rapida', to_path(contagem), params={ 'total': str(total), 'cursor': busca_cmd.cursor.urlsafe() }) cmd()
def test_success(self): template_response = home.index() render(template_response.template_path,template_response.context)