effective_icon and add_search
This commit is contained in:
parent
920422d359
commit
b96707d426
6 changed files with 42 additions and 29 deletions
|
@ -92,5 +92,6 @@ class Level(SpecificLocation, models.Model):
|
||||||
return unary_union(tuple(item.geometry.buffer(0)
|
return unary_union(tuple(item.geometry.buffer(0)
|
||||||
for item in chain(self.altitudeareas.all(), self.buildings.all()))).bounds
|
for item in chain(self.altitudeareas.all(), self.buildings.all()))).bounds
|
||||||
|
|
||||||
def get_icon(self):
|
@property
|
||||||
return super().get_icon() or 'layers'
|
def effective_icon(self):
|
||||||
|
return super().effective_icon or 'layers'
|
||||||
|
|
|
@ -124,25 +124,19 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
||||||
result = {name: result[name] for name in fields if name in result}
|
result = {name: result[name] for name in fields if name in result}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _serialize(self, search=False, **kwargs):
|
@property
|
||||||
result = super()._serialize(**kwargs)
|
def add_search(self):
|
||||||
result['subtitle'] = self.subtitle
|
return ' '.join((
|
||||||
result['icon'] = self.get_icon()
|
*(redirect.slug for redirect in self.redirects.all()),
|
||||||
result['can_search'] = self.can_search
|
*self.other_titles,
|
||||||
result['can_describe'] = self.can_search
|
))
|
||||||
if search:
|
|
||||||
result['add_search'] = ' '.join((
|
|
||||||
*(redirect.slug for redirect in self.redirects.all()),
|
|
||||||
*self.other_titles,
|
|
||||||
))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def details_display(self, **kwargs):
|
def details_display(self, **kwargs):
|
||||||
result = super().details_display(**kwargs)
|
result = super().details_display(**kwargs)
|
||||||
result['display'].extend([
|
result['display'].extend([
|
||||||
(_('searchable'), _('Yes') if self.can_search else _('No')),
|
(_('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()),
|
(_('icon'), self.effective_icon),
|
||||||
])
|
])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -175,7 +169,8 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
|
||||||
return (0, group.category.priority, group.hierarchy, group.priority), color
|
return (0, group.category.priority, group.hierarchy, group.priority), color
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_icon(self):
|
@property
|
||||||
|
def effective_icon(self):
|
||||||
return self.icon or None
|
return self.icon or None
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,8 +276,9 @@ class SpecificLocation(Location, models.Model):
|
||||||
return (0, 0, 0)
|
return (0, 0, 0)
|
||||||
return (0, groups[0].category.priority, groups[0].priority)
|
return (0, groups[0].category.priority, groups[0].priority)
|
||||||
|
|
||||||
def get_icon(self):
|
@property
|
||||||
icon = super().get_icon()
|
def effective_icon(self):
|
||||||
|
icon = super().effective_icon
|
||||||
if icon:
|
if icon:
|
||||||
return icon
|
return icon
|
||||||
for group in self.groups.all():
|
for group in self.groups.all():
|
||||||
|
@ -554,7 +550,7 @@ class DynamicLocation(CustomLocationProxyMixin, SpecificLocation, models.Model):
|
||||||
'available': False,
|
'available': False,
|
||||||
'id': self.pk,
|
'id': self.pk,
|
||||||
'slug': self.slug,
|
'slug': self.slug,
|
||||||
'icon': self.get_icon(),
|
'icon': self.effective_icon,
|
||||||
'title': str(self.title),
|
'title': str(self.title),
|
||||||
'subtitle': '%s %s, %s' % (_('currently unavailable'), _('(moving)'), self.subtitle)
|
'subtitle': '%s %s, %s' % (_('currently unavailable'), _('(moving)'), self.subtitle)
|
||||||
}
|
}
|
||||||
|
@ -563,7 +559,7 @@ class DynamicLocation(CustomLocationProxyMixin, SpecificLocation, models.Model):
|
||||||
'available': True,
|
'available': True,
|
||||||
'id': self.pk,
|
'id': self.pk,
|
||||||
'slug': self.slug,
|
'slug': self.slug,
|
||||||
'icon': self.get_icon(),
|
'icon': self.effective_icon,
|
||||||
'title': str(self.title),
|
'title': str(self.title),
|
||||||
'subtitle': '%s %s%s, %s' % (
|
'subtitle': '%s %s%s, %s' % (
|
||||||
_('(moving)'),
|
_('(moving)'),
|
||||||
|
|
|
@ -96,8 +96,13 @@ class LocationSchema(WithAccessRestrictionSchema, TitledSchema, LocationSlugSche
|
||||||
example="near Area 51",
|
example="near Area 51",
|
||||||
)
|
)
|
||||||
icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
||||||
title="icon name",
|
title="set icon name",
|
||||||
description="any material design icon name",
|
description="as set in the object specifically (any material design icon name)",
|
||||||
|
example="pin_drop",
|
||||||
|
)
|
||||||
|
effective_icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
||||||
|
title="icon name to use",
|
||||||
|
description="effective icon to use (any material design icon name)",
|
||||||
example="pin_drop",
|
example="pin_drop",
|
||||||
)
|
)
|
||||||
can_search: bool = APIField(
|
can_search: bool = APIField(
|
||||||
|
|
|
@ -387,8 +387,13 @@ class CustomLocationSchema(BaseSchema):
|
||||||
description="slug, identical to ID"
|
description="slug, identical to ID"
|
||||||
)
|
)
|
||||||
icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
||||||
title="icon name",
|
title="set icon name",
|
||||||
description="any material design icon name",
|
description="as set in the object specifically (any material design icon name)",
|
||||||
|
example="pin_drop",
|
||||||
|
)
|
||||||
|
effective_icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
||||||
|
title="icon name to use",
|
||||||
|
description="effective icon to use (any material design icon name)",
|
||||||
example="pin_drop",
|
example="pin_drop",
|
||||||
)
|
)
|
||||||
title: NonEmptyStr = APIField(
|
title: NonEmptyStr = APIField(
|
||||||
|
@ -470,8 +475,13 @@ class TrackablePositionSchema(BaseSchema):
|
||||||
example="p:adskjfalskdj",
|
example="p:adskjfalskdj",
|
||||||
)
|
)
|
||||||
icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
||||||
title="icon name",
|
title="set icon name",
|
||||||
description="any material design icon name",
|
description="icon as set in the location specifically (any material design icon name)",
|
||||||
|
example="pin_drop",
|
||||||
|
)
|
||||||
|
effective_icon: Optional[NonEmptyStr] = APIField( # todo: not optional?
|
||||||
|
title="icon name to use",
|
||||||
|
description="effective icon to use (any material design icon name)",
|
||||||
example="pin_drop",
|
example="pin_drop",
|
||||||
)
|
)
|
||||||
title: NonEmptyStr = APIField(
|
title: NonEmptyStr = APIField(
|
||||||
|
|
|
@ -458,7 +458,8 @@ class CustomLocation:
|
||||||
def subtitle(self):
|
def subtitle(self):
|
||||||
return self.title_subtitle[1]
|
return self.title_subtitle[1]
|
||||||
|
|
||||||
def get_icon(self):
|
@property
|
||||||
|
def effective_icon(self):
|
||||||
return self.icon
|
return self.icon
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -969,7 +969,7 @@ c3nav = {
|
||||||
},
|
},
|
||||||
_build_location_html: function (location) {
|
_build_location_html: function (location) {
|
||||||
var html = $('<div class="location">')
|
var html = $('<div class="location">')
|
||||||
.append($('<i class="icon material-symbols">').text(c3nav._map_material_icon(location.icon || 'place')))
|
.append($('<i class="icon material-symbols">').text(c3nav._map_material_icon(location.effective_icon || 'place')))
|
||||||
.append($('<span>').text(location.title))
|
.append($('<span>').text(location.title))
|
||||||
.append($('<small>').text(location.subtitle)).attr('data-id', location.id);
|
.append($('<small>').text(location.subtitle)).attr('data-id', location.id);
|
||||||
html.attr('data-location', JSON.stringify(location));
|
html.attr('data-location', JSON.stringify(location));
|
||||||
|
@ -1024,7 +1024,7 @@ c3nav = {
|
||||||
c3nav._locationinput_reset_autocomplete();
|
c3nav._locationinput_reset_autocomplete();
|
||||||
elem.toggleClass('selected', !!location).toggleClass('empty', !location)
|
elem.toggleClass('selected', !!location).toggleClass('empty', !location)
|
||||||
.data('location', location).data('lastlocation', location).removeData('suggestion');
|
.data('location', location).data('lastlocation', location).removeData('suggestion');
|
||||||
elem.find('.icon').text(location ? c3nav._map_material_icon(location.icon || 'place') : '');
|
elem.find('.icon').text(location ? c3nav._map_material_icon(location.effective_icon || 'place') : '');
|
||||||
elem.find('input').val(location ? location.title : '').removeData('origval');
|
elem.find('input').val(location ? location.title : '').removeData('origval');
|
||||||
elem.find('small').text(location ? location.subtitle : '');
|
elem.find('small').text(location ? location.subtitle : '');
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue