0001-api-add-single-agenda-infos-api-17188.patch
chrono/api/urls.py | ||
---|---|---|
20 | 20 | |
21 | 21 |
urlpatterns = [ |
22 | 22 |
url(r'agenda/$', views.agendas), |
23 | ||
23 |
url(r'agenda/(?P<agenda_identifier>[\w-]+)/$', views.agenda), |
|
24 | 24 |
url(r'agenda/(?P<agenda_identifier>[\w-]+)/datetimes/$', views.datetimes, name='api-agenda-datetimes'), |
25 | 25 |
url(r'agenda/(?P<agenda_identifier>[\w-]+)/fillslot/(?P<event_pk>[\w:-]+)/$', |
26 | 26 |
views.fillslot, name='api-fillslot'), |
chrono/api/views.py | ||
---|---|---|
61 | 61 |
agendas = Agendas.as_view() |
62 | 62 | |
63 | 63 | |
64 |
class AgendaAPIView(GenericAPIView): |
|
65 |
"""View returning detail of a single agenda |
|
66 |
""" |
|
67 |
permission_classes = () |
|
68 | ||
69 |
def get(self, request, agenda_identifier): |
|
70 |
try: |
|
71 |
agenda = Agenda.objects.get(slug=agenda_identifier) |
|
72 |
except Agenda.DoesNotExist: |
|
73 |
try: |
|
74 |
# legacy access by agenda id |
|
75 |
agenda = Agenda.objects.get(id=int(agenda_identifier)) |
|
76 |
except (ValueError, Agenda.DoesNotExist): |
|
77 |
raise Http404() |
|
78 | ||
79 |
agenda_data = { |
|
80 |
'id': agenda.id, |
|
81 |
'slug': agenda.slug, |
|
82 |
'text': agenda.label, |
|
83 |
'kind': agenda.kind, |
|
84 |
} |
|
85 |
if agenda.kind == 'events': |
|
86 |
agenda_data['api'] = { |
|
87 |
'datetimes_url': request.build_absolute_uri( |
|
88 |
reverse('api-agenda-datetimes', |
|
89 |
kwargs={'agenda_identifier': agenda.slug}))} |
|
90 |
elif agenda.kind == 'meetings': |
|
91 |
agenda_data['api'] = { |
|
92 |
'meetings_url': request.build_absolute_uri( |
|
93 |
reverse('api-agenda-meetings', |
|
94 |
kwargs={'agenda_identifier': agenda.slug}))} |
|
95 | ||
96 |
return Response({'data': agenda_data}) |
|
97 | ||
98 | ||
99 |
agenda = AgendaAPIView.as_view() |
|
100 | ||
101 | ||
64 | 102 |
class Datetimes(GenericAPIView): |
65 | 103 |
permission_classes = () |
66 | 104 |
tests/test_api.py | ||
---|---|---|
588 | 588 |
resp = app.post(resp3.json['api']['accept_url']) |
589 | 589 |
assert event.booked_places == 7 |
590 | 590 |
assert event.waiting_list == 0 |
591 | ||
592 | ||
593 |
def test_agenda_api(app, some_data): |
|
594 |
agenda = Agenda.objects.get(slug='foo-bar') |
|
595 |
resp = app.get('/api/agenda/%s/' % agenda.slug) |
|
596 |
data = resp.json['data'] |
|
597 |
assert data['id'] == 1 |
|
598 |
assert data['slug'] == 'foo-bar' |
|
599 |
assert data['text'] == 'Foo bar' |
|
600 |
assert data['kind'] == 'events' |
|
601 |
assert data['api']['datetimes_url'] == 'http://testserver/api/agenda/foo-bar/datetimes/' |
|
591 |
- |