Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

[YC-1197] Rename ofs_id #1015

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions geocity/apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ class Meta:
fields = [
"name",
"tags",
"ofs_id",
"group_order",
"is_single_form_submissions",
"sites",
"expeditor_email",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.11 on 2024-05-30 08:58
# Generated by Django 4.2.11 on 2024-06-24 09:45

import django.core.validators
from django.db import migrations, models
Expand All @@ -11,6 +11,19 @@ class Migration(migrations.Migration):
]

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.<br>Affichés par ordre croissant et groupés en cas de nombre identique",
verbose_name="Groupe et ordre",
),
),
migrations.AlterField(
model_name="administrativeentity",
name="phone",
Expand Down
10 changes: 8 additions & 2 deletions geocity/apps/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def associated_to_user(self, user):
.filter(
departments__group__in=user.groups.all(),
)
.order_by("ofs_id", "name")
.order_by("group_order", "name")
)


Expand All @@ -267,7 +267,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.<br>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(
Expand Down
2 changes: 1 addition & 1 deletion geocity/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Meta:
fields = (
"id",
"name",
"ofs_id",
"group_order",
"link",
"phone",
)
Expand Down
2 changes: 1 addition & 1 deletion geocity/apps/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,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()
)

Expand Down
10 changes: 6 additions & 4 deletions geocity/apps/submissions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions geocity/apps/submissions/management/commands/fixturize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions geocity/apps/submissions/management/fixturize_data/agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions geocity/apps/submissions/management/fixturize_data/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions geocity/apps/submissions/management/fixturize_data/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion geocity/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion geocity/tests/reports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))",
)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading