create and save autotiles from air quality dynamic paage (#26982)

This commit is contained in:
Frédéric Péters 2018-10-04 15:38:21 +02:00
parent 7174579b17
commit 3721a4f2c7
1 changed files with 19 additions and 0 deletions

View File

@ -29,6 +29,7 @@ from requests import RequestException
from django import template
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.core import signing
from django.utils.dateparse import parse_datetime
from django.utils.http import quote
from django.utils.html import format_html
@ -663,3 +664,21 @@ def indice_values(indices):
for key in ('indice_j-1', 'indice_j', 'indice_j+1'):
if indices.get(key):
yield indices.get(key)
@register.filter
def airquality_hack(cell, request):
if cell.key == 'airquality' and not cell.parameters:
# Cell on airquality dynamic page, it has empty cell.parameters as it
# gets those from the query string. In order to get un/favorite link
# to work we need to duplicate the cell into a concrete object with a
# copy of query parameters within.
if request.GET.get('ctx'):
ctx = signing.loads(request.GET['ctx'])
lon, lat = ctx['q_lon'], ctx['q_lat']
else:
lon, lat = request.path.split('/')[-2].split(',')
cell.parameters = {'lon': lon, 'lat': lat}
cell.placeholder = '_auto_tile'
cell.id = None
cell.save()
return cell