0001-api-agendas-endpoint-with-filtering-37436.patch
chrono/api/views.py | ||
---|---|---|
151 | 151 |
permission_classes = () |
152 | 152 | |
153 | 153 |
def get(self, request, format=None): |
154 |
agendas = [get_agenda_detail(request, agenda) for agenda in Agenda.objects.all().order_by('label')] |
|
154 |
agendas_queryset = Agenda.objects.all().order_by('label') |
|
155 |
if request.GET.get('q'): |
|
156 |
agendas_queryset = agendas_queryset.filter(slug__icontains=request.GET['q']) |
|
157 |
agendas = [get_agenda_detail(request, agenda) for agenda in agendas_queryset] |
|
155 | 158 |
return Response({'data': agendas}) |
156 | 159 | |
157 | 160 |
tests/test_api.py | ||
---|---|---|
155 | 155 |
] |
156 | 156 |
} |
157 | 157 | |
158 |
resp = app.get('/api/agenda/', params={'q': 'foo'}) |
|
159 |
assert len(resp.json['data']) == 3 |
|
160 |
resp = app.get('/api/agenda/', params={'q': 'MEET'}) |
|
161 |
assert len(resp.json['data']) == 1 |
|
162 |
resp = app.get('/api/agenda/', params={'q': ''}) |
|
163 |
assert len(resp.json['data']) == 3 |
|
164 | ||
158 | 165 | |
159 | 166 |
def test_agendas_meetingtypes_api(app, some_data, meetings_agenda): |
160 | 167 |
resp = app.get('/api/agenda/%s/meetings/' % meetings_agenda.slug) |
161 |
- |