add Level.short_label

This commit is contained in:
Laura Klünder 2017-10-25 12:29:08 +02:00
parent fbc9efd2a0
commit 48fb0e4555
4 changed files with 45 additions and 2 deletions

View file

@ -93,6 +93,9 @@ class EditorFormBase(ModelForm):
self.fields.move_to_end('title_' + language, last=False)
self.titles = titles
if 'short_label' in self.fields:
self.fields.move_to_end('short_label', last=False)
if 'name' in self.fields:
self.fields.move_to_end('name', last=False)
@ -163,7 +166,7 @@ def create_editor_form(editor_model):
possible_fields = ['slug', 'name', 'ordering', 'category', 'width', 'groups', 'color', 'priority', 'base_altitude',
'waytype', 'access_restriction', 'height', 'default_height', 'can_search', 'can_describe',
'outside', 'geometry', 'single', 'allow_levels', 'allow_spaces', 'allow_areas', 'allow_pois',
'altitude', 'left', 'top', 'right', 'bottom']
'altitude', 'short_label', 'left', 'top', 'right', 'bottom']
field_names = [field.name for field in editor_model._meta.get_fields() if not field.one_to_many]
existing_fields = [name for name in possible_fields if name in field_names]

View file

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-25 10:19
from __future__ import unicode_literals
from django.db import migrations, models
def add_short_label(apps, schema_editor):
models = ('AltitudeArea', 'AltitudeMarker', 'Area', 'Building', 'Column', 'Door', 'GraphNode', 'Hole',
'LineObstacle', 'Obstacle', 'POI', 'Space', 'Stair')
Level = apps.get_model('mapdata', 'level')
for level in Level.objects.all():
level.short_label = level.slug or str(level.pk)
level.save()
def remove_short_label(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0040_access_permissions'),
]
operations = [
migrations.AddField(
model_name='level',
name='short_label',
field=models.CharField(null=True, max_length=20, unique=True, verbose_name='short label'),
),
migrations.RunPython(add_short_label, remove_short_label),
migrations.AlterField(
model_name='level',
name='short_label',
field=models.CharField(max_length=20, unique=True, verbose_name='short label'),
),
]

View file

@ -30,6 +30,7 @@ class Level(SpecificLocation, models.Model):
default_height = models.DecimalField(_('default space height'), max_digits=6, decimal_places=2, default=3.0)
on_top_of = models.ForeignKey('mapdata.Level', null=True, on_delete=models.CASCADE,
related_name='levels_on_top', verbose_name=_('on top of'))
short_label = models.CharField(max_length=20, verbose_name=_('short label'), unique=True)
render_data = models.BinaryField(null=True)
@ -81,6 +82,7 @@ class Level(SpecificLocation, models.Model):
def _serialize(self, level=True, **kwargs):
result = super()._serialize(**kwargs)
result['short_label'] = self.short_label
result['on_top_of'] = self.on_top_of_id
result['base_altitude'] = float(str(self.base_altitude))
result['default_height'] = float(str(self.default_height))

View file

@ -66,7 +66,7 @@ def map_index(request):
ctx = {
'bounds': json.dumps(Source.max_bounds(), separators=(',', ':')),
'levels': json.dumps(tuple((level.pk, level.title) for level in levels), separators=(',', ':')),
'levels': json.dumps(tuple((level.pk, level.short_label) for level in levels), separators=(',', ':')),
}
response = render(request, 'site/map.html', ctx)
set_tile_access_cookie(request, response)