diff --git a/geocity/apps/accounts/admin.py b/geocity/apps/accounts/admin.py index 2456015be..0ba70660c 100644 --- a/geocity/apps/accounts/admin.py +++ b/geocity/apps/accounts/admin.py @@ -1,3 +1,5 @@ +from uuid import uuid4 + from django import forms from django.conf import settings from django.contrib import admin, messages @@ -75,7 +77,8 @@ def filter_for_user(user, qs): if not user.is_superuser: qs = qs.filter( integrator__in=user.groups.filter( - permit_department__is_integrator_admin=True + permit_department__is_integrator_admin=True, + permit_department__integrator__isnull=False, ) ) return qs @@ -524,6 +527,7 @@ def has_delete_permission(self, request, obj=None): class GroupAdmin(BaseGroupAdmin): + change_list_template = "accounts/admin/group_change_list.html" inlines = (PermitDepartmentInline, UserInline) form = GroupAdminForm list_display = [ @@ -648,6 +652,61 @@ def formfield_for_manytomany(self, db_field, request, **kwargs): return super().formfield_for_manytomany(db_field, request, **kwargs) + def create_integrator(self, request): + + administrative_entity = AdministrativeEntity.objects.create( + name=str(uuid4()), + ofs_id=9999, + geom="SRID=2056;MultiPolygon (((2518409 1150276, 2517764 1190494, 2575188 1193290, 2579489 1152641, 2518409 1150276)))", + is_single_form_submissions=True, + services_fees_hourly_rate=154, + ) + + group = Group.objects.create(name=str(uuid4())) + models.PermitDepartment.objects.create( + group=group, + administrative_entity=administrative_entity, + is_validator=False, + is_integrator_admin=True, + is_backoffice=False, + is_default_validator=False, + integrator=None, + ) + + message = _( + "Nouvel intégrateur créé avec succès, vous devez maintenant finaliser la configuration du groupe et de son entité administrative: " + ) + + messages.add_message( + request, + messages.SUCCESS, + f"{message} {administrative_entity.pk}", + ) + + return redirect( + reverse( + "admin:auth_group_change", + kwargs={"object_id": group.pk}, + ) + ) + + def set_statuses_for_entity(self, administrative_entity): + for status_value in Submission.STATUS_CHOICES: + SubmissionWorkflowStatus.objects.get_or_create( + status=status_value[0], administrative_entity=administrative_entity + ) + + def get_urls(self): + urls = super().get_urls() + + return [ + path( + "create-integrator/", + self.admin_site.admin_view(self.create_integrator), + name="create_integrator", + ), + ] + urls + class SiteWithAdministrativeEntitiesField(forms.ModelMultipleChoiceField): def label_from_instance(self, obj): diff --git a/geocity/apps/accounts/migrations/0020_allow_null_for_integrator_on_permitdepartment.py b/geocity/apps/accounts/migrations/0020_allow_null_for_integrator_on_permitdepartment.py new file mode 100644 index 000000000..d01e59b51 --- /dev/null +++ b/geocity/apps/accounts/migrations/0020_allow_null_for_integrator_on_permitdepartment.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-05-28 13:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0019_administrativeentity_agenda_domain'), + ] + + operations = [ + migrations.AlterField( + model_name='permitdepartment', + name='integrator', + field=models.IntegerField(default=0, help_text='Identifiant du groupe', null=True, verbose_name='Groupe des administrateurs'), + ), + ] diff --git a/geocity/apps/accounts/models.py b/geocity/apps/accounts/models.py index bc208a22a..db6909627 100644 --- a/geocity/apps/accounts/models.py +++ b/geocity/apps/accounts/models.py @@ -177,6 +177,7 @@ class PermitDepartment(models.Model): _("Groupe des administrateurs"), help_text=_("Identifiant du groupe"), default=0, + null=True, ) is_integrator_admin = models.BooleanField( _("Intégrateur"), diff --git a/geocity/apps/accounts/templates/accounts/admin/group_change_list.html b/geocity/apps/accounts/templates/accounts/admin/group_change_list.html new file mode 100644 index 000000000..f456049d9 --- /dev/null +++ b/geocity/apps/accounts/templates/accounts/admin/group_change_list.html @@ -0,0 +1,9 @@ +{% extends "admin/change_list.html" %} +{% load i18n %} + +{% block object-tools-items %} + +   Créer un intégrateur + + {{ block.super }} +{% endblock %} \ No newline at end of file diff --git a/geocity/apps/submissions/management/commands/fixturize.py b/geocity/apps/submissions/management/commands/fixturize.py index 7a9cebffd..7d4eb3919 100644 --- a/geocity/apps/submissions/management/commands/fixturize.py +++ b/geocity/apps/submissions/management/commands/fixturize.py @@ -1104,7 +1104,7 @@ def create_administrative_entity(self, entity, ofs_id, geom): administrative_entity.sites.add(Site.objects.get(name="default site")) self.set_statuses_for_entity(administrative_entity) - return administrative_entity + return "coucou" def set_statuses_for_entity(self, administrative_entity): for status_value in Submission.STATUS_CHOICES: