Eventplanner: Grid / Translation
This commit is contained in:
@@ -13,37 +13,22 @@ import datetime
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from django.forms.models import ModelForm
|
||||
|
||||
|
||||
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 ):
|
||||
def event_participation_detail( request, username = None, eventId = None ):
|
||||
# TODO Permissions!
|
||||
try:
|
||||
participationQs = EventParticipation.objects.filter( musician__user__username = username )
|
||||
participationQs = EventParticipation.objects.filter( event__date__gte = datetime.date.today() )
|
||||
if username:
|
||||
participationQs = EventParticipation.objects.filter( musician__user__username = username )
|
||||
if eventId:
|
||||
participationQs = participationQs.filter( event__pk = eventId )
|
||||
|
||||
@@ -68,12 +53,16 @@ def event_participation_detail( request, username, eventId = None ):
|
||||
|
||||
|
||||
|
||||
|
||||
# ------------------------------------ Normal Views ----------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
def events_view( request ):
|
||||
def eventplanning_view( request ):
|
||||
"""
|
||||
View for a specific user, to edit his events
|
||||
"""
|
||||
# All events in the future sorted by date
|
||||
all_future_events = list ( Event.objects.filter( date__gte = datetime.date.today() ) )
|
||||
|
||||
@@ -84,4 +73,56 @@ def events_view( request ):
|
||||
e.participation = EventParticipation.objects.get( event = e, musician = musician )
|
||||
|
||||
context = { 'events' : all_future_events }
|
||||
return render ( request, 'eventplanner/event_view.html', context )
|
||||
return render ( request, 'eventplanner/eventplanning_view.html', context )
|
||||
|
||||
|
||||
|
||||
|
||||
def events_grid( request ):
|
||||
|
||||
musicians = Musician.objects.all()
|
||||
musicianNames = [ m.user.username for m in musicians ]
|
||||
|
||||
|
||||
all_future_events = list ( Event.objects.filter( date__gte = datetime.date.today() ) )
|
||||
|
||||
for e in all_future_events:
|
||||
e.participation = [ EventParticipation.objects.get( event = e, musician = m ) for m in musicians ]
|
||||
|
||||
# Sort the participations in a dict
|
||||
#for p in participationQs:
|
||||
# username = p.musician.user.username
|
||||
# eventId = p.event.pk
|
||||
# if not eventId in grid:
|
||||
# grid[eventId] = {}
|
||||
#
|
||||
# grid[eventId][username] = p
|
||||
|
||||
|
||||
context = { 'events': all_future_events,
|
||||
'musicianNames' : musicianNames }
|
||||
return render ( request, 'eventplanner/events_grid.html', context )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from django.views.generic.edit import UpdateView
|
||||
|
||||
|
||||
class EventForm( ModelForm ):
|
||||
class Meta:
|
||||
model = Event
|
||||
fields= ['title', 'date','time','type']
|
||||
|
||||
class EventUpdate( UpdateView ):
|
||||
form_class = EventForm
|
||||
model = Event
|
||||
template_name_suffix = "_update_form"
|
||||
success_url = '/events/grid'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user