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

Commit

Permalink
Merge pull request #990 from yverdon/feature/yc-1193
Browse files Browse the repository at this point in the history
YC-1193
  • Loading branch information
AlexandreJunod authored May 28, 2024
2 parents cc2f359 + 15db952 commit 507736b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions geocity/apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ class AdministrativeEntityAdmin(IntegratorFilterMixin, admin.ModelAdmin):
{
"fields": (
"name",
"agenda_domain",
"agenda_name",
"tags",
"ofs_id",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.11 on 2024-05-03 13:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0018_administrativeentity_agenda_name_and_more"),
]

operations = [
migrations.AddField(
model_name="administrativeentity",
name="agenda_domain",
field=models.CharField(
blank=True,
help_text="Utilisé afin de sélectionner les agendas visible dans agenda-embed",
max_length=128,
verbose_name="Domaine de l'agenda",
),
),
]
20 changes: 20 additions & 0 deletions geocity/apps/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ def associated_to_user(self, user):

class AdministrativeEntity(models.Model):
name = models.CharField(_("name"), max_length=128)
agenda_domain = models.CharField(
_("Domaine de l'agenda"),
help_text=_(
"Utilisé afin de sélectionner les agendas visible dans agenda-embed"
),
max_length=128,
blank=True,
)
agenda_name = models.CharField(
_("Nom dans l'api agenda"),
help_text=_("Nom visible dans le filtre de l'agenda"),
Expand Down Expand Up @@ -442,6 +450,18 @@ def clean(self):
}
)

# Unique constraint for agenda_domain
# Cannot be used on model, because None is also subject to the constraint (blank=True)
if self.agenda_domain:
if (
AdministrativeEntity.objects.exclude(pk=self.pk)
.filter(agenda_domain=self.agenda_domain)
.exists()
):
raise ValidationError(
{"agenda_domain": _("Le domaine de l'agenda doit être unique.")}
)

if (
not self.is_single_form_submissions
and Form.objects.filter(
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 @@ -964,7 +964,7 @@ def get_available_filters_for_agenda_as_qs(domains):

entity = (
AdministrativeEntity.objects.filter(
tags__name=domain,
agenda_domain=domain,
forms__agenda_visible=True,
)
.distinct()
Expand Down
3 changes: 1 addition & 2 deletions geocity/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,10 @@ def get_queryset(self):
domain_filter = query_params.getlist("domain_filter")
entities = AdministrativeEntity.objects.filter(id__in=domain_filter)
submissions = get_agenda_submissions(entities, submissions)

elif "domain" in query_params:
domains = query_params["domain"]
domains = domains.split(",") if domains else None
entities = AdministrativeEntity.objects.filter(tags__name__in=domains)
entities = AdministrativeEntity.objects.filter(agenda_domain__in=domains)
submissions = get_agenda_submissions(entities, submissions)

if "starts_at" in query_params:
Expand Down
4 changes: 2 additions & 2 deletions geocity/tests/api/test_agenda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setUp(self):
self.sit_integrator_group = factories.IntegratorGroupFactory(department=None)
self.sit_pilot_group = factories.SecretariatGroupFactory(department=None)
self.sit_administrative_entity = factories.AdministrativeEntityFactory(
tags=["sit"], integrator=self.sit_integrator_group
agenda_domain="sit", integrator=self.sit_integrator_group
)

factories.IntegratorPermitDepartmentFactory(
Expand Down Expand Up @@ -435,7 +435,7 @@ def setUp(self):
self.fin_integrator_group = factories.IntegratorGroupFactory(department=None)
self.fin_group = factories.SecretariatGroupFactory(department=None)
self.fin_administrative_entity = factories.AdministrativeEntityFactory(
tags=["fin"], integrator=self.fin_integrator_group
agenda_domain="fin", integrator=self.fin_integrator_group
)

factories.IntegratorPermitDepartmentFactory(
Expand Down

0 comments on commit 507736b

Please sign in to comment.