declare tiles to be used as pages in tile settings

This makes it possible to add new place pages without editing gnm_create_places.
This commit is contained in:
Frédéric Péters 2020-11-20 07:59:21 +01:00
parent a3e97a6534
commit 1e300df3d8
2 changed files with 23 additions and 16 deletions

View File

@ -18,6 +18,7 @@
from django.conf import settings
from django.core.management.base import BaseCommand
from django.template import Context, Template
from combo.apps.maps.models import MapLayer
from combo.data.models import Page, ConfigJsonCell
@ -25,15 +26,12 @@ from combo.data.models import Page, ConfigJsonCell
class Command(BaseCommand):
def handle(self, *args, **options):
layers = ['mdr', 'piscine', 'mairie', 'bibliotheque', 'decheterie',
'donnerie', 'urgence-sanitaire-soins',
'urgence-sanitaire-alimentation',
'urgence-sanitaire-hebergement',
'urgence-sanitaire-quotidien']
places_page = Page.objects.get(slug='lieux')
for layer in MapLayer.objects.filter(slug__in=layers):
cell_form_keys = [x['varname'] for x in settings.JSON_CELL_TYPES[layer.slug].get('form')]
for layer in MapLayer.objects.all():
json_cell_type = settings.JSON_CELL_TYPES.get(layer.slug)
if not json_cell_type or not json_cell_type.get('toodego:page'):
continue
cell_form_keys = [x['varname'] for x in json_cell_type.get('form')]
parent_page, created = Page.objects.get_or_create(
parent__id=places_page.id,
slug=layer.slug,
@ -55,14 +53,11 @@ class Command(BaseCommand):
page__template_name='place')
except ConfigJsonCell.DoesNotExist:
page = Page()
if layer.slug == 'decheterie':
page.title = u'Déchèterie %s' % feature['properties']['nom']
elif layer.slug == 'donnerie':
page.title = u'Donnerie %s' % feature['properties']['nom']
elif layer.slug == 'taxi':
page.title = u'Station de taxi %s' % feature['properties']['adresse']
else:
page.title = feature['properties']['nom']
page_title_template = json_cell_type.get(
'toodego:page-title-template',
'{{ properties.nom }}')
ctx = Context({'properties': feature['properties']})
page.title = Template(page_title_template).render(ctx)
page.parent = Page.objects.get(slug=layer.slug)
page.template_name = 'place'
page.save()

12
debian/50gnm.py vendored
View File

@ -95,6 +95,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": u"Maison de la Métropole de Lyon",
"toodego:page": True,
"form": [
{
"varname": "identifiant",
@ -108,6 +109,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": u"Piscine de la Métropole de Lyon",
"toodego:page": True,
"form": [
{
"varname": "identifiant",
@ -121,6 +123,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": u"Mairie",
"toodego:page": True,
"form": [
{
"varname": "identifiant",
@ -134,6 +137,8 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": u"Déchèterie",
"toodego:page": True,
"toodego:page-title-template": "Déchèterie {{properties.nom}}",
"form": [
{
"varname": "identifiant",
@ -147,6 +152,8 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": u"Donnerie",
"toodego:page": True,
"toodego:page-title-template": "Donnerie {{properties.nom}}",
"form": [
{
"varname": "identifiant",
@ -160,6 +167,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": u"Bibliothèque",
"toodego:page": True,
"form": [
{
"varname": "identifiant",
@ -462,6 +470,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": "Urgence sanitaire Covid 19 - Accès aux soins",
"toodego:page": True,
"template-name": "combo/json/urgence-sanitaire.html",
"form": [
{
@ -476,6 +485,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": "Urgence sanitaire Covid 19 - Alimentation",
"toodego:page": True,
"template-name": "combo/json/urgence-sanitaire.html",
"form": [
{
@ -490,6 +500,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": "Urgence sanitaire Covid 19 - Hébergement",
"toodego:page": True,
"template-name": "combo/json/urgence-sanitaire.html",
"form": [
{
@ -504,6 +515,7 @@ JSON_CELL_TYPES = {
"cache_duration": 86400,
"force_async": False,
"name": "Urgence sanitaire Covid 19 - Services au quotidien",
"toodego:page": True,
"template-name": "combo/json/urgence-sanitaire.html",
"form": [
{