ajustes a la vista
This commit is contained in:
32
pdf/views.py
32
pdf/views.py
@@ -52,7 +52,8 @@ def static_map_view(geojson_colec, sat_map):
|
|||||||
else:
|
else:
|
||||||
style_id = "light-v11"
|
style_id = "light-v11"
|
||||||
|
|
||||||
width, height = 340, 340
|
width, height = 400, 400
|
||||||
|
padding = 100
|
||||||
|
|
||||||
# Procedimiento pendiente para extraer el token desde la configuración del sistema
|
# Procedimiento pendiente para extraer el token desde la configuración del sistema
|
||||||
access_token = 'pk.eyJ1IjoianNidXJnb3N2IiwiYSI6ImNsaWhoN3ZtMTBxeHUzZm1xaGM0cGpxOXIifQ.ki3vldVB5MwZMqDSpLSjLg'
|
access_token = 'pk.eyJ1IjoianNidXJnb3N2IiwiYSI6ImNsaWhoN3ZtMTBxeHUzZm1xaGM0cGpxOXIifQ.ki3vldVB5MwZMqDSpLSjLg'
|
||||||
@@ -60,7 +61,7 @@ def static_map_view(geojson_colec, sat_map):
|
|||||||
mapbox_url = (
|
mapbox_url = (
|
||||||
f"https://api.mapbox.com/styles/v1/{username}/{style_id}/static/"
|
f"https://api.mapbox.com/styles/v1/{username}/{style_id}/static/"
|
||||||
f"geojson({encoded_geojson})/auto/{width}x{height}"
|
f"geojson({encoded_geojson})/auto/{width}x{height}"
|
||||||
f"?access_token={access_token}"
|
f"?padding={padding}&access_token={access_token}"
|
||||||
)
|
)
|
||||||
|
|
||||||
response = requests.get(mapbox_url)
|
response = requests.get(mapbox_url)
|
||||||
@@ -171,7 +172,7 @@ def export_resource_pdf(request, resourceid, printubic, satmap, printimgs, print
|
|||||||
if ruta_gis is not None and bool(int(printubic)) :
|
if ruta_gis is not None and bool(int(printubic)) :
|
||||||
if reduce(getitem, ruta_gis[:-1], resource_data)[ruta_gis[-1]]["@value"] :
|
if reduce(getitem, ruta_gis[:-1], resource_data)[ruta_gis[-1]]["@value"] :
|
||||||
map_img = static_map_view(reduce(getitem, ruta_gis[:-1], resource_data)[ruta_gis[-1]]["@value"], bool(int(satmap)))
|
map_img = static_map_view(reduce(getitem, ruta_gis[:-1], resource_data)[ruta_gis[-1]]["@value"], bool(int(satmap)))
|
||||||
|
|
||||||
resources = [{
|
resources = [{
|
||||||
'resourceinstanceid': str(resource.resourceinstanceid),
|
'resourceinstanceid': str(resource.resourceinstanceid),
|
||||||
'graph_id': str(resource.graph_id),
|
'graph_id': str(resource.graph_id),
|
||||||
@@ -210,23 +211,24 @@ def export_resource_pdf(request, resourceid, printubic, satmap, printimgs, print
|
|||||||
|
|
||||||
merger = PdfWriter()
|
merger = PdfWriter()
|
||||||
merger.append(PdfReader(io.BytesIO(gen_pdf_file)))
|
merger.append(PdfReader(io.BytesIO(gen_pdf_file)))
|
||||||
|
|
||||||
root_path = Path(__file__).resolve().parent.parent
|
|
||||||
|
|
||||||
if ruta_medios is not None and bool(int(printpdfs)) :
|
if ruta_medios is not None and bool(int(printpdfs)) :
|
||||||
for medio in reduce(getitem, ruta_medios[:-1], resource_data)[ruta_medios[-1]] :
|
for medio in reduce(getitem, ruta_medios[:-1], resource_data)[ruta_medios[-1]] :
|
||||||
if medio['formato'] == 'application/pdf' :
|
if medio['formato'] == 'application/pdf' :
|
||||||
medio_file = f'{root_path}/uploadedfiles/{medio["file"]}'
|
try :
|
||||||
with open(medio_file,'rb') as pdf_file :
|
response = requests.get(f'{sprpcb_url}{medio["url"]}', timeout=10)
|
||||||
merger.append(pdf_file)
|
response.raise_for_status()
|
||||||
output_buffer = io.BytesIO()
|
remote_pdf_stream = io.BytesIO(response.content)
|
||||||
merger.write(output_buffer)
|
merger.append(remote_pdf_stream)
|
||||||
merger.close()
|
remote_pdf_stream.close()
|
||||||
else:
|
except requests.RequestException as e:
|
||||||
output_buffer = io.BytesIO()
|
return HttpResponse(f"Error al incluir el archivo PDF: {e}", status=502)
|
||||||
merger.write(output_buffer)
|
|
||||||
merger.close()
|
output_buffer = io.BytesIO()
|
||||||
|
merger.write(output_buffer)
|
||||||
output_buffer.seek(0)
|
output_buffer.seek(0)
|
||||||
|
merger.close()
|
||||||
|
|
||||||
response = HttpResponse(output_buffer.read(), content_type='application/pdf')
|
response = HttpResponse(output_buffer.read(), content_type='application/pdf')
|
||||||
response['Content-Disposition'] = f'attachment; filename="{nombre_pdf}.pdf"'
|
response['Content-Disposition'] = f'attachment; filename="{nombre_pdf}.pdf"'
|
||||||
return response
|
return response
|
||||||
Reference in New Issue
Block a user