Enhanced Map control
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import HttpResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.forms.models import ModelForm
|
||||
from django.forms import TextInput
|
||||
|
||||
from models import Event, EventParticipation
|
||||
from musicians.models import Musician
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
from serializers import ParticipationSerializer
|
||||
|
||||
@@ -29,14 +30,13 @@ def event_api( request, username = None, eventId = None ):
|
||||
try:
|
||||
participationQs = EventParticipation.objects.filter( event__date__gte = datetime.date.today() )
|
||||
if username:
|
||||
participationQs = EventParticipation.objects.filter( musician__user__username = username )
|
||||
participationQs = EventParticipation.objects.filter( 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 )
|
||||
@@ -45,7 +45,7 @@ def event_api( request, username = None, eventId = None ):
|
||||
serializer = ParticipationSerializer ( participationQs, data = request.DATA, many=True )
|
||||
if serializer.is_valid():
|
||||
for serializedObject in serializer.object:
|
||||
if serializedObject.musician.user != request.user:
|
||||
if serializedObject.user != request.user:
|
||||
if not request.user.has_perm('change_others_participation') :
|
||||
return Response( status = status.HTTP_403_FORBIDDEN )
|
||||
|
||||
@@ -73,10 +73,8 @@ def eventplanning( 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.get_or_create( event = e, musician = musician )
|
||||
e.participation = EventParticipation.get_or_create( event = e, user = request.user )
|
||||
|
||||
context = { 'events' : all_future_events }
|
||||
return render ( request, 'eventplanner/eventplanning_view.html', context )
|
||||
@@ -86,17 +84,16 @@ def eventplanning( request ):
|
||||
@login_required
|
||||
def events_grid( request ):
|
||||
|
||||
musicians = Musician.objects.all()
|
||||
musicianNames = [ m.user.username for m in musicians ]
|
||||
|
||||
usernames = [ u.username for u in User.objects.all() ]
|
||||
|
||||
all_future_events = list ( Event.objects.filter( date__gte = datetime.date.today() ) )
|
||||
|
||||
for e in all_future_events:
|
||||
e.participation = [ EventParticipation.get_or_create( event = e, musician = m ) for m in musicians ]
|
||||
e.participation = [ EventParticipation.get_or_create( event = e, user = u ) for u in User.objects.all() ]
|
||||
|
||||
context = { 'events': all_future_events,
|
||||
'usernames' : usernames }
|
||||
|
||||
context = { 'events': all_future_events,
|
||||
'musicianNames' : musicianNames }
|
||||
return render ( request, 'eventplanner/events_grid.html', context )
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user