Пример #1
0
    def _generate_pdf(self, state=None):
        customer = Customer(**self.archived_customer)
        provider = Provider(**self.archived_provider)
        if state is None:
            state = self.state

        context = {
            'document': self,
            'provider': provider,
            'customer': customer,
            'entries': self._entries,
            'state': state
        }

        provider_state_template = '{provider}/{kind}_{state}_pdf.html'.format(
            kind=self.kind, provider=self.provider.slug, state=state).lower()
        provider_template = '{provider}/{kind}_pdf.html'.format(
            kind=self.kind, provider=self.provider.slug).lower()
        generic_state_template = '{kind}_{state}_pdf.html'.format(
            kind=self.kind, state=state).lower()
        generic_template = '{kind}_pdf.html'.format(
            kind=self.kind).lower()
        _templates = [provider_state_template, provider_template,
                      generic_state_template, generic_template]

        templates = []
        for t in _templates:
            templates.append('billing_documents/' + t)

        template = select_template(templates)

        file_object = HttpResponse(content_type='application/pdf')
        generate_pdf_template_object(template, file_object, context)

        return file_object
Пример #2
0
    def generate_pdf(self, state=None):
        context = self.get_template_context(state)
        template = self.get_template(state=context['state'])
        file_object = HttpResponse(content_type='application/pdf')

        generate_pdf_template_object(template, file_object, context)

        return file_object
Пример #3
0
 def render_to_response(self, context, **response_kwargs):
     context = RequestContext(self.request, context)
     resp = self.response_class(content_type='application/pdf')
     template = select_template(self.get_template_names())
     generate_pdf_template_object(template, resp, context)
     self.filename = self.get_filename(template)
     if self.attachment:
         att = 'attachment; '
     else:
         att = ""
     resp['Content-Disposition'] = '{0}filename={1}'.format(att, self.filename)
     return resp
Пример #4
0
 def render_to_response(self, context, **response_kwargs):
     context = RequestContext(self.request, context)
     resp = self.response_class(content_type='application/pdf')
     template = select_template(self.get_template_names())
     generate_pdf_template_object(template, resp, context)
     self.filename = self.get_filename(template)
     if self.attachment:
         att = 'attachment; '
     else:
         att = ""
     resp['Content-Disposition'] = '{0}filename={1}'.format(
         att, self.filename)
     return resp
Пример #5
0
    def generate(self, template, context, upload=True):
        pdf_file_object = HttpResponse(content_type='application/pdf')

        generate_pdf_template_object(template, pdf_file_object, context)

        if not pdf_file_object:
            return

        if upload:
            self.upload(pdf_file_object=pdf_file_object,
                        filename=context['filename'])

        self.mark_as_clean()

        return pdf_file_object
Пример #6
0
    def _generate_pdf(self, state=None):
        customer = Customer(**self.archived_customer)
        provider = Provider(**self.archived_provider)
        if state is None:
            state = self.state

        context = {
            'document': self,
            'provider': provider,
            'customer': customer,
            'entries': self._entries,
            'state': state
        }

        provider_state_template = '{provider}/{kind}_{state}_pdf.html'.format(
            kind=self.kind, provider=self.provider.slug, state=state).lower()
        provider_template = '{provider}/{kind}_pdf.html'.format(
            kind=self.kind, provider=self.provider.slug).lower()
        generic_state_template = '{kind}_{state}_pdf.html'.format(
            kind=self.kind, state=state).lower()
        generic_template = '{kind}_pdf.html'.format(kind=self.kind).lower()
        _templates = [
            provider_state_template, provider_template, generic_state_template,
            generic_template
        ]

        templates = []
        for t in _templates:
            templates.append('billing_documents/' + t)

        template = select_template(templates)

        file_object = HttpResponse(content_type='application/pdf')
        generate_pdf_template_object(template, file_object, context)

        return file_object