add external_url and hub_import_type
This commit is contained in:
parent
21688c11d9
commit
4ade6cfc1f
5 changed files with 73 additions and 3 deletions
|
@ -299,7 +299,7 @@ class EditorFormBase(I18nModelFormMixin, ModelForm):
|
||||||
|
|
||||||
def create_editor_form(editor_model):
|
def create_editor_form(editor_model):
|
||||||
possible_fields = ['slug', 'name', 'title', 'title_plural', 'help_text', 'position_secret',
|
possible_fields = ['slug', 'name', 'title', 'title_plural', 'help_text', 'position_secret',
|
||||||
'icon', 'join_edges', 'up_separate', 'bssid', 'main_point',
|
'icon', 'join_edges', 'up_separate', 'bssid', 'main_point', 'external_url', 'hub_import_type',
|
||||||
'walk', 'ordering', 'category', 'width', 'groups', 'height', 'color', 'priority', 'hierarchy',
|
'walk', 'ordering', 'category', 'width', 'groups', 'height', 'color', 'priority', 'hierarchy',
|
||||||
'icon_name', 'base_altitude', 'waytype', 'access_restriction', 'default_height', 'door_height',
|
'icon_name', 'base_altitude', 'waytype', 'access_restriction', 'default_height', 'door_height',
|
||||||
'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label',
|
'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label',
|
||||||
|
@ -308,7 +308,7 @@ def create_editor_form(editor_model):
|
||||||
'level_change_description', 'base_mapdata_accessible', 'can_report_missing',
|
'level_change_description', 'base_mapdata_accessible', 'can_report_missing',
|
||||||
'label_settings', 'label_override', 'min_zoom', 'max_zoom', 'font_size',
|
'label_settings', 'label_override', 'min_zoom', 'max_zoom', 'font_size',
|
||||||
'allow_levels', 'allow_spaces', 'allow_areas', 'allow_pois', 'allow_dynamic_locations',
|
'allow_levels', 'allow_spaces', 'allow_areas', 'allow_pois', 'allow_dynamic_locations',
|
||||||
'left', 'top', 'right', 'bottom', 'public']
|
'left', 'top', 'right', 'bottom', 'public', 'import_tag']
|
||||||
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]
|
||||||
|
|
||||||
|
|
43
src/c3nav/mapdata/migrations/0094_hub_import_prepare.py
Normal file
43
src/c3nav/mapdata/migrations/0094_hub_import_prepare.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
# Generated by Django 4.2.7 on 2023-12-22 00:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0093_public_accessrestriction'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='area',
|
||||||
|
name='external_url',
|
||||||
|
field=models.URLField(blank=True, null=True, verbose_name='external URL'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='dynamiclocation',
|
||||||
|
name='external_url',
|
||||||
|
field=models.URLField(blank=True, null=True, verbose_name='external URL'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='level',
|
||||||
|
name='external_url',
|
||||||
|
field=models.URLField(blank=True, null=True, verbose_name='external URL'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='locationgroup',
|
||||||
|
name='hub_import_type',
|
||||||
|
field=models.CharField(blank=True, help_text='assign this group to imported hub locations of this type', max_length=100, null=True, unique=True, verbose_name='hub import type'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='poi',
|
||||||
|
name='external_url',
|
||||||
|
field=models.URLField(blank=True, null=True, verbose_name='external URL'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='space',
|
||||||
|
name='external_url',
|
||||||
|
field=models.URLField(blank=True, null=True, verbose_name='external URL'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -178,6 +178,7 @@ class SpecificLocation(Location, models.Model):
|
||||||
label_settings = models.ForeignKey('mapdata.LabelSettings', null=True, blank=True, on_delete=models.PROTECT,
|
label_settings = models.ForeignKey('mapdata.LabelSettings', null=True, blank=True, on_delete=models.PROTECT,
|
||||||
verbose_name=_('label settings'))
|
verbose_name=_('label settings'))
|
||||||
label_override = I18nField(_('Label override'), plural_name='label_overrides', blank=True, fallback_any=True)
|
label_override = I18nField(_('Label override'), plural_name='label_overrides', blank=True, fallback_any=True)
|
||||||
|
external_url = models.URLField(_('external URL'), null=True, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
@ -237,6 +238,12 @@ class SpecificLocation(Location, models.Model):
|
||||||
} for group in sorted(groups, key=attrgetter('priority'), reverse=True))
|
} for group in sorted(groups, key=attrgetter('priority'), reverse=True))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
if self.external_url:
|
||||||
|
result['display'].insert(3, (_('External URL'), tuple({
|
||||||
|
'title': _('Open'),
|
||||||
|
'url': self.external_url,
|
||||||
|
})))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
@ -347,6 +354,9 @@ class LocationGroup(Location, models.Model):
|
||||||
can_report_missing = models.BooleanField(default=False, verbose_name=_('for missing locations'),
|
can_report_missing = models.BooleanField(default=False, verbose_name=_('for missing locations'),
|
||||||
help_text=_('can be used when reporting a missing location'))
|
help_text=_('can be used when reporting a missing location'))
|
||||||
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('background color'))
|
color = models.CharField(null=True, blank=True, max_length=32, verbose_name=_('background color'))
|
||||||
|
hub_import_type = models.CharField(max_length=100, verbose_name=_('hub import type'), null=True, blank=True,
|
||||||
|
unique=True,
|
||||||
|
help_text=_('assign this group to imported hub locations of this type'))
|
||||||
|
|
||||||
objects = LocationGroupManager()
|
objects = LocationGroupManager()
|
||||||
|
|
||||||
|
|
|
@ -672,6 +672,14 @@ class DisplayLink(BaseSchema):
|
||||||
can_search: bool
|
can_search: bool
|
||||||
|
|
||||||
|
|
||||||
|
class DisplayURL(BaseSchema):
|
||||||
|
"""
|
||||||
|
A URL link for the location display
|
||||||
|
"""
|
||||||
|
title: NonEmptyStr
|
||||||
|
url: NonEmptyStr
|
||||||
|
|
||||||
|
|
||||||
class LocationDisplay(BaseSchema):
|
class LocationDisplay(BaseSchema):
|
||||||
id: AnyLocationID = APIField(
|
id: AnyLocationID = APIField(
|
||||||
description="a numeric ID for a map location or a string ID for generated locations",
|
description="a numeric ID for a map location or a string ID for generated locations",
|
||||||
|
@ -701,6 +709,7 @@ class LocationDisplay(BaseSchema):
|
||||||
Annotated[str, APIField(title="a simple string value")],
|
Annotated[str, APIField(title="a simple string value")],
|
||||||
Annotated[DisplayLink, APIField(title="a link value")],
|
Annotated[DisplayLink, APIField(title="a link value")],
|
||||||
Annotated[list[DisplayLink], APIField(title="a list of link values")],
|
Annotated[list[DisplayLink], APIField(title="a list of link values")],
|
||||||
|
Annotated[DisplayURL, APIField(title="an URL value")],
|
||||||
Annotated[None, APIField(title="no value")]
|
Annotated[None, APIField(title="no value")]
|
||||||
], APIField(title="field value", union_mode='left_to_right')]
|
], APIField(title="field value", union_mode='left_to_right')]
|
||||||
]
|
]
|
||||||
|
@ -729,7 +738,11 @@ class LocationDisplay(BaseSchema):
|
||||||
"title": "Locations that Start with E",
|
"title": "Locations that Start with E",
|
||||||
"can_search": False,
|
"can_search": False,
|
||||||
}
|
}
|
||||||
])
|
]),
|
||||||
|
("External URL", {
|
||||||
|
"title": "Open",
|
||||||
|
"url": "https://example.com/",
|
||||||
|
})
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
geometry: Union[
|
geometry: Union[
|
||||||
|
|
|
@ -443,6 +443,10 @@ c3nav = {
|
||||||
elem.append($('<dd>').text(line[1]));
|
elem.append($('<dd>').text(line[1]));
|
||||||
} else if (line[1] === null || line.length === 0) {
|
} else if (line[1] === null || line.length === 0) {
|
||||||
elem.append($('<dd>').text('-'));
|
elem.append($('<dd>').text('-'));
|
||||||
|
} else if (line[1].length === undefined && line[2].url !== undefined) {
|
||||||
|
loclist = $('<dd>');
|
||||||
|
loclist.append($('<a>').attr('href', line[2].url).attr('target', '_blank').text(line[2].title));
|
||||||
|
elem.append(loclist);
|
||||||
} else {
|
} else {
|
||||||
sublocations = (line[1].length === undefined) ? [line[1]] : line[1];
|
sublocations = (line[1].length === undefined) ? [line[1]] : line[1];
|
||||||
loclist = $('<dd>');
|
loclist = $('<dd>');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue