cfdi-admin/source/main/views.py

23 lines
658 B
Python

from django.shortcuts import render
from django.http import FileResponse
from main.models import Cfdi
from main.util import util
def down_xml(request, id_cfdi):
obj = Cfdi.objects.get(id=id_cfdi)
name = f'{obj.uuid}.xml'
response = FileResponse(obj.xml, content_type='text/xml')
response['Content-Length'] = len(obj.xml.encode())
response['Content-Disposition'] = f'attachment; filename="{name}"'
return response
def down_pdf(request, id_cfdi):
obj = Cfdi.objects.get(id=id_cfdi)
name = f'{obj.uuid}.pdf'
pdf = util.get_pdf(obj)
response = FileResponse(pdf, as_attachment=True, filename=name)
return response