refactor: update document sequencing logic and refresh internationalization message catalogs

This commit is contained in:
kdeterme 2026-08-31 13:32:10 +02:00
parent 5f8a771277
commit 14ab4d15df
8 changed files with 3211 additions and 2775 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -72,7 +72,7 @@ def get_sequenced_intervention_documents(intervention) -> Dict[str, Any]:
"""
Organise les documents et photos de l'intervention en 3 blocs temporels :
1. before_work : Avant réalisation (préparation, constat, signalement)
2. during_work : Exécution du chantier (pendant les travaux)
2. during_work : Exécution de l'intervention (pendant les travaux)
3. after_work : Après réalisation (contrôle, levée de réserves, clôture)
Retourne un dictionnaire :
@ -165,7 +165,7 @@ def get_sequenced_intervention_documents(intervention) -> Dict[str, Any]:
},
{
'key': 'during_work',
'title': _("Exécution du chantier"),
'title': _("Exécution de l'intervention"),
'subtitle': _("Travaux en cours et constat d'achèvement"),
'icon': 'bi-tools',
'badge_class': 'bg-primary text-white',

View file

@ -142,7 +142,7 @@ class DocumentSequencingViewsTests(TestCase):
self.User = get_user_model()
self.user = self.User.objects.create_user(username='admin_user', password='password')
self.role_admin = Role.objects.create(name='admin')
self.user_config = UserConfig.objects.create(user=self.user, is_intern=True)
self.user_config = UserConfig.objects.create(user=self.user, is_intern=True, preferred_language='fr')
self.user_config.roles.add(self.role_admin)
self.thematic = Thematic.objects.create(code='road', name_fr='Route', name_nl='Weg')
@ -171,25 +171,48 @@ class DocumentSequencingViewsTests(TestCase):
InterventionDocument.objects.filter(id=doc2.id).update(upload_date=self.now - timedelta(hours=1))
self.client.force_login(self.user)
self.client.cookies['django_language'] = 'fr'
def test_desktop_detail_view_contains_sequenced_blocks(self):
url = reverse('interventions:intervention_detail', args=[self.intervention.id])
response = self.client.get(url + '?force_desktop=1')
self.assertEqual(response.status_code, 200)
self.assertIn('document_blocks', response.context)
self.assertEqual(response.context['total_documents_count'], 2)
from django.utils import translation
with translation.override('fr'):
url = reverse('interventions:intervention_detail', args=[self.intervention.id])
response = self.client.get(url + '?force_desktop=1')
self.assertEqual(response.status_code, 200)
self.assertIn('document_blocks', response.context)
self.assertEqual(response.context['total_documents_count'], 2)
content = response.content.decode('utf-8')
self.assertIn('Avant réalisation', content)
self.assertIn('Exécution du chantier', content)
import html
content = html.unescape(response.content.decode('utf-8'))
self.assertIn('Avant réalisation', content)
self.assertIn("Exécution de l'intervention", content)
def test_mobile_detail_view_contains_sequenced_blocks(self):
url = reverse('interventions:intervention_detail_mobile', args=[self.intervention.id])
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertIn('document_blocks', response.context)
self.assertEqual(response.context['total_documents_count'], 2)
from django.utils import translation
with translation.override('fr'):
url = reverse('interventions:intervention_detail_mobile', args=[self.intervention.id])
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertIn('document_blocks', response.context)
self.assertEqual(response.context['total_documents_count'], 2)
content = response.content.decode('utf-8')
self.assertIn('Avant réalisation', content)
self.assertIn('Exécution du chantier', content)
import html
content = html.unescape(response.content.decode('utf-8'))
self.assertIn('Avant réalisation', content)
self.assertIn("Exécution de l'intervention", content)
def test_translations_nl_and_en(self):
from django.utils import translation
with translation.override('nl'):
res_nl = get_sequenced_intervention_documents(self.intervention)
titles_nl = [b['title'] for b in res_nl['blocks']]
self.assertIn('Vóór uitvoering', titles_nl)
self.assertIn('Uitvoering van de interventie', titles_nl)
self.assertIn('Na uitvoering', titles_nl)
with translation.override('en'):
res_en = get_sequenced_intervention_documents(self.intervention)
titles_en = [b['title'] for b in res_en['blocks']]
self.assertIn('Before realization', titles_en)
self.assertIn('Execution of the intervention', titles_en)
self.assertIn('After realization', titles_en)