Exemplo n.º 1
0
    def get(self, request):
        now = timezone.now()
        context = {
            'courses':
            ServiceCourse.objects.all(),
            'services':
            Service.get_annotated_list(),
            'discounts':
            Discount.objects.filter(
                is_published=True,
                created_at__lt=now).exclude(close_at__lte=now),
            'qr_data':
            'http://%s%s' %
            (get_current_site(request), reverse('pages:services')),
            'qr_host':
            'www.ryabinaclinic.ru'
        }

        template = get_template(self.template_name)
        # return render_to_response(self.template_name, context, context_instance=RequestContext(request))

        result = StringIO()
        pdf = pisa.pisaDocument(
            StringIO(template.render(context).encode("UTF-8")), result)
        if not pdf.err:
            response = HttpResponse(result.getvalue(),
                                    content_type='application/pdf')
            response[
                'Content-Disposition'] = 'attachment; filename=ryabina_price_%s.pdf' % timezone.now(
                ).strftime('_%Y_%m_%d__%H_%M')
            return response
        else:
            return HttpResponseServerError()
Exemplo n.º 2
0
    def get(self, request):
        now = timezone.now()
        context = {
            'courses': ServiceCourse.objects.all(),
            'services': Service.get_annotated_list(),
            'discounts': Discount.objects.filter(is_published=True, created_at__lt=now).exclude(close_at__lte=now),
            'qr_data': 'http://%s%s' % (get_current_site(request), reverse('pages:services')),
            'qr_host': 'www.ryabinaclinic.ru'
        }

        template = get_template(self.template_name)
        # return render_to_response(self.template_name, context, context_instance=RequestContext(request))

        result = StringIO()
        pdf = pisa.pisaDocument(StringIO(template.render(context).encode("UTF-8")), result)
        if not pdf.err:
            response = HttpResponse(result.getvalue(), content_type='application/pdf')
            response['Content-Disposition'] = 'attachment; filename=ryabina_price_%s.pdf' % timezone.now().strftime('_%Y_%m_%d__%H_%M')
            return response
        else:
            return HttpResponseServerError()
Exemplo n.º 3
0
def get_services_annotated_list(service):
    return Service.get_annotated_list(parent=service)
Exemplo n.º 4
0
def get_services_annotated_list(service):
    return Service.get_annotated_list(parent=service)