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

Commit

Permalink
add action button to automate integrator creation
Browse files Browse the repository at this point in the history
  • Loading branch information
monodo committed May 28, 2024
1 parent 507736b commit 17d224c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
61 changes: 60 additions & 1 deletion geocity/apps/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from uuid import uuid4

from django import forms
from django.conf import settings
from django.contrib import admin, messages
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
1 change: 1 addition & 0 deletions geocity/apps/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "admin/change_list.html" %}
{% load i18n %}

{% block object-tools-items %}
<a href="{% url "admin:create_integrator" %}" class="btn btn-success float-right">
<i class="fa fa-plus-circle"></i> &nbsp; Créer un intégrateur
</a>
{{ block.super }}
{% endblock %}
2 changes: 1 addition & 1 deletion geocity/apps/submissions/management/commands/fixturize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 17d224c

Please sign in to comment.