Enhanced Map control

This commit is contained in:
Martin Bauer
2013-09-26 21:56:32 +02:00
parent 204c8773a2
commit 11135b5592
43 changed files with 574 additions and 563 deletions

View File

@@ -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") ),
)