api: add datetimes API endpoint to agendas API

This commit is contained in:
Frédéric Péters 2016-06-20 09:34:53 +02:00
parent 6463c0cafb
commit 54b7142f54
3 changed files with 11 additions and 3 deletions

View File

@ -20,7 +20,7 @@ from . import views
urlpatterns = patterns('',
url(r'agenda/$', views.agendas),
url(r'agenda/(?P<pk>\w+)/datetimes/$', views.datetimes),
url(r'agenda/(?P<pk>\w+)/datetimes/$', views.datetimes, name='api-agenda-datetimes'),
url(r'agenda/(?P<agenda_pk>\w+)/fillslot/(?P<event_pk>\w+)/$', views.fillslot),
url(r'agenda/(?P<agenda_pk>\w+)/status/(?P<event_pk>\w+)/$', views.slot_status),
url(r'booking/(?P<booking_pk>\w+)/$', views.booking),

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.core.urlresolvers import reverse
from django.db.models import F
from django.utils.timezone import localtime, now
@ -30,6 +31,10 @@ class Agendas(GenericAPIView):
response = {'data': [{
'id': x.id,
'slug': x.slug,
'api': {
'datetimes': request.build_absolute_uri(
reverse('api-agenda-datetimes', kwargs={'pk': x.id})),
},
'text': x.label}
for x in Agenda.objects.all().order_by('label')]}
return Response(response)

View File

@ -51,8 +51,11 @@ def test_agendas_api(app, some_data):
agenda2_id = Agenda.objects.filter(label=u'Foo bar2')[0].id
resp = app.get('/api/agenda/')
assert resp.json == {'data': [
{'text': 'Foo bar', 'id': agenda_id, 'slug': u'foo-bar'},
{'text': 'Foo bar2', 'id': agenda2_id, 'slug': u'foo-bar2'}]}
{'text': 'Foo bar', 'id': agenda_id, 'slug': u'foo-bar',
'api': {'datetimes': 'http://localhost:80/api/agenda/%s/datetimes/' % agenda_id}},
{'text': 'Foo bar2', 'id': agenda2_id, 'slug': u'foo-bar2',
'api': {'datetimes': 'http://localhost:80/api/agenda/%s/datetimes/' % agenda2_id}}
]}
def test_datetimes_api(app, some_data):
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id