Skip to content

Commit

Permalink
Ajout de l'export des demandes d'habilitation de structure (#1448)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjmad authored Oct 29, 2024
2 parents 751304e + f94e624 commit 5df4e11
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
51 changes: 50 additions & 1 deletion aidants_connect_habilitation/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from zoneinfo import ZoneInfo

from django.conf import settings
from django.contrib import admin, messages
from django.contrib.admin import (
Expand All @@ -14,10 +16,14 @@
from django.shortcuts import render
from django.template import loader
from django.urls import path, reverse
from django.utils import timezone
from django.utils.html import linebreaks, urlize
from django.utils.safestring import mark_safe

from django_reverse_admin import ReverseInlineModelAdmin, ReverseModelAdmin
from import_export import resources
from import_export.admin import ImportExportMixin
from import_export.fields import Field

from aidants_connect.admin import VisibleToAdminMetier, VisibleToTechAdmin, admin_site
from aidants_connect_common.admin import DepartmentFilter, RegionFilter
Expand Down Expand Up @@ -163,8 +169,51 @@ def queryset(self, request, queryset):
return queryset


class OrganisationRequestResource(resources.ModelResource):
request_created_at = Field()
request_updated_at = Field()

def dehydrate_request_created_at(self, orga_request):
return timezone.make_naive(orga_request.created_at, ZoneInfo("Europe/Paris"))

def dehydrate_request_updated_at(self, orga_request):
return timezone.make_naive(orga_request.updated_at, ZoneInfo("Europe/Paris"))

class Meta:
model = OrganisationRequest
fields = (
"request_created_at",
"request_updated_at",
"status",
"name",
"siret",
"legal_category",
"type__name",
"type_other",
"address",
"zipcode",
"city",
"is_private_org",
"france_services_label",
"france_services_number",
"issuer__last_name",
"issuer__first_name",
"issuer__profession",
"issuer__phone",
"manager__email",
"manager__last_name",
"manager__first_name",
"manager__profession",
"manager__email",
"manager__phone",
)


@admin.register(OrganisationRequest, site=admin_site)
class OrganisationRequestAdmin(VisibleToAdminMetier, ReverseModelAdmin):
class OrganisationRequestAdmin(
ImportExportMixin, VisibleToAdminMetier, ReverseModelAdmin
):
resource_classes = [OrganisationRequestResource]
list_filter = (
RegionFilter,
DepartmentFilter,
Expand Down
26 changes: 26 additions & 0 deletions aidants_connect_habilitation/tests/test_admin_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.contrib.admin.sites import AdminSite
from django.test import TestCase, tag
from django.test.client import RequestFactory

from aidants_connect_habilitation.admin import OrganisationRequestAdmin
from aidants_connect_habilitation.models import OrganisationRequest
from aidants_connect_habilitation.tests.factories import OrganisationRequestFactory


@tag("admin")
class OrganisationRequestResourceTestCase(TestCase):

@classmethod
def setUpTestData(cls):
cls.rf = RequestFactory()
cls.orga_request_1 = OrganisationRequestFactory(name="MAIRIE 1")
cls.orga_request_2 = OrganisationRequestFactory(name="MAIRIE 2")

def test_export_organisation_request(self):
request = self.rf.get("/", {})
orga_requests = OrganisationRequest.objects.all()
orga_request_admin = OrganisationRequestAdmin(OrganisationRequest, AdminSite())
data = orga_request_admin.get_data_for_export(request, orga_requests)
self.assertEqual(len(data), 2)
self.assertEqual(data[0][3], "MAIRIE 1")
self.assertEqual(data[1][3], "MAIRIE 2")

0 comments on commit 5df4e11

Please sign in to comment.