diff --git a/blechreiz/database.sqlite b/blechreiz/database.sqlite index 038adcf..2e76fde 100644 Binary files a/blechreiz/database.sqlite and b/blechreiz/database.sqlite differ diff --git a/blechreiz/settings.py b/blechreiz/settings.py index 85e8960..fb2850a 100644 --- a/blechreiz/settings.py +++ b/blechreiz/settings.py @@ -148,8 +148,16 @@ INSTALLED_APPS = ( 'sekizai', 'intern_area', 'website', + 'rest_framework', ) + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',), + 'PAGINATE_BY': 10 +} + + CRISPY_TEMPLATE_PACK = 'bootstrap' # A sample logging configuration. The only tangible logging diff --git a/blechreiz/urls.py b/blechreiz/urls.py index 868037d..52309cb 100644 --- a/blechreiz/urls.py +++ b/blechreiz/urls.py @@ -9,6 +9,10 @@ import intern_area.views import website.views +import eventplanner.views + + + admin.autodiscover() urlpatterns = patterns('', @@ -28,4 +32,8 @@ urlpatterns = patterns('', url(r'^website/$', website.views.home_view), url(r'^login/$', website.views.login_view), url(r'^logout/$', website.views.logout_view), + url(r'^events/$', eventplanner.views.events_view), + url(r'^eventParticipation/$', eventplanner.views.event_participation_list ), + url(r'^eventParticipation/(\w+)/$', eventplanner.views.event_participation_detail ), + url(r'^eventParticipation/(\w+)/(\d+)$', eventplanner.views.event_participation_detail ), ) \ No newline at end of file diff --git a/eventplanner/models.py b/eventplanner/models.py index abc0d25..4b3ced8 100644 --- a/eventplanner/models.py +++ b/eventplanner/models.py @@ -51,5 +51,10 @@ class EventParticipation( models.Model ): status = models.CharField ( max_length=3, choices = OPTIONS, default='?' ) comment = models.CharField ( max_length=64, blank=True ) + def get_musician_username(self): + return self.musician.user.username + class Meta: - unique_together = ("event", "musician") \ No newline at end of file + unique_together = ("event", "musician") + + \ No newline at end of file diff --git a/eventplanner/serializers.py b/eventplanner/serializers.py new file mode 100644 index 0000000..e0dc106 --- /dev/null +++ b/eventplanner/serializers.py @@ -0,0 +1,24 @@ +from rest_framework import serializers +from models import EventParticipation + + + + +class ParticipationSerializer(serializers.ModelSerializer): + event = serializers.PrimaryKeyRelatedField( many=False, read_only = False ) + musician = serializers.Field( source='get_musician_username' ) +# musician = serializers.PrimaryKeyRelatedField( many=False, read_only = False ) + + def get_identity(self, data): + """ This hook is required for bulk update. """ + try: + return ( data.get('event', None), data.get('musician') ) + except AttributeError: + return None + + class Meta: + model = EventParticipation + fields = ('event', 'musician', 'status', 'comment') + + + diff --git a/eventplanner/templates/eventplanner/event_view.html b/eventplanner/templates/eventplanner/event_view.html new file mode 100644 index 0000000..86897c0 --- /dev/null +++ b/eventplanner/templates/eventplanner/event_view.html @@ -0,0 +1,175 @@ +{% extends "website/base.html" %} + +{% load sekizai_tags staticfiles %} + + + +{% 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 )