api: get meeting by slug (#43526)
This commit is contained in:
parent
2969c00506
commit
49bca6ecc3
|
@ -44,6 +44,11 @@ urlpatterns = [
|
|||
name='api-agenda-meeting-datetimes-legacy',
|
||||
),
|
||||
url(r'^agenda/(?P<agenda_identifier>[\w-]+)/meetings/$', views.meeting_list, name='api-agenda-meetings'),
|
||||
url(
|
||||
r'^agenda/(?P<agenda_identifier>[\w-]+)/meetings/(?P<meeting_identifier>[\w-]+)/$',
|
||||
views.meeting_info,
|
||||
name='api-agenda-meetings',
|
||||
),
|
||||
url(r'^agenda/(?P<agenda_identifier>[\w-]+)/desks/$', views.agenda_desk_list, name='api-agenda-desks'),
|
||||
url(
|
||||
r'^agenda/(?P<agenda_identifier>[\w-]+)/meetings/(?P<meeting_identifier>[\w-]+)/datetimes/$',
|
||||
|
|
|
@ -571,6 +571,45 @@ class MeetingList(APIView):
|
|||
meeting_list = MeetingList.as_view()
|
||||
|
||||
|
||||
class MeetingInfo(APIView):
|
||||
permission_classes = ()
|
||||
|
||||
def get(self, request, agenda_identifier=None, meeting_identifier=None, format=None):
|
||||
try:
|
||||
agenda = Agenda.objects.get(slug=agenda_identifier)
|
||||
except Agenda.DoesNotExist:
|
||||
raise Http404()
|
||||
if not agenda.accept_meetings():
|
||||
raise Http404('agenda found, but it does not accept meetings')
|
||||
|
||||
try:
|
||||
meeting_type = agenda.get_meetingtype(slug=meeting_identifier)
|
||||
except MeetingType.DoesNotExist:
|
||||
raise Http404()
|
||||
|
||||
datetimes_url = request.build_absolute_uri(
|
||||
reverse(
|
||||
'api-agenda-meeting-datetimes',
|
||||
kwargs={'agenda_identifier': agenda.slug, 'meeting_identifier': meeting_type.slug},
|
||||
)
|
||||
)
|
||||
return Response(
|
||||
{
|
||||
'data': {
|
||||
'text': meeting_type.label,
|
||||
'id': meeting_type.slug,
|
||||
'duration': meeting_type.duration,
|
||||
'api': {'datetimes_url': datetimes_url},
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return Response({'data': meeting_types})
|
||||
|
||||
|
||||
meeting_info = MeetingInfo.as_view()
|
||||
|
||||
|
||||
class AgendaDeskList(APIView):
|
||||
permission_classes = ()
|
||||
|
||||
|
|
|
@ -258,6 +258,28 @@ def test_agendas_meetingtypes_api(app, some_data, meetings_agenda):
|
|||
resp = app.get('/api/agenda/xxxx/meetings/', status=404)
|
||||
|
||||
|
||||
def test_agendas_meetingtype_api(app, some_data, meetings_agenda):
|
||||
resp = app.get('/api/agenda/%s/meetings/blah/' % meetings_agenda.slug)
|
||||
assert resp.json == {
|
||||
'data': {
|
||||
'text': 'Blah',
|
||||
'id': 'blah',
|
||||
'duration': 30,
|
||||
'api': {
|
||||
'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah/datetimes/',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
# wrong kind
|
||||
agenda1 = Agenda.objects.filter(label=u'Foo bar')[0]
|
||||
resp = app.get('/api/agenda/%s/meetings/' % agenda1.slug, status=404)
|
||||
|
||||
# unknown
|
||||
resp = app.get('/api/agenda/xxxx/meetings/', status=404)
|
||||
resp = app.get('/api/agenda/%s/meetings/xxxx/' % agenda1.slug, status=404)
|
||||
|
||||
|
||||
def test_agendas_desks_api(app, some_data, meetings_agenda):
|
||||
resp = app.get('/api/agenda/%s/desks/' % meetings_agenda.slug)
|
||||
assert resp.json == {'data': [{'text': 'Desk 1', 'id': 'desk-1',}]}
|
||||
|
|
Loading…
Reference in New Issue