def get_template_context(self, state=None): customer = Customer(**self.archived_customer) provider = Provider(**self.archived_provider) if state is None: state = self.state return { 'document': self, 'provider': provider, 'customer': customer, 'entries': self._entries, 'state': state }
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