Protección del token de mapbox
This commit is contained in:
18
pdf/views.py
18
pdf/views.py
@@ -1,10 +1,11 @@
|
|||||||
# mi_proyecto/pdf/views.py
|
# mi_proyecto/pdf/views.py
|
||||||
# dpsk - 2026
|
|
||||||
import io
|
import io
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from weasyprint import HTML
|
from weasyprint import HTML
|
||||||
|
from arches.app.models.models import GraphModel
|
||||||
from arches.app.models.resource import Resource
|
from arches.app.models.resource import Resource
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -19,9 +20,14 @@ import json
|
|||||||
import ast
|
import ast
|
||||||
|
|
||||||
def static_map_view(geojson_colec, sat_map):
|
def static_map_view(geojson_colec, sat_map):
|
||||||
|
g_sys_cfg=GraphModel.objects.get(name='{"en": "Arches System Settings"}')
|
||||||
|
r_sys_cfg=Resource.objects.get(graph=g_sys_cfg)
|
||||||
|
r_sys_cfg_data=r_sys_cfg.to_json()
|
||||||
|
access_token = r_sys_cfg_data['Map Settings']['Mapbox']['MAPBOX_API_KEY']
|
||||||
|
|
||||||
geojson_dict = ast.literal_eval(geojson_colec)
|
geojson_dict = ast.literal_eval(geojson_colec)
|
||||||
if sat_map:
|
if sat_map:
|
||||||
|
style_id = "satellite-streets-v12" # streets-v12 | outdoors-v11 | satellite-streets-v12
|
||||||
for geo in geojson_dict['features'] :
|
for geo in geojson_dict['features'] :
|
||||||
if geo['geometry'].get('type') == 'Polygon':
|
if geo['geometry'].get('type') == 'Polygon':
|
||||||
geo['properties'] = {
|
geo['properties'] = {
|
||||||
@@ -42,22 +48,16 @@ def static_map_view(geojson_colec, sat_map):
|
|||||||
"stroke-width": 2,
|
"stroke-width": 2,
|
||||||
"stroke-opacity": 0.8
|
"stroke-opacity": 0.8
|
||||||
}
|
}
|
||||||
|
else:
|
||||||
|
style_id = "light-v11"
|
||||||
|
|
||||||
geojson_string = json.dumps(geojson_dict, separators=(',', ':'))
|
geojson_string = json.dumps(geojson_dict, separators=(',', ':'))
|
||||||
encoded_geojson = urllib.parse.quote(geojson_string)
|
encoded_geojson = urllib.parse.quote(geojson_string)
|
||||||
|
|
||||||
username = "mapbox"
|
username = "mapbox"
|
||||||
if sat_map:
|
|
||||||
style_id = "satellite-streets-v12" # streets-v12 | outdoors-v11 | satellite-streets-v12
|
|
||||||
else:
|
|
||||||
style_id = "light-v11"
|
|
||||||
|
|
||||||
width, height = 400, 400
|
width, height = 400, 400
|
||||||
padding = 100
|
padding = 100
|
||||||
|
|
||||||
# Procedimiento pendiente para extraer el token desde la configuración del sistema
|
|
||||||
access_token = 'pk.eyJ1IjoianNidXJnb3N2IiwiYSI6ImNsaWhoN3ZtMTBxeHUzZm1xaGM0cGpxOXIifQ.ki3vldVB5MwZMqDSpLSjLg'
|
|
||||||
|
|
||||||
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}"
|
||||||
|
|||||||
Reference in New Issue
Block a user