Ejemplo n.º 1
0
 def _test_file(self, template_name):
     template = webodt.ODFTemplate(template_name)
     context = {'username': '******', 'balance': 10.01}
     document = template.render(Context(context))
     self.assertTrue(os.path.isfile(document.name))
     self.assertEqual(os.stat(document.name).st_mode & 0777, 0600)
     self.assertEqual(document.format, 'odt')
     self.assertTrue('John Doe' in document.get_content_xml())
     document.delete()
     self.assertFalse(os.path.isfile(document.name))
Ejemplo n.º 2
0
 def test_converter(self):
     template = webodt.ODFTemplate('sample.odt')
     document = template.render(Context(self.context))
     converter = self.Converter()
     html_document = converter.convert(document, 'html')
     html_data = html_document.read()
     self.assertTrue('John Doe' in html_data)
     document.close()
     html_document.close()
     self.assertFalse(os.path.isfile(document.name))
     self.assertFalse(os.path.isfile(html_document.name))
Ejemplo n.º 3
0
 def test_unescape_in_templates(self):
     template = webodt.ODFTemplate(
         'unescape_templatetags.odt',
         preprocessors=[
             'webodt.preprocessors.unescape_templatetags_preprocessor',
         ])
     context = {'user': '******'}
     document = template.render(Context(context))
     self.assertTrue(
         'Unescape templatetags works!' in document.get_content_xml())
     document.delete()
Ejemplo n.º 4
0
 def test_manager(self):
     template = webodt.ODFTemplate('sample.odt')
     context = {'username': '******', 'balance': 10.01}
     format = 'pdf'
     # check that cache is empty
     odf_document = template.render(Context(context))
     cached_document = self.cache_manager.get(odf_document, format)
     self.assertEqual(cached_document, None)
     # store document to cache
     document = self.converter.convert(odf_document, format)
     self.cache_manager.set(odf_document, format, document)
     # check that cache is not empty
     cached_document = self.cache_manager.get(odf_document, format)
     self.assertEqual(cached_document.read(), document.read())
     # delete data from cache
     self.cache_manager.delete(odf_document, format)
     cached_document = self.cache_manager.get(odf_document, format)
     self.assertEqual(cached_document, None)
Ejemplo n.º 5
0
def invio_fattura(request, f_id):
    f = Fattura.objects.get(id=f_id)
    azione = 'Invio'
    data = {
        'mittente': f.user.email,
        'destinatario': f.cliente.mail,
    }
    if f.user == request.user or request.user.is_superuser:
        if request.method == 'POST':
            form = FatturaInvioForm(
                request.POST,
                data,
            )
            #form.helper.form_action = 'fatture/invio/'+ str(f.id)+'/'
            if form.is_valid():
                oggetto = form.cleaned_data['oggetto']
                corpo = form.cleaned_data['messaggio']
                email = EmailMessage(
                    oggetto,
                    corpo,
                    form.cleaned_data['mittente'],
                    [form.cleaned_data['destinatario']],
                    headers={'Reply-To': form.cleaned_data['mittente']})
                template = webodt.ODFTemplate(f.template.template.name)
                context = dict(
                    data=str(f.data),
                    fattura=f,
                )

                document = template.render(Context(context))
                conv = converter()
                pdf = conv.convert(document, format='pdf')
                email.attach_file(pdf.name)
                return HttpResponseRedirect('/fatture/dettagli/' + str(f.id))
        else:
            form = FatturaInvioForm(data)
            #form.helper.form_action = '/'
        return render_to_response('InvioFattura.html', {
            'request': request,
            'form': form,
        }, RequestContext(request))
    else:
        raise PermissionDenied
Ejemplo n.º 6
0
def stampa_fattura(request, f_id):
    f = Fattura.objects.get(id=f_id)
    if f.user == request.user or request.user.is_superuser:
        #pdb.set_trace()
        #f.template
        template = webodt.ODFTemplate(f.template.template.name)
        context = dict(
            data=str(f.data),
            fattura=f,
        )

        document = template.render(Context(context))
        conv = converter()
        pdf = conv.convert(document, format='pdf')
        #return render_to_response( 'modello_fattura.html', {'request':request, 'f': f})
        response = HttpResponse(pdf, mimetype='application/pdf')
        response[
            'Content-Disposition'] = 'attachment; filename=Fattura-%s-%s.pdf' % (
                f.progressivo(), f.data.year)
        return response
    else:
        raise PermissionDenied
Ejemplo n.º 7
0
def _Template(template_name, preprocessors):
    if template_name.endswith('.html'):
        return webodt.HTMLTemplate(template_name)
    return webodt.ODFTemplate(template_name, preprocessors=preprocessors)
Ejemplo n.º 8
0
 def test_convert_utf8(self):
     template = webodt.ODFTemplate('russian_sample.odt')
     document = template.render(Context({'ts': datetime.datetime.now()}))
     converter = self.Converter()
     pdf_document = converter.convert(document, 'pdf')
     pdf_document.read()
Ejemplo n.º 9
0
 def test_unpacked_template(self):
     template = webodt.ODFTemplate('sample')
     content = template.get_content_xml()
     self.assertTrue('{{ username }}' in content)
Ejemplo n.º 10
0
 def __init__(self, templateName):
     """
         Creates a template converter which will generate ODT documents when passed a dictionary, among other things
         templateName: The name of the template, it will be used to load it from the database
     """
     self.template = webodt.ODFTemplate(templateName)
Ejemplo n.º 11
0
def _Template(template_name):
    if template_name.endswith('.html'):
        return webodt.HTMLTemplate(template_name)
    return webodt.ODFTemplate(template_name)