add Level.short_label
This commit is contained in:
parent
fbc9efd2a0
commit
48fb0e4555
4 changed files with 45 additions and 2 deletions
|
@ -93,6 +93,9 @@ class EditorFormBase(ModelForm):
|
||||||
self.fields.move_to_end('title_' + language, last=False)
|
self.fields.move_to_end('title_' + language, last=False)
|
||||||
self.titles = titles
|
self.titles = titles
|
||||||
|
|
||||||
|
if 'short_label' in self.fields:
|
||||||
|
self.fields.move_to_end('short_label', last=False)
|
||||||
|
|
||||||
if 'name' in self.fields:
|
if 'name' in self.fields:
|
||||||
self.fields.move_to_end('name', last=False)
|
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',
|
possible_fields = ['slug', 'name', 'ordering', 'category', 'width', 'groups', 'color', 'priority', 'base_altitude',
|
||||||
'waytype', 'access_restriction', 'height', 'default_height', 'can_search', 'can_describe',
|
'waytype', 'access_restriction', 'height', 'default_height', 'can_search', 'can_describe',
|
||||||
'outside', 'geometry', 'single', 'allow_levels', 'allow_spaces', 'allow_areas', 'allow_pois',
|
'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]
|
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]
|
existing_fields = [name for name in possible_fields if name in field_names]
|
||||||
|
|
||||||
|
|
38
src/c3nav/mapdata/migrations/0041_level_short_label.py
Normal file
38
src/c3nav/mapdata/migrations/0041_level_short_label.py
Normal 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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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)
|
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,
|
on_top_of = models.ForeignKey('mapdata.Level', null=True, on_delete=models.CASCADE,
|
||||||
related_name='levels_on_top', verbose_name=_('on top of'))
|
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)
|
render_data = models.BinaryField(null=True)
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ class Level(SpecificLocation, models.Model):
|
||||||
|
|
||||||
def _serialize(self, level=True, **kwargs):
|
def _serialize(self, level=True, **kwargs):
|
||||||
result = super()._serialize(**kwargs)
|
result = super()._serialize(**kwargs)
|
||||||
|
result['short_label'] = self.short_label
|
||||||
result['on_top_of'] = self.on_top_of_id
|
result['on_top_of'] = self.on_top_of_id
|
||||||
result['base_altitude'] = float(str(self.base_altitude))
|
result['base_altitude'] = float(str(self.base_altitude))
|
||||||
result['default_height'] = float(str(self.default_height))
|
result['default_height'] = float(str(self.default_height))
|
||||||
|
|
|
@ -66,7 +66,7 @@ def map_index(request):
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
'bounds': json.dumps(Source.max_bounds(), separators=(',', ':')),
|
'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)
|
response = render(request, 'site/map.html', ctx)
|
||||||
set_tile_access_cookie(request, response)
|
set_tile_access_cookie(request, response)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue