feat: implement thematic filtering for inspection list views with updated asset category logic
This commit is contained in:
parent
7614d56112
commit
fb1ad643a9
2 changed files with 56 additions and 5 deletions
|
|
@ -42,11 +42,28 @@ class InspectionModelAndViewsTestCase(TestCase):
|
|||
code='parking',
|
||||
defaults={'name_fr': 'Stationnement'}
|
||||
)
|
||||
UserThematics.objects.create(
|
||||
user_config=config,
|
||||
thematic=self.thematic,
|
||||
can_view_assets=True,
|
||||
can_edit_assets=True
|
||||
)
|
||||
|
||||
from assets.models import AssetCategory
|
||||
self.parking_cat, _ = AssetCategory.objects.get_or_create(
|
||||
code='parking_spot',
|
||||
thematic=self.thematic,
|
||||
defaults={
|
||||
'name_fr': 'Emplacements de stationnement',
|
||||
'name_nl': 'Parkeerplaatsen'
|
||||
}
|
||||
)
|
||||
self.spot = ParkingSpot.objects.create(
|
||||
name_fr='Emplacement Vélo Test'
|
||||
name_fr='Emplacement Vélo Test',
|
||||
category=self.parking_cat
|
||||
)
|
||||
self.spot_ct = ContentType.objects.get_for_model(ParkingSpot)
|
||||
self.parking_cat.allowed_models.add(self.spot_ct)
|
||||
|
||||
self.rwiz = NatureRWIZ.objects.create(
|
||||
name_fr='Zone GIEP Test'
|
||||
|
|
@ -327,8 +344,38 @@ class InspectionModelAndViewsTestCase(TestCase):
|
|||
self.client.login(username='inspector_user', password='password123')
|
||||
url = reverse('inspections:delete_inspection_document_api', kwargs={'document_id': doc.id})
|
||||
response = self.client.post(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTrue(response.json()['success'])
|
||||
|
||||
self.assertFalse(InspectionDocument.objects.filter(id=doc.id).exists())
|
||||
|
||||
def test_inspections_list_thematic_filter(self):
|
||||
self.client.login(username='inspector_user', password='password123')
|
||||
|
||||
# Create inspections on both water and parking
|
||||
insp_water = Inspection.objects.create(
|
||||
asset_content_type=self.rwiz_ct,
|
||||
asset_object_id=self.rwiz.id,
|
||||
inspector=self.user,
|
||||
result_status='compliant'
|
||||
)
|
||||
insp_parking = Inspection.objects.create(
|
||||
asset_content_type=self.spot_ct,
|
||||
asset_object_id=self.spot.id,
|
||||
inspector=self.user,
|
||||
result_status='compliant'
|
||||
)
|
||||
|
||||
url = reverse('inspections:inspections_list')
|
||||
|
||||
# Filter water thematic
|
||||
resp_water = self.client.get(url, {'thematic': 'water', 'tab': 'all'})
|
||||
self.assertEqual(resp_water.status_code, 200)
|
||||
inspections_water = list(resp_water.context['inspections'])
|
||||
self.assertIn(insp_water, inspections_water)
|
||||
self.assertNotIn(insp_parking, inspections_water)
|
||||
|
||||
# Filter parking thematic
|
||||
resp_parking = self.client.get(url, {'thematic': 'parking', 'tab': 'all'})
|
||||
self.assertEqual(resp_parking.status_code, 200)
|
||||
inspections_parking = list(resp_parking.context['inspections'])
|
||||
self.assertIn(insp_parking, inspections_parking)
|
||||
self.assertNotIn(insp_water, inspections_parking)
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,11 @@ def inspections_list(request):
|
|||
try:
|
||||
thematic = Thematic.objects.get(code=thematic_code)
|
||||
categories = AssetCategory.objects.filter(thematic=thematic)
|
||||
cts = ContentType.objects.filter(assetcategory__in=categories).distinct()
|
||||
cts = set(ContentType.objects.filter(asset_categories__in=categories).distinct())
|
||||
if thematic_code == 'water':
|
||||
from assets.models.nature import NatureRWIZ, NatureRWIAsset
|
||||
cts.add(ContentType.objects.get_for_model(NatureRWIZ))
|
||||
cts.add(ContentType.objects.get_for_model(NatureRWIAsset))
|
||||
qs = qs.filter(asset_content_type__in=cts)
|
||||
except Thematic.DoesNotExist:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue