From 482da3b244cf00edec0d14062645cfe017ba37bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Sun, 24 Mar 2024 15:24:36 +0100 Subject: [PATCH] add migration that overhauls report flow settings --- src/c3nav/editor/forms.py | 4 +- .../migrations/0103_report_flow_overhaul.py | 55 +++++++++++++++++++ src/c3nav/mapdata/models/locations.py | 16 +++++- src/c3nav/mapdata/models/report.py | 1 - src/c3nav/mapdata/schemas/models.py | 5 +- 5 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 src/c3nav/mapdata/migrations/0103_report_flow_overhaul.py diff --git a/src/c3nav/editor/forms.py b/src/c3nav/editor/forms.py index 5a5c99d9..240b90f5 100644 --- a/src/c3nav/editor/forms.py +++ b/src/c3nav/editor/forms.py @@ -413,8 +413,8 @@ def create_editor_form(editor_model): 'icon_name', 'base_altitude', 'waytype', 'access_restriction', 'default_height', 'door_height', 'outside', 'can_search', 'can_describe', 'geometry', 'single', 'altitude', 'short_label', 'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor', 'groundaltitude', - 'extra_seconds', 'speed', 'description', 'speed_up', 'description_up', 'enter_description', - 'level_change_description', 'base_mapdata_accessible', 'can_report_missing', + 'extra_seconds', 'speed', 'can_report_missing', 'description', 'speed_up', 'description_up', + 'report_help_text', 'enter_description', 'level_change_description', 'base_mapdata_accessible', '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', diff --git a/src/c3nav/mapdata/migrations/0103_report_flow_overhaul.py b/src/c3nav/mapdata/migrations/0103_report_flow_overhaul.py new file mode 100644 index 00000000..19d404af --- /dev/null +++ b/src/c3nav/mapdata/migrations/0103_report_flow_overhaul.py @@ -0,0 +1,55 @@ +# Generated by Django 5.0.1 on 2024-03-24 14:03 + +import c3nav.mapdata.fields +from django.db import migrations, models + + +def forwards_func(apps, schema_editor): + LocationGroup = apps.get_model('mapdata', 'LocationGroup') + LocationGroup.objects.filter(can_report_missing_old=True).update(can_report_missing="single") + + +def backwards_func(apps, schema_editor): + LocationGroup = apps.get_model('mapdata', 'LocationGroup') + LocationGroup.objects.exclude(can_report_missing__in=("single", "multiple")).update(can_report_missing_old=True) + + +class Migration(migrations.Migration): + + dependencies = [ + ('mapdata', '0102_rename_bssid_rangingbeacon_wifi_bssid_and_more'), + ] + + operations = [ + migrations.RenameField( + model_name='locationgroup', + old_name='can_report_missing', + new_name='can_report_missing_old', + ), + migrations.AddField( + model_name='locationgroup', + name='description', + field=c3nav.mapdata.fields.I18nField(blank=True, fallback_any=True, help_text='to aid with selection in the report form', plural_name='descriptions', verbose_name='description'), + ), + migrations.AddField( + model_name='locationgroup', + name='can_report_missing', + field=models.CharField(choices=[('dont_offer', "don't offer"), ('reject', 'offer in first step, then reject'), ('single', 'offer in first step, exclusive choice'), ('multiple', 'offer if nothing in the first step matches, multiple choice')], default='dont_offer', max_length=16, verbose_name='report missing location'), + ), + migrations.AddField( + model_name='locationgroup', + name='report_help_text', + field=c3nav.mapdata.fields.I18nField(blank=True, fallback_any=True, help_text='to explain the report form or rejection', plural_name='report_help_texts', verbose_name='report help text'), + ), + migrations.RunPython(forwards_func, backwards_func), + migrations.RemoveField( + model_name='locationgroup', + name='can_report_missing_old', + ), + migrations.AlterField( + model_name='report', + name='created_groups', + field=models.ManyToManyField(blank=True, help_text='select all groups that apply, if any', related_name='+', + to='mapdata.locationgroup', verbose_name='location groups'), + ), + ] diff --git a/src/c3nav/mapdata/models/locations.py b/src/c3nav/mapdata/models/locations.py index 3d234f5e..22a582ac 100644 --- a/src/c3nav/mapdata/models/locations.py +++ b/src/c3nav/mapdata/models/locations.py @@ -351,6 +351,12 @@ class LocationGroupManager(models.Manager): class LocationGroup(Location, models.Model): + class CanReportMissing(models.TextChoices): + DONT_OFFER = "dont_offer", _("don't offer") + REJECT = "reject", _("offer in first step, then reject") + SINGLE = "single", _("offer in first step, exclusive choice") + MULTIPLE = "multiple", _("offer if nothing in the first step matches, multiple choice") + category = models.ForeignKey(LocationGroupCategory, related_name='groups', on_delete=models.PROTECT, verbose_name=_('Category')) priority = models.IntegerField(default=0, db_index=True) @@ -358,8 +364,14 @@ class LocationGroup(Location, models.Model): label_settings = models.ForeignKey('mapdata.LabelSettings', null=True, blank=True, on_delete=models.PROTECT, verbose_name=_('label settings'), help_text=_('unless location specifies otherwise')) - can_report_missing = models.BooleanField(default=False, verbose_name=_('for missing locations'), - help_text=_('can be used when reporting a missing location')) + can_report_missing = models.CharField(_('report missing location'), choices=CanReportMissing.choices, + default=CanReportMissing.DONT_OFFER, max_length=16) + + description = I18nField(_('description'), plural_name='descriptions', blank=True, fallback_any=True, + help_text=_('to aid with selection in the report form')) + report_help_text = I18nField(_('report help text'), plural_name='report_help_texts', blank=True, fallback_any=True, + help_text=_('to explain the report form or rejection')) + 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, diff --git a/src/c3nav/mapdata/models/report.py b/src/c3nav/mapdata/models/report.py index 26f4e047..1ff98338 100644 --- a/src/c3nav/mapdata/models/report.py +++ b/src/c3nav/mapdata/models/report.py @@ -50,7 +50,6 @@ class Report(models.Model): created_title = I18nField(_('new location title'), plural_name='titles', blank=False, fallback_any=True, help_text=_('you have to supply a title in at least one language')) created_groups = models.ManyToManyField('mapdata.LocationGroup', verbose_name=_('location groups'), blank=True, - limit_choices_to={'can_report_missing': True}, help_text=_('select all groups that apply, if any'), related_name='+') secret = models.CharField(_('secret'), max_length=32, default=get_report_secret) diff --git a/src/c3nav/mapdata/schemas/models.py b/src/c3nav/mapdata/schemas/models.py index 1725c920..92f1e7d0 100644 --- a/src/c3nav/mapdata/schemas/models.py +++ b/src/c3nav/mapdata/schemas/models.py @@ -6,6 +6,7 @@ from pydantic import NonNegativeFloat, PositiveFloat, PositiveInt from c3nav.api.schema import BaseSchema, GeometrySchema, PointSchema from c3nav.api.utils import NonEmptyStr +from c3nav.mapdata.models import LocationGroup from c3nav.mapdata.schemas.model_base import (AnyLocationID, AnyPositionID, CustomLocationID, DjangoModelSchema, LabelSettingsSchema, LocationSchema, PositionID, SimpleGeometryLocationsSchema, SimpleGeometryPointAndBoundsSchema, @@ -238,9 +239,9 @@ class LocationGroupSchema(LocationSchema, DjangoModelSchema): "\n\nlocations can override this setting" ) ) - can_report_missing: bool = APIField( + can_report_missing: LocationGroup.CanReportMissing = APIField( title="report missing locations", - description="can be used in form for reporting missing locations", + description="whether this location group can be used to report missing locations", ) color: Union[ Annotated[NonEmptyStr, APIField(title="color", description="a valid CSS color expression")],