Project

General

Profile

0003-api-display-category-on-agenda-details-57670.patch

Nicolas Roche, 08 Oct 2021 03:27 PM

Download (8.05 KB)

View differences:

Subject: [PATCH 3/5] 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(-)
chrono/api/views.py
350 350
        'id': agenda.slug,
351 351
        'slug': agenda.slug,  # kept for compatibility
352 352
        'text': agenda.label,
353 353
        'kind': agenda.kind,
354 354
        'minimal_booking_delay': agenda.minimal_booking_delay,
355 355
        'maximal_booking_delay': agenda.maximal_booking_delay,
356 356
        'edit_role': agenda.edit_role.name if agenda.edit_role else None,
357 357
        'view_role': agenda.view_role.name if agenda.view_role else None,
358
        'category': agenda.category.slug if agenda.category else None,
358 359
    }
359 360

  
360 361
    if agenda.kind == 'meetings':
361 362
        agenda_detail['resources'] = [
362 363
            {'id': r.slug, 'text': r.label, 'description': r.description} for r in agenda.resources.all()
363 364
        ]
364 365
    if agenda.kind == 'events':
365 366
        agenda_detail['minimal_booking_delay_in_working_days'] = agenda.minimal_booking_delay_in_working_days
......
700 701
    def get_permissions(self):
701 702
        if self.request.method == 'GET':
702 703
            return []
703 704
        return [permissions.IsAuthenticated()]
704 705

  
705 706
    def get(self, request, format=None):
706 707
        agendas_queryset = (
707 708
            Agenda.objects.all()
708
            .select_related('absence_reasons_group')
709
            .select_related('absence_reasons_group', 'category')
709 710
            .prefetch_related('resources', 'absence_reasons_group__absence_reasons')
710 711
            .order_by('label')
711 712
        )
712 713

  
713 714
        if 'q' in request.GET:
714 715
            if not request.GET['q']:
715 716
                return Response({'data': []})
716 717
            agendas_queryset = agendas_queryset.filter(slug__icontains=request.GET['q'])
tests/api/test_all.py
63 63
                'id': 'foo-bar',
64 64
                'slug': 'foo-bar',
65 65
                'kind': 'events',
66 66
                'minimal_booking_delay': 1,
67 67
                'minimal_booking_delay_in_working_days': False,
68 68
                'maximal_booking_delay': 56,
69 69
                'edit_role': 'Edit',
70 70
                'view_role': None,
71
                'category': 'category-a',
71 72
                'absence_reasons': [
72 73
                    {'id': reason.slug, 'slug': reason.slug, 'text': reason.label, 'label': reason.label},
73 74
                    {'id': reason2.slug, 'slug': reason2.slug, 'text': reason2.label, 'label': reason2.label},
74 75
                ],
75 76
                'api': {
76 77
                    'datetimes_url': 'http://testserver/api/agenda/foo-bar/datetimes/',
77 78
                    'fillslots_url': 'http://testserver/api/agenda/foo-bar/fillslots/',
78 79
                },
......
82 83
                'id': 'foo-bar-2',
83 84
                'kind': 'events',
84 85
                'slug': 'foo-bar-2',
85 86
                'minimal_booking_delay': 1,
86 87
                'minimal_booking_delay_in_working_days': False,
87 88
                'maximal_booking_delay': 56,
88 89
                'edit_role': None,
89 90
                'view_role': None,
91
                'category': 'category-a',
90 92
                'api': {
91 93
                    'datetimes_url': 'http://testserver/api/agenda/foo-bar-2/datetimes/',
92 94
                    'fillslots_url': 'http://testserver/api/agenda/foo-bar-2/fillslots/',
93 95
                },
94 96
            },
95 97
            {
96 98
                'text': 'Foo bar 3',
97 99
                'id': 'foo-bar-3',
98 100
                'kind': 'events',
99 101
                'slug': 'foo-bar-3',
100 102
                'minimal_booking_delay': 1,
101 103
                'minimal_booking_delay_in_working_days': False,
102 104
                'maximal_booking_delay': 56,
103 105
                'edit_role': None,
104 106
                'view_role': None,
107
                'category': None,
105 108
                'absence_reasons': [
106 109
                    {'id': reason.slug, 'slug': reason.slug, 'text': reason.label, 'label': reason.label},
107 110
                    {'id': reason2.slug, 'slug': reason2.slug, 'text': reason2.label, 'label': reason2.label},
108 111
                ],
109 112
                'api': {
110 113
                    'datetimes_url': 'http://testserver/api/agenda/foo-bar-3/datetimes/',
111 114
                    'fillslots_url': 'http://testserver/api/agenda/foo-bar-3/fillslots/',
112 115
                },
......
114 117
            {
115 118
                'text': 'Foo bar Meeting',
116 119
                'id': 'foo-bar-meeting',
117 120
                'slug': 'foo-bar-meeting',
118 121
                'minimal_booking_delay': 1,
119 122
                'maximal_booking_delay': 56,
120 123
                'edit_role': None,
121 124
                'view_role': 'View',
125
                'category': 'category-b',
122 126
                'kind': 'meetings',
123 127
                'resources': [
124 128
                    {'id': 'resource-1', 'text': 'Resource 1', 'description': 'Foo bar Resource 1'},
125 129
                    {'id': 'resource-2', 'text': 'Resource 2', 'description': 'Foo bar Resource 2'},
126 130
                ],
127 131
                'api': {
128 132
                    'meetings_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/',
129 133
                    'desks_url': 'http://testserver/api/agenda/foo-bar-meeting/desks/',
......
134 138
            {
135 139
                'text': 'Foo bar Meeting 2',
136 140
                'id': 'foo-bar-meeting-2',
137 141
                'slug': 'foo-bar-meeting-2',
138 142
                'minimal_booking_delay': 1,
139 143
                'maximal_booking_delay': 56,
140 144
                'edit_role': None,
141 145
                'view_role': None,
146
                'category': None,
142 147
                'kind': 'meetings',
143 148
                'resources': [],
144 149
                'api': {
145 150
                    'meetings_url': 'http://testserver/api/agenda/foo-bar-meeting-2/meetings/',
146 151
                    'desks_url': 'http://testserver/api/agenda/foo-bar-meeting-2/desks/',
147 152
                    'resources_url': 'http://testserver/api/agenda/foo-bar-meeting-2/resources/',
148 153
                    'fillslots_url': 'http://testserver/api/agenda/foo-bar-meeting-2/fillslots/',
149 154
                },
......
151 156
            {
152 157
                'text': 'Virtual Agenda',
153 158
                'id': 'virtual-agenda',
154 159
                'slug': 'virtual-agenda',
155 160
                'minimal_booking_delay': 1,
156 161
                'maximal_booking_delay': 56,
157 162
                'edit_role': 'Edit',
158 163
                'view_role': 'View',
164
                'category': None,
159 165
                'kind': 'virtual',
160 166
                'api': {
161 167
                    'meetings_url': 'http://testserver/api/agenda/virtual-agenda/meetings/',
162 168
                    'desks_url': 'http://testserver/api/agenda/virtual-agenda/desks/',
163 169
                    'fillslots_url': 'http://testserver/api/agenda/virtual-agenda/fillslots/',
164 170
                },
165 171
            },
166 172
        ],
......
500 506
        'data': {
501 507
            'text': 'Virtual Agenda',
502 508
            'id': 'virtual-agenda',
503 509
            'slug': 'virtual-agenda',
504 510
            'minimal_booking_delay': None,
505 511
            'maximal_booking_delay': None,
506 512
            'edit_role': None,
507 513
            'view_role': None,
514
            'category': None,
508 515
            'kind': 'virtual',
509 516
            'api': {
510 517
                'meetings_url': 'http://testserver/api/agenda/%s/meetings/' % virtual_meetings_agenda.slug,
511 518
                'desks_url': 'http://testserver/api/agenda/%s/desks/' % virtual_meetings_agenda.slug,
512 519
                'fillslots_url': 'http://testserver/api/agenda/%s/fillslots/' % virtual_meetings_agenda.slug,
513 520
            },
514 521
        },
515 522
    }
516
-