From 0660f76ee7e964012fd94e1ef18d483942741367 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Fri, 8 Oct 2021 09:47:52 +0200 Subject: [PATCH] api: display category on agenda details (#57670) --- chrono/api/views.py | 3 ++- tests/api/test_all.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/chrono/api/views.py b/chrono/api/views.py index e33a54aa..351640cc 100644 --- a/chrono/api/views.py +++ b/chrono/api/views.py @@ -355,6 +355,7 @@ def get_agenda_detail(request, agenda, check_events=False): 'maximal_booking_delay': agenda.maximal_booking_delay, 'edit_role': agenda.edit_role.name if agenda.edit_role else None, 'view_role': agenda.view_role.name if agenda.view_role else None, + 'category': agenda.category.slug if agenda.category else None, } if agenda.kind == 'meetings': @@ -705,7 +706,7 @@ class Agendas(APIView): def get(self, request, format=None): agendas_queryset = ( Agenda.objects.all() - .select_related('absence_reasons_group') + .select_related('absence_reasons_group', 'category') .prefetch_related('resources', 'absence_reasons_group__absence_reasons') .order_by('label') ) diff --git a/tests/api/test_all.py b/tests/api/test_all.py index 8c4699a7..f25c2604 100644 --- a/tests/api/test_all.py +++ b/tests/api/test_all.py @@ -68,6 +68,7 @@ def test_agendas_api(app): 'maximal_booking_delay': 56, 'edit_role': 'Edit', 'view_role': None, + 'category': 'category-a', 'absence_reasons': [ {'id': reason.slug, 'slug': reason.slug, 'text': reason.label, 'label': reason.label}, {'id': reason2.slug, 'slug': reason2.slug, 'text': reason2.label, 'label': reason2.label}, @@ -87,6 +88,7 @@ def test_agendas_api(app): 'maximal_booking_delay': 56, 'edit_role': None, 'view_role': None, + 'category': 'category-a', 'api': { 'datetimes_url': 'http://testserver/api/agenda/foo-bar-2/datetimes/', 'fillslots_url': 'http://testserver/api/agenda/foo-bar-2/fillslots/', @@ -102,6 +104,7 @@ def test_agendas_api(app): 'maximal_booking_delay': 56, 'edit_role': None, 'view_role': None, + 'category': None, 'absence_reasons': [ {'id': reason.slug, 'slug': reason.slug, 'text': reason.label, 'label': reason.label}, {'id': reason2.slug, 'slug': reason2.slug, 'text': reason2.label, 'label': reason2.label}, @@ -119,6 +122,7 @@ def test_agendas_api(app): 'maximal_booking_delay': 56, 'edit_role': None, 'view_role': 'View', + 'category': 'category-b', 'kind': 'meetings', 'resources': [ {'id': 'resource-1', 'text': 'Resource 1', 'description': 'Foo bar Resource 1'}, @@ -139,6 +143,7 @@ def test_agendas_api(app): 'maximal_booking_delay': 56, 'edit_role': None, 'view_role': None, + 'category': None, 'kind': 'meetings', 'resources': [], 'api': { @@ -156,6 +161,7 @@ def test_agendas_api(app): 'maximal_booking_delay': 56, 'edit_role': 'Edit', 'view_role': 'View', + 'category': None, 'kind': 'virtual', 'api': { 'meetings_url': 'http://testserver/api/agenda/virtual-agenda/meetings/', @@ -505,6 +511,7 @@ def test_virtual_agenda_detail(app, virtual_meetings_agenda): 'maximal_booking_delay': None, 'edit_role': None, 'view_role': None, + 'category': None, 'kind': 'virtual', 'api': { 'meetings_url': 'http://testserver/api/agenda/%s/meetings/' % virtual_meetings_agenda.slug,