From 6faf398daf341cb767007da237bde943b21e0f43 Mon Sep 17 00:00:00 2001 From: AlexandreJunod Date: Mon, 3 Jun 2024 09:12:55 +0200 Subject: [PATCH] rename ofs_id --- geocity/apps/accounts/admin.py | 6 ++--- ...ve_administrativeentity_ofs_id_and_more.py | 26 +++++++++++++++++++ geocity/apps/accounts/models.py | 10 +++++-- geocity/apps/api/serializers.py | 2 +- geocity/apps/forms/models.py | 2 +- geocity/apps/submissions/forms.py | 10 ++++--- .../management/commands/fixturize.py | 6 ++--- .../management/fixturize_data/agenda.py | 4 +-- .../management/fixturize_data/demo.py | 4 +-- .../management/fixturize_data/generic.py | 4 +-- geocity/tests/factories.py | 2 +- geocity/tests/reports/base.py | 2 +- locale/de/LC_MESSAGES/django.po | 2 +- locale/en/LC_MESSAGES/django.po | 2 +- locale/fr/LC_MESSAGES/django.po | 2 +- locale/it/LC_MESSAGES/django.po | 2 +- 16 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 geocity/apps/accounts/migrations/0020_remove_administrativeentity_ofs_id_and_more.py diff --git a/geocity/apps/accounts/admin.py b/geocity/apps/accounts/admin.py index 22300ba77..b75e2dbfb 100644 --- a/geocity/apps/accounts/admin.py +++ b/geocity/apps/accounts/admin.py @@ -690,7 +690,7 @@ class Meta: fields = [ "name", "tags", - "ofs_id", + "group_order", "is_single_form_submissions", "sites", "expeditor_email", @@ -784,7 +784,7 @@ class AdministrativeEntityAdmin(IntegratorFilterMixin, admin.ModelAdmin): "agenda_domain", "agenda_name", "tags", - "ofs_id", + "group_order", "is_single_form_submissions", "sites", "expeditor_email", @@ -875,7 +875,7 @@ def __new__(cls, *args, **kwargs): "expeditor_name", "expeditor_email", "reply_to_email", - "ofs_id", + "group_order", "get_tags", "get_is_single_form", "get_sites", diff --git a/geocity/apps/accounts/migrations/0020_remove_administrativeentity_ofs_id_and_more.py b/geocity/apps/accounts/migrations/0020_remove_administrativeentity_ofs_id_and_more.py new file mode 100644 index 000000000..15b7aa098 --- /dev/null +++ b/geocity/apps/accounts/migrations/0020_remove_administrativeentity_ofs_id_and_more.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.11 on 2024-06-03 07:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0019_administrativeentity_agenda_domain"), + ] + + operations = [ + migrations.RemoveField( + model_name="administrativeentity", + name="ofs_id", + ), + migrations.AddField( + model_name="administrativeentity", + name="group_order", + field=models.PositiveIntegerField( + default=0, + help_text="Utilisé afin de grouper et définir l'ordre des entités.
Affichés par ordre croissant et groupés en cas de nombre identique", + verbose_name="Groupe et ordre", + ), + ), + ] diff --git a/geocity/apps/accounts/models.py b/geocity/apps/accounts/models.py index bc208a22a..6c8facadd 100644 --- a/geocity/apps/accounts/models.py +++ b/geocity/apps/accounts/models.py @@ -251,7 +251,7 @@ def associated_to_user(self, user): .filter( departments__group__in=user.groups.all(), ) - .order_by("ofs_id", "name") + .order_by("group_order", "name") ) @@ -271,7 +271,13 @@ class AdministrativeEntity(models.Model): max_length=128, blank=True, ) - ofs_id = models.PositiveIntegerField(_("Numéro OFS")) + group_order = models.PositiveIntegerField( + _("Groupe et ordre"), + default=0, + help_text=_( + "Utilisé afin de grouper et définir l'ordre des entités.
Affichés par ordre croissant et groupés en cas de nombre identique" + ), + ) link = models.URLField(_("Lien"), max_length=200, blank=True) archive_link = models.URLField(_("Archives externes"), max_length=1024, blank=True) general_informations = models.CharField( diff --git a/geocity/apps/api/serializers.py b/geocity/apps/api/serializers.py index 9a165860f..fce5a38e1 100644 --- a/geocity/apps/api/serializers.py +++ b/geocity/apps/api/serializers.py @@ -234,7 +234,7 @@ class Meta: fields = ( "id", "name", - "ofs_id", + "group_order", "link", "phone", ) diff --git a/geocity/apps/forms/models.py b/geocity/apps/forms/models.py index 3d58c8a44..1849aef15 100644 --- a/geocity/apps/forms/models.py +++ b/geocity/apps/forms/models.py @@ -114,7 +114,7 @@ def get_administrative_entities_with_forms(self, user, site=None): pk__in=self.values_list("administrative_entities", flat=True), forms__is_anonymous=False, ) - .order_by("ofs_id", "name") + .order_by("group_order", "name") .distinct() ) diff --git a/geocity/apps/submissions/forms.py b/geocity/apps/submissions/forms.py index 903150034..ae581ca80 100644 --- a/geocity/apps/submissions/forms.py +++ b/geocity/apps/submissions/forms.py @@ -109,8 +109,10 @@ def get_field_cls_for_field(field): raise KeyError(f"Field of type {e} is not supported.") -def regroup_by_ofs_id(entities): - return groupby(entities.order_by("ofs_id", "name"), lambda entity: entity.ofs_id) +def regroup_by_group_order(entities): + return groupby( + entities.order_by("group_order", "name"), lambda entity: entity.group_order + ) def disable_form(form, editable_fields=None): @@ -184,8 +186,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["administrative_entity"].choices = [ - (ofs_id, [(entity.pk, entity.name) for entity in entities]) - for ofs_id, entities in regroup_by_ofs_id(administrative_entities) + (group_order, [(entity.pk, entity.name) for entity in entities]) + for group_order, entities in regroup_by_group_order(administrative_entities) ] def save(self, author): diff --git a/geocity/apps/submissions/management/commands/fixturize.py b/geocity/apps/submissions/management/commands/fixturize.py index 7a9cebffd..2397c56fe 100644 --- a/geocity/apps/submissions/management/commands/fixturize.py +++ b/geocity/apps/submissions/management/commands/fixturize.py @@ -193,7 +193,7 @@ def handle(self, *args, **options): self.setup_site(entity) self.stdout.write(" • Creating administrative entity...") administrative_entity = self.create_administrative_entity( - entity, module.ofs_ids[idx], module.geoms[idx] + entity, module.group_orders[idx], module.geoms[idx] ) self.stdout.write(" • Creating users...") integrator_group = self.create_users( @@ -1087,11 +1087,11 @@ def create_permit_department( integrator_email_domains=integrator_email_domains, ) - def create_administrative_entity(self, entity, ofs_id, geom): + def create_administrative_entity(self, entity, group_order, geom): name = f"{entity}" administrative_entity = AdministrativeEntity.objects.create( name=name, - ofs_id=ofs_id, + group_order=group_order, link="https://mapnv.ch", archive_link="https://mapnv.ch", geom=geom, diff --git a/geocity/apps/submissions/management/fixturize_data/agenda.py b/geocity/apps/submissions/management/fixturize_data/agenda.py index bca5e8e26..bf0ed85af 100644 --- a/geocity/apps/submissions/management/fixturize_data/agenda.py +++ b/geocity/apps/submissions/management/fixturize_data/agenda.py @@ -31,8 +31,8 @@ "SRID=2056;MultiPolygon (((2538391 1176432, 2538027 1178201, 2538485 1178804, 2537777 1179199, 2536748 1178450, 2536123 1179647, 2537382 1180593, 2537143 1181623, 2538651 1183257, 2540368 1183236, 2541252 1181093, 2541460 1180458, 2540160 1179543, 2540097 1178877, 2538391 1176432)))", ] -# Ofs_ids for the entities -ofs_ids = [5003, 5002, 5001] +# group_orders for the entities +group_orders = [5003, 5002, 5001] # Define the fields field_title = { diff --git a/geocity/apps/submissions/management/fixturize_data/demo.py b/geocity/apps/submissions/management/fixturize_data/demo.py index 0439765cd..b5f265ce7 100644 --- a/geocity/apps/submissions/management/fixturize_data/demo.py +++ b/geocity/apps/submissions/management/fixturize_data/demo.py @@ -30,8 +30,8 @@ "SRID=2056;MultiPolygon (((2538391 1176432, 2538027 1178201, 2538485 1178804, 2537777 1179199, 2536748 1178450, 2536123 1179647, 2537382 1180593, 2537143 1181623, 2538651 1183257, 2540368 1183236, 2541252 1181093, 2541460 1180458, 2540160 1179543, 2540097 1178877, 2538391 1176432)))", ] -# Ofs_ids for the entities -ofs_ids = [5001, 5002, 5003] +# group_orders for the entities +group_orders = [5001, 5002, 5003] # Define the fields field_comment = { diff --git a/geocity/apps/submissions/management/fixturize_data/generic.py b/geocity/apps/submissions/management/fixturize_data/generic.py index 426d1a8f0..0642fa54e 100644 --- a/geocity/apps/submissions/management/fixturize_data/generic.py +++ b/geocity/apps/submissions/management/fixturize_data/generic.py @@ -29,8 +29,8 @@ "SRID=2056;MultiPolygon (((2538391 1176432, 2538027 1178201, 2538485 1178804, 2537777 1179199, 2536748 1178450, 2536123 1179647, 2537382 1180593, 2537143 1181623, 2538651 1183257, 2540368 1183236, 2541252 1181093, 2541460 1180458, 2540160 1179543, 2540097 1178877, 2538391 1176432)))", ] -# Ofs_ids for the entities -ofs_ids = [5001, 5002, 5003, 5004, 5005] +# group_orders for the entities +group_orders = [5001, 5002, 5003, 5004, 5005] # Define the fields field_comment = { diff --git a/geocity/tests/factories.py b/geocity/tests/factories.py index 4693978af..a2f680baa 100644 --- a/geocity/tests/factories.py +++ b/geocity/tests/factories.py @@ -82,7 +82,7 @@ def groups(self, create, extracted, **kwargs): # In AgendaAPITestCase nothing was working cause FormFactory couldn't link to administrative entity. # The error was : accounts.AdministrativeEntity.None class AdministrativeEntityFactory(factory.django.DjangoModelFactory): - ofs_id = 0 + group_order = 0 name = factory.Faker("company") geom = MultiPolygon(Polygon(((1, 1), (1, 2), (2, 2), (1, 1)))) is_single_form_submissions = False diff --git a/geocity/tests/reports/base.py b/geocity/tests/reports/base.py index 7804a0ac5..eddd479e7 100644 --- a/geocity/tests/reports/base.py +++ b/geocity/tests/reports/base.py @@ -102,7 +102,7 @@ def setUp(self): # Create the admin entity admin_entity = accounts_models.AdministrativeEntity.objects.create( name="entity", - ofs_id=1, + group_order=1, integrator=group, geom="SRID=2056;MultiPolygon (((2538512 1181638, 2538447 1180620, 2539787 1180606, 2539784 1181553, 2538512 1181638)))", ) diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 6b7cd1ce6..ed9f8c5c6 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -475,7 +475,7 @@ msgid "name" msgstr "" #: geocity/apps/accounts/models.py:261 -msgid "Numéro OFS" +msgid "Groupe et ordre" msgstr "" #: geocity/apps/accounts/models.py:262 diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index f5d112787..9f5ec3ac0 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -477,7 +477,7 @@ msgid "name" msgstr "" #: geocity/apps/accounts/models.py:261 -msgid "Numéro OFS" +msgid "Groupe et ordre" msgstr "" #: geocity/apps/accounts/models.py:262 diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 17da07c15..e223052de 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -475,7 +475,7 @@ msgid "name" msgstr "" #: geocity/apps/accounts/models.py:261 -msgid "Numéro OFS" +msgid "Groupe et ordre" msgstr "" #: geocity/apps/accounts/models.py:262 diff --git a/locale/it/LC_MESSAGES/django.po b/locale/it/LC_MESSAGES/django.po index 7a39500ae..5de905a20 100644 --- a/locale/it/LC_MESSAGES/django.po +++ b/locale/it/LC_MESSAGES/django.po @@ -475,7 +475,7 @@ msgid "name" msgstr "" #: geocity/apps/accounts/models.py:261 -msgid "Numéro OFS" +msgid "Groupe et ordre" msgstr "" #: geocity/apps/accounts/models.py:262