From 4ade6cfc1f3bba6a102ca71ddad3024d636d5409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Fri, 22 Dec 2023 01:19:53 +0100 Subject: [PATCH] add external_url and hub_import_type --- src/c3nav/editor/forms.py | 4 +- .../migrations/0094_hub_import_prepare.py | 43 +++++++++++++++++++ src/c3nav/mapdata/models/locations.py | 10 +++++ src/c3nav/mapdata/schemas/models.py | 15 ++++++- src/c3nav/site/static/site/js/c3nav.js | 4 ++ 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/c3nav/mapdata/migrations/0094_hub_import_prepare.py diff --git a/src/c3nav/editor/forms.py b/src/c3nav/editor/forms.py index 4c28d8cc..ae54a481 100644 --- a/src/c3nav/editor/forms.py +++ b/src/c3nav/editor/forms.py @@ -299,7 +299,7 @@ class EditorFormBase(I18nModelFormMixin, ModelForm): def create_editor_form(editor_model): 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', 'icon_name', 'base_altitude', 'waytype', 'access_restriction', 'default_height', 'door_height', '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', 'label_settings', 'label_override', 'min_zoom', 'max_zoom', 'font_size', '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] existing_fields = [name for name in possible_fields if name in field_names] diff --git a/src/c3nav/mapdata/migrations/0094_hub_import_prepare.py b/src/c3nav/mapdata/migrations/0094_hub_import_prepare.py new file mode 100644 index 00000000..7323606c --- /dev/null +++ b/src/c3nav/mapdata/migrations/0094_hub_import_prepare.py @@ -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'), + ), + ] diff --git a/src/c3nav/mapdata/models/locations.py b/src/c3nav/mapdata/models/locations.py index 8fd21018..400e7f3c 100644 --- a/src/c3nav/mapdata/models/locations.py +++ b/src/c3nav/mapdata/models/locations.py @@ -178,6 +178,7 @@ class SpecificLocation(Location, models.Model): label_settings = models.ForeignKey('mapdata.LabelSettings', null=True, blank=True, on_delete=models.PROTECT, verbose_name=_('label settings')) 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: abstract = True @@ -237,6 +238,12 @@ class SpecificLocation(Location, models.Model): } 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 @cached_property @@ -347,6 +354,9 @@ class LocationGroup(Location, models.Model): can_report_missing = models.BooleanField(default=False, verbose_name=_('for missing locations'), help_text=_('can be used when reporting a missing location')) 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() diff --git a/src/c3nav/mapdata/schemas/models.py b/src/c3nav/mapdata/schemas/models.py index 1a651f45..1d5fbedd 100644 --- a/src/c3nav/mapdata/schemas/models.py +++ b/src/c3nav/mapdata/schemas/models.py @@ -672,6 +672,14 @@ class DisplayLink(BaseSchema): can_search: bool +class DisplayURL(BaseSchema): + """ + A URL link for the location display + """ + title: NonEmptyStr + url: NonEmptyStr + + class LocationDisplay(BaseSchema): id: AnyLocationID = APIField( 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[DisplayLink, APIField(title="a link value")], Annotated[list[DisplayLink], APIField(title="a list of link values")], + Annotated[DisplayURL, APIField(title="an URL value")], Annotated[None, APIField(title="no value")] ], APIField(title="field value", union_mode='left_to_right')] ] @@ -729,7 +738,11 @@ class LocationDisplay(BaseSchema): "title": "Locations that Start with E", "can_search": False, } - ]) + ]), + ("External URL", { + "title": "Open", + "url": "https://example.com/", + }) ] ) geometry: Union[ diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index e528511f..9ce1b32f 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -443,6 +443,10 @@ c3nav = { elem.append($('
').text(line[1])); } else if (line[1] === null || line.length === 0) { elem.append($('
').text('-')); + } else if (line[1].length === undefined && line[2].url !== undefined) { + loclist = $('
'); + loclist.append($('').attr('href', line[2].url).attr('target', '_blank').text(line[2].title)); + elem.append(loclist); } else { sublocations = (line[1].length === undefined) ? [line[1]] : line[1]; loclist = $('
');