From 0ce7dc2f252906fd6070e60bf80aa974ccd3b3f2 Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Tue, 18 Jun 2013 22:49:01 +0200 Subject: [PATCH] Event API & User Event view --- blechreiz/database.sqlite | Bin 51200 -> 52224 bytes blechreiz/settings.py | 8 + blechreiz/urls.py | 8 + eventplanner/models.py | 7 +- eventplanner/serializers.py | 24 +++ .../templates/eventplanner/event_view.html | 175 ++++++++++++++++++ eventplanner/views.py | 88 ++++++++- website/templates/website/login.html | 1 + website/views.py | 2 - 9 files changed, 309 insertions(+), 4 deletions(-) create mode 100644 eventplanner/serializers.py create mode 100644 eventplanner/templates/eventplanner/event_view.html diff --git a/blechreiz/database.sqlite b/blechreiz/database.sqlite index 038adcff108c8f3bddac68d08a6b103c02914578..2e76fde3bb682d5dff95c0f31ce94952cfd3c96a 100644 GIT binary patch delta 1266 zcmah}U1%It6u$SK*`K?~nv{*W$%37bmb4_hoqO;6u9bAH(!{p0ik5ACsMF14H*T_< zO*YvyP})>qd{8P=Fb_fn@ktQM6#6EXK8X*4PtyA0gCYb$K_XZmyfbUJL=g|enK_*A z-tW8TPx>jI@!Aur>X&oKxLzfYx$Po6? zWq)wGmiIcV3);0zB6j*MqZAbzOjKKpRjm4@_QHbew7kvQT*VdZ%ZC5S^pbz`RQ-PCN}I{NHM$w*SY>NO1Rq;|k

w$(LnMh9F&I>~T|DhdV-OCKt>U5rJ(vnj>^e(=^kbWM&%fNn3Bk;0AmKU%|KX2y#kU97mL9CeC@Q z_2$x&*J!&dEIbL%5ZS@|M#*fm*WvIJN>U2Y2XTbyK!!|7C{<*E2hxO0h0cbNrF39o zs<*DYV@fs@_yI}he}kXp2SUM6|2Hs^P%y@XC~*Z-Odzh%s8lGW-8DN1{)As)7j}Zd z+Yg{Gw1g<3l@RRSc_O)#MtKCULXLb-0Igis54v4BOO%lj3{rR1c}rQO{jjbr;pcYS8+^hkgYjRliGJJ93r}V63Yu$`EQJ z0F-*R)QNQHr~o!cuzH;RT?;LK*G;cIsf4XMX#ZlmhWsgU?v>|N0)=-)pS4-S*n5>Nfs`8Q&Tlc|^2j?Iq%($auk$myAV3nSbv0H_yQn!`+D) Zczo{;a$?*rSVs50v@6rGv-^6`?UiB&ANMPpHPk&pN0&HIW%2yPNF)QXFu3pFM&i8g7{RMQ~X z;>L}oGSGA(C=^$&bOb>}bm?zsH{A&ma8Xh)E_`XA+wSf?=Wx%xhr6-~E9DoXD z(O2Ol-uQ6$mKjv-1Tzy%jWI^4qKTj8<&YnbA@GqCnBy@XN|&N}yQ)%z@X73RJ$2BO zELJJpt28V3E7~&EjRmz}XjL;`Z8!P5^!$ZqZdZ0SkfMb;UCNak`Nh^kv5{++t(M&| ztHq-Bu%2rv2LF~~9%w0I+ zC2l0+V1Oh&*s0`TAn7|0?IGyHo+J7NQ*KGdm=H;lWqHW<5d4FlBaDmCr)}^z%eCrs z_~P{Z(xT{n9`#O*pgMw^FiCcaAZ-%If1JOV!+!J))%mP +{% block feature_slider %} +{% endblock %} + + + +{% block navbar_options %} navbar navbar-inverse navbar-static-top {% endblock %} + + + +{% block content %} + + + {% addtoblock "js" %} + + + {% endaddtoblock %} + + +

+
+
+
+ +

Termine

+ +
+ + + + + + + + + + + + + + + {% for event in events %} + + + + + + + + + + + + {% endfor %} + + +
TerminDatumUhrzeitOrtStatus ändernKommentar
{{ event.title }} {{ event.date }} {{ event.time }} Ort +
+ + + +
+
+
+ +
+
+
+
+ +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/eventplanner/views.py b/eventplanner/views.py index 60f00ef..44220e6 100644 --- a/eventplanner/views.py +++ b/eventplanner/views.py @@ -1 +1,87 @@ -# Create your views here. + +from django.shortcuts import render, get_object_or_404 +from django.http import HttpResponse + +from models import Event, EventParticipation +from musicians.models import Musician + +from serializers import ParticipationSerializer + +import datetime + + +from rest_framework.decorators import api_view +from rest_framework.response import Response +from rest_framework import status + +from django.views.decorators.csrf import csrf_exempt + +# ---------------------------------------- API --------------------------------------------------------- + +@csrf_exempt +@api_view( ['GET'] ) +def event_participation_list( request ): + """ + API for participation + """ + if request.method == 'GET': + event_participations = EventParticipation.objects.filter( event__date__gte = datetime.date.today() ) + serializer = ParticipationSerializer( event_participations, many=True) + return Response( serializer.data ) + + elif request.method == 'POST': + serializer = ParticipationSerializer( data=request.DATA ) + if serializer.is_valid(): + print serializer.data + serializer.save() + return Response( serializer.data, status=status.HTTP_201_CREATED ) + else: + return Response( serializer.errors, status = status.HTTP_400_BAD_REQUEST ) + + +@csrf_exempt +@api_view( ['GET', 'PUT'] ) +def event_participation_detail( request, username, eventId = None ): + try: + participationQs = EventParticipation.objects.filter( musician__user__username = username ) + if eventId: + participationQs = participationQs.filter( event__pk = eventId ) + + except EventParticipation.DoesNotExist: + return HttpResponse( status=404) + + + if request.method == 'GET': + serializer = ParticipationSerializer( participationQs ) + return Response( serializer.data ) + + elif request.method == 'PUT': + serializer = ParticipationSerializer ( participationQs, data = request.DATA, many=True ) + if serializer.is_valid(): + serializer.save() + return Response( serializer.data ) + else: + return Response( status = status.HTTP_400_BAD_REQUEST ) + + + + + + +# ------------------------------------ Normal Views ---------------------------------------------------- + + + + +def events_view( request ): + # All events in the future sorted by date + all_future_events = list ( Event.objects.filter( date__gte = datetime.date.today() ) ) + + + musician = get_object_or_404( Musician, user=request.user ) + + for e in all_future_events: + e.participation = EventParticipation.objects.get( event = e, musician = musician ) + + context = { 'events' : all_future_events } + return render ( request, 'eventplanner/event_view.html', context ) diff --git a/website/templates/website/login.html b/website/templates/website/login.html index bb7e5eb..a656e93 100644 --- a/website/templates/website/login.html +++ b/website/templates/website/login.html @@ -70,6 +70,7 @@ {% endaddtoblock %} +
diff --git a/website/views.py b/website/views.py index 20325da..4526578 100644 --- a/website/views.py +++ b/website/views.py @@ -13,8 +13,6 @@ def home_view(request): return render( request, 'website/mainpage.html' ) - - def logout_view(request): logout( request ) return redirect( login_view )