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")
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')
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"')
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"')
def render_to_response(self, context, **response_kwargs): return render_to_pdf(self.template_name, context)