custom location icons
This commit is contained in:
parent
b88e9401aa
commit
475ea434fe
3 changed files with 54 additions and 3 deletions
|
@ -257,7 +257,7 @@ class EditorFormBase(I18nModelFormMixin, ModelForm):
|
|||
|
||||
|
||||
def create_editor_form(editor_model):
|
||||
possible_fields = ['slug', 'name', 'title', 'title_plural', 'join_edges', 'up_separate', 'walk',
|
||||
possible_fields = ['slug', 'name', 'title', 'title_plural', 'icon', 'join_edges', 'up_separate', 'walk',
|
||||
'ordering', 'category', 'width', 'groups', 'color', 'priority', 'icon_name',
|
||||
'base_altitude', 'waytype', 'access_restriction', 'height', 'default_height', 'door_height',
|
||||
'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label',
|
||||
|
|
38
src/c3nav/mapdata/migrations/0006_location_icon.py
Normal file
38
src/c3nav/mapdata/migrations/0006_location_icon.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Generated by Django 2.1.4 on 2018-12-21 02:04
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mapdata', '0005_geometry_import_tag'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='area',
|
||||
name='icon',
|
||||
field=models.CharField(blank=True, help_text='any material icons name', max_length=32, null=True, verbose_name='icon'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='level',
|
||||
name='icon',
|
||||
field=models.CharField(blank=True, help_text='any material icons name', max_length=32, null=True, verbose_name='icon'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='locationgroup',
|
||||
name='icon',
|
||||
field=models.CharField(blank=True, help_text='any material icons name', max_length=32, null=True, verbose_name='icon'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='poi',
|
||||
name='icon',
|
||||
field=models.CharField(blank=True, help_text='any material icons name', max_length=32, null=True, verbose_name='icon'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='space',
|
||||
name='icon',
|
||||
field=models.CharField(blank=True, help_text='any material icons name', max_length=32, null=True, verbose_name='icon'),
|
||||
),
|
||||
]
|
|
@ -79,6 +79,7 @@ class LocationSlug(SerializableMixin, models.Model):
|
|||
class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
||||
can_search = models.BooleanField(default=True, verbose_name=_('can be searched'))
|
||||
can_describe = models.BooleanField(default=True, verbose_name=_('can describe'))
|
||||
icon = models.CharField(_('icon'), max_length=32, null=True, blank=True, help_text=_('any material icons name'))
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
@ -86,7 +87,7 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
|||
def serialize(self, detailed=True, describe_only=False, **kwargs):
|
||||
result = super().serialize(detailed=detailed, **kwargs)
|
||||
if not detailed:
|
||||
fields = ('id', 'type', 'slug', 'title', 'subtitle', 'point', 'bounds', 'grid_square',
|
||||
fields = ('id', 'type', 'slug', 'title', 'subtitle', 'icon', 'point', 'bounds', 'grid_square',
|
||||
'locations', 'on_top_of')
|
||||
result = OrderedDict(((name, result[name]) for name in fields if name in result))
|
||||
return result
|
||||
|
@ -94,6 +95,7 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
|||
def _serialize(self, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
result['subtitle'] = str(self.subtitle)
|
||||
result['icon'] = self.icon
|
||||
result['can_search'] = self.can_search
|
||||
result['can_describe'] = self.can_search
|
||||
return result
|
||||
|
@ -102,7 +104,8 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
|||
result = super().details_display(**kwargs)
|
||||
result['display'].extend([
|
||||
(_('searchable'), _('Yes') if self.can_search else _('No')),
|
||||
(_('can describe'), _('Yes') if self.can_describe else _('No'))
|
||||
(_('can describe'), _('Yes') if self.can_describe else _('No')),
|
||||
(_('icon'), self.get_icon()),
|
||||
])
|
||||
return result
|
||||
|
||||
|
@ -130,6 +133,9 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
|||
return group.color
|
||||
return None
|
||||
|
||||
def get_icon(self):
|
||||
return self.icon or None
|
||||
|
||||
|
||||
class SpecificLocation(Location, models.Model):
|
||||
groups = models.ManyToManyField('mapdata.LocationGroup', verbose_name=_('Location Groups'), blank=True)
|
||||
|
@ -195,6 +201,13 @@ class SpecificLocation(Location, models.Model):
|
|||
return (0, 0, 0)
|
||||
return (0, groups[0].category.priority, groups[0].priority)
|
||||
|
||||
def get_icon(self):
|
||||
icon = super().get_icon()
|
||||
if not icon:
|
||||
for group in self.groups.all():
|
||||
if group.icon and getattr(group.category, 'allow_' + self.__class__._meta.default_related_name):
|
||||
return group.icon
|
||||
|
||||
|
||||
class LocationGroupCategory(SerializableMixin, models.Model):
|
||||
name = models.SlugField(_('Name'), unique=True, max_length=50)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue