Example #1
0
def gen_user_infos(request, pk):
    """
    Generates a latex document include adhesion certificate and list of `cotisations <users.models.CotisationHistory>`.
    """
    user = get_object_or_404(User, pk=pk)
    cotisations = CotisationHistory.objects.filter(user=user).order_by('-paymentDate')
    now = datetime.now()
    path = os.path.join(settings.BASE_DIR, "templates/coope.png")
    return render_to_pdf(request, 'users/bulletin.tex', {"user": user, "now": now, "cotisations": cotisations, "path":path}, filename="bulletin_" + user.first_name + "_" + user.last_name + ".pdf")
Example #2
0
def pdf_view(request):
    template_name = 'tests/test.tex'
    context = {
        'test': 'a simple test',
        'number': Decimal('1000.10'),
        'date': datetime.date(2017, 10, 25),
        'names': ['Arjen', 'Jérôme', 'Robert', 'Mats'],
    }
    return render_to_pdf(template_name, context, filename='test.pdf')
Example #3
0
 def test_render_to_pdf(self):
     request = None # request is only needed to make the signature of render_to_pdf similar to the signature of django's render function
     template_name = 'tests/test.tex'
     context = {
         'test': 'a simple test', 
         'number': Decimal('1000.10'), 
         'date': datetime.date(2017, 10, 25),
         'names': ['Arjen', 'Jérôme', 'Robert', 'Mats'], 
     }
     response = render_to_pdf(request, template_name, context, filename='test.pdf')
     self.assertIsInstance(response, HttpResponse)
     self.assertEquals(response['Content-Type'], 'application/pdf')
     self.assertEquals(response['Content-Disposition'], 'filename="test.pdf"')
Example #4
0
 def test_render_to_pdf(self):
     template_name = 'tests/test.tex'
     context = {
         'test': 'a simple test',
         'number': Decimal('1000.10'),
         'date': datetime.date(2017, 10, 25),
         'names': ['Arjen', 'Jérôme', 'Robert', 'Mats'],
     }
     response = render_to_pdf(template_name, context, filename='test.pdf')
     self.assertIsInstance(response, HttpResponse)
     self.assertEquals(response['Content-Type'], 'application/pdf')
     self.assertEquals(response['Content-Disposition'],
                       'filename="test.pdf"')
Example #5
0
 def render_to_response(self, context, **response_kwargs):
     return render_to_pdf(self.template_name, context)