api: agendas endpoint with filtering (#37436)
This commit is contained in:
parent
65b1286d5e
commit
5636c001ac
|
@ -151,7 +151,12 @@ class Agendas(APIView):
|
|||
permission_classes = ()
|
||||
|
||||
def get(self, request, format=None):
|
||||
agendas = [get_agenda_detail(request, agenda) for agenda in Agenda.objects.all().order_by('label')]
|
||||
agendas_queryset = Agenda.objects.all().order_by('label')
|
||||
if 'q' in request.GET:
|
||||
if not request.GET['q']:
|
||||
return Response({'data': []})
|
||||
agendas_queryset = agendas_queryset.filter(slug__icontains=request.GET['q'])
|
||||
agendas = [get_agenda_detail(request, agenda) for agenda in agendas_queryset]
|
||||
return Response({'data': agendas})
|
||||
|
||||
|
||||
|
|
|
@ -155,6 +155,13 @@ def test_agendas_api(app, some_data, meetings_agenda):
|
|||
]
|
||||
}
|
||||
|
||||
resp = app.get('/api/agenda/', params={'q': 'foo'})
|
||||
assert len(resp.json['data']) == 3
|
||||
resp = app.get('/api/agenda/', params={'q': 'MEET'})
|
||||
assert len(resp.json['data']) == 1
|
||||
resp = app.get('/api/agenda/', params={'q': ''})
|
||||
assert len(resp.json['data']) == 0
|
||||
|
||||
|
||||
def test_agendas_meetingtypes_api(app, some_data, meetings_agenda):
|
||||
resp = app.get('/api/agenda/%s/meetings/' % meetings_agenda.slug)
|
||||
|
|
Loading…
Reference in New Issue