Enhanced Map control
This commit is contained in:
@@ -5,13 +5,13 @@ from eventplanner.models import Event, EventParticipation
|
||||
class EventParticipationInline(admin.TabularInline):
|
||||
model = EventParticipation
|
||||
extra = 1
|
||||
readonly_fields = ('musician',)
|
||||
fields = ( 'musician', 'status', 'comment', )
|
||||
readonly_fields = ('user',)
|
||||
fields = ( 'user', 'status', 'comment', )
|
||||
has_add_permission = lambda self, req : False
|
||||
has_delete_permission = lambda self, req, obj : False
|
||||
|
||||
template = "custom_tabular.html"
|
||||
|
||||
|
||||
|
||||
class EventAdmin(admin.ModelAdmin):
|
||||
inlines = ( EventParticipationInline, )
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
from musicians.models import Musician
|
||||
|
||||
from datetime import datetime
|
||||
from location_field.models import PlainLocationField
|
||||
@@ -26,9 +27,7 @@ class Event ( models.Model ):
|
||||
time = models.TimeField( null=True, blank=True, verbose_name = _("time") )
|
||||
meeting_time = models.TimeField( null=True, blank=True, verbose_name = _("meeting_time") )
|
||||
|
||||
|
||||
|
||||
participants = models.ManyToManyField( Musician, through='EventParticipation', verbose_name=_("participants") )
|
||||
participants = models.ManyToManyField( User, through='EventParticipation', verbose_name=_("participants") )
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title + " ( " + self.get_type_display() + " ) "
|
||||
@@ -39,9 +38,9 @@ class Event ( models.Model ):
|
||||
super(Event, self).save(*args, **kwargs)
|
||||
|
||||
# Create a "Don't Know" participation for each Musician
|
||||
for m in Musician.objects.all():
|
||||
if not m in self.participants.all():
|
||||
EventParticipation.objects.create( event=self, musician = m, status='?', comment = '' )
|
||||
for u in User.objects.all():
|
||||
if not u in self.participants.all():
|
||||
EventParticipation.objects.create( event=self, user = u, status='?', comment = '' )
|
||||
|
||||
@property
|
||||
def displaytime(self):
|
||||
@@ -60,19 +59,18 @@ class EventParticipation( models.Model ):
|
||||
)
|
||||
|
||||
event = models.ForeignKey( Event, verbose_name=_("event") )
|
||||
musician = models.ForeignKey( Musician, verbose_name=_("musician") )
|
||||
user = models.ForeignKey( User, verbose_name=_("user") )
|
||||
status = models.CharField ( max_length=3, choices = OPTIONS, default='?', verbose_name=_("status") )
|
||||
comment = models.CharField ( max_length=64, blank=True, verbose_name=_("comment") )
|
||||
|
||||
|
||||
def get_musician_username(self):
|
||||
return self.musician.user.username
|
||||
def get_username(self):
|
||||
return self.user.username
|
||||
|
||||
@staticmethod
|
||||
def hasUserSetParticipationForAllEvents( user ):
|
||||
futurePart = EventParticipation.objects.filter( event__date__gte = datetime.now() )
|
||||
maybeObjects = futurePart.filter( musician__user = user ).filter( status = '?' )
|
||||
|
||||
|
||||
maybeObjects = futurePart.filter( user = user ).filter( status = '?' )
|
||||
if len( maybeObjects ) > 0:
|
||||
return False
|
||||
else:
|
||||
@@ -80,16 +78,16 @@ class EventParticipation( models.Model ):
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_or_create( musician , event ):
|
||||
def get_or_create( user , event ):
|
||||
try:
|
||||
result = EventParticipation.objects.get( event = event, musician = musician )
|
||||
result = EventParticipation.objects.get( event = event, user = user )
|
||||
except EventParticipation.DoesNotExist:
|
||||
result = EventParticipation.objects.create( event = event, musician = musician, status='?', comment = '' )
|
||||
result = EventParticipation.objects.create( event = event, user = user, status='?', comment = '' )
|
||||
|
||||
return result
|
||||
|
||||
class Meta:
|
||||
unique_together = ("event", "musician")
|
||||
unique_together = ("event", "user")
|
||||
permissions = (
|
||||
("change_others_participation", _("Can modify participation status of other users") ),
|
||||
)
|
||||
|
||||
@@ -5,20 +5,19 @@ 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 )
|
||||
event = serializers.PrimaryKeyRelatedField( many=False, read_only = False )
|
||||
user = serializers.Field( source='get_username' )
|
||||
|
||||
def get_identity(self, data):
|
||||
""" This hook is required for bulk update. """
|
||||
try:
|
||||
return ( data.get('event', None), data.get('musician') )
|
||||
return ( data.get('event', None), data.get('user') )
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
class Meta:
|
||||
model = EventParticipation
|
||||
fields = ('event', 'musician', 'status', 'comment')
|
||||
fields = ('event', 'user', 'status', 'comment')
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
function putStatus( button, status ) {
|
||||
p = button.parent();
|
||||
putObject = [ { "event": p.data("event-id"),
|
||||
"musician": p.data("username"),
|
||||
"user": p.data("username"),
|
||||
"status": status } ];
|
||||
|
||||
request = $.ajax( {
|
||||
@@ -66,7 +66,7 @@
|
||||
|
||||
|
||||
putObject = [ { "event": $(this).data("event-id"),
|
||||
"musician": $(this).data("username"),
|
||||
"user": $(this).data("username"),
|
||||
"comment": $(this).val() } ];
|
||||
|
||||
$.ajax( {
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
|
||||
dataObject = {
|
||||
"event" : $(this).data("event"),
|
||||
"musician": $(this).data("musician"),
|
||||
"user" : $(this).data("username"),
|
||||
"status" : $(this).children("button").data("status")
|
||||
};
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
<tr>
|
||||
<th> Termin </th>
|
||||
<th> Datum </th>
|
||||
{% for name in musicianNames %}
|
||||
{% for name in usernames %}
|
||||
<th> {{ name|capfirst }} </th>
|
||||
{% endfor %}
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
|
||||
|
||||
{% for p in event.participation %}
|
||||
<td class="center userEventTableData" data-musician="{{p.musician.user.username}}" data-event="{{event.pk}}">
|
||||
<td class="center userEventTableData" data-username="{{p.user.username}}" data-event="{{event.pk}}">
|
||||
{% if p.status == "Yes" %}
|
||||
<button class="btn btn-mini btn-success eventButton" title="{{p.comment}}" data-status="{{p.status}}">
|
||||
{% if p.comment %} <i class="icon-comment icon-white"></i> {% endif %}
|
||||
|
||||
@@ -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