add migration that overhauls report flow settings

This commit is contained in:
Laura Klünder 2024-03-24 15:24:36 +01:00
parent 868317dabf
commit 482da3b244
5 changed files with 74 additions and 7 deletions

View file

@ -413,8 +413,8 @@ def create_editor_form(editor_model):
'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',
'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor', 'groundaltitude', 'origin_space', 'target_space', 'data', 'comment', 'slow_down_factor', 'groundaltitude',
'extra_seconds', 'speed', 'description', 'speed_up', 'description_up', 'enter_description', 'extra_seconds', 'speed', 'can_report_missing', 'description', 'speed_up', 'description_up',
'level_change_description', 'base_mapdata_accessible', 'can_report_missing', 'report_help_text', 'enter_description', 'level_change_description', 'base_mapdata_accessible',
'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',

View file

@ -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'),
),
]

View file

@ -351,6 +351,12 @@ class LocationGroupManager(models.Manager):
class LocationGroup(Location, models.Model): 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, category = models.ForeignKey(LocationGroupCategory, related_name='groups', on_delete=models.PROTECT,
verbose_name=_('Category')) verbose_name=_('Category'))
priority = models.IntegerField(default=0, db_index=True) 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, label_settings = models.ForeignKey('mapdata.LabelSettings', null=True, blank=True, on_delete=models.PROTECT,
verbose_name=_('label settings'), verbose_name=_('label settings'),
help_text=_('unless location specifies otherwise')) help_text=_('unless location specifies otherwise'))
can_report_missing = models.BooleanField(default=False, verbose_name=_('for missing locations'), can_report_missing = models.CharField(_('report missing location'), choices=CanReportMissing.choices,
help_text=_('can be used when reporting a missing location')) 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')) 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, hub_import_type = models.CharField(max_length=100, verbose_name=_('hub import type'), null=True, blank=True,
unique=True, unique=True,

View file

@ -50,7 +50,6 @@ class Report(models.Model):
created_title = I18nField(_('new location title'), plural_name='titles', blank=False, fallback_any=True, 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')) 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, 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='+') help_text=_('select all groups that apply, if any'), related_name='+')
secret = models.CharField(_('secret'), max_length=32, default=get_report_secret) secret = models.CharField(_('secret'), max_length=32, default=get_report_secret)

View file

@ -6,6 +6,7 @@ from pydantic import NonNegativeFloat, PositiveFloat, PositiveInt
from c3nav.api.schema import BaseSchema, GeometrySchema, PointSchema from c3nav.api.schema import BaseSchema, GeometrySchema, PointSchema
from c3nav.api.utils import NonEmptyStr from c3nav.api.utils import NonEmptyStr
from c3nav.mapdata.models import LocationGroup
from c3nav.mapdata.schemas.model_base import (AnyLocationID, AnyPositionID, CustomLocationID, DjangoModelSchema, from c3nav.mapdata.schemas.model_base import (AnyLocationID, AnyPositionID, CustomLocationID, DjangoModelSchema,
LabelSettingsSchema, LocationSchema, PositionID, LabelSettingsSchema, LocationSchema, PositionID,
SimpleGeometryLocationsSchema, SimpleGeometryPointAndBoundsSchema, SimpleGeometryLocationsSchema, SimpleGeometryPointAndBoundsSchema,
@ -238,9 +239,9 @@ class LocationGroupSchema(LocationSchema, DjangoModelSchema):
"\n\nlocations can override this setting" "\n\nlocations can override this setting"
) )
) )
can_report_missing: bool = APIField( can_report_missing: LocationGroup.CanReportMissing = APIField(
title="report missing locations", 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[ color: Union[
Annotated[NonEmptyStr, APIField(title="color", description="a valid CSS color expression")], Annotated[NonEmptyStr, APIField(title="color", description="a valid CSS color expression")],