2013-06-02 21:26:10 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from musicians.models import Musician
|
|
|
|
|
|
|
|
|
|
|
|
class Event ( models.Model ):
|
|
|
|
|
|
|
|
EVENT_TYPES = (
|
|
|
|
( 'Reh', _('Rehearsal') ),
|
|
|
|
( 'Conc', _('Concert') ),
|
2013-06-30 16:55:00 +02:00
|
|
|
( 'GenReh', _('General Rehearsal') ),
|
|
|
|
( 'Party', _('Party') ),
|
2013-06-02 21:26:10 +02:00
|
|
|
)
|
|
|
|
|
2013-09-15 12:29:56 +02:00
|
|
|
title = models.CharField( max_length=40, verbose_name = _("titel") )
|
2013-06-30 16:55:00 +02:00
|
|
|
type = models.CharField( max_length=6, choices=EVENT_TYPES, default='Reh', verbose_name= _("type") )
|
|
|
|
location = models.TextField( blank=False, verbose_name=_("location") )
|
|
|
|
desc = models.TextField( blank=True, verbose_name=_("description"))
|
|
|
|
|
2013-06-30 11:01:12 +02:00
|
|
|
date = models.DateField( verbose_name= _("date") )
|
|
|
|
time = models.TimeField( null=True, blank=True, verbose_name = _("time") )
|
2013-06-30 16:55:00 +02:00
|
|
|
meeting_time = models.TimeField( null=True, blank=True, verbose_name = _("meeting_time") )
|
|
|
|
|
2013-06-30 11:01:12 +02:00
|
|
|
participants = models.ManyToManyField( Musician, through='EventParticipation', verbose_name=_("participants") )
|
2013-06-02 21:26:10 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.title + " ( " + self.get_type_display() + " ) "
|
|
|
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
# Call the "real" save() method
|
|
|
|
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 = '' )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EventParticipation( models.Model ):
|
|
|
|
OPTIONS = ( ('?' , _('?' )),
|
|
|
|
('Yes', _('Yes')),
|
|
|
|
('No' , _('No' ))
|
|
|
|
)
|
|
|
|
|
2013-06-30 11:01:12 +02:00
|
|
|
event = models.ForeignKey( Event, verbose_name=_("event") )
|
|
|
|
musician = models.ForeignKey( Musician, verbose_name=_("musician") )
|
|
|
|
status = models.CharField ( max_length=3, choices = OPTIONS, default='?', verbose_name=_("status") )
|
|
|
|
comment = models.CharField ( max_length=64, blank=True, verbose_name=_("comment") )
|
2013-06-02 21:26:10 +02:00
|
|
|
|
2013-06-30 16:55:00 +02:00
|
|
|
|
2013-06-18 22:49:01 +02:00
|
|
|
def get_musician_username(self):
|
|
|
|
return self.musician.user.username
|
2013-06-30 16:55:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_or_create( musician , event ):
|
|
|
|
try:
|
|
|
|
result = EventParticipation.objects.get( event = event, musician = musician )
|
|
|
|
except EventParticipation.DoesNotExist:
|
|
|
|
result = EventParticipation.objects.create( event = event, musician = musician, status='?', comment = '' )
|
2013-06-18 22:49:01 +02:00
|
|
|
|
2013-06-30 16:55:00 +02:00
|
|
|
return result
|
|
|
|
|
2013-06-02 21:26:10 +02:00
|
|
|
class Meta:
|
2013-06-18 22:49:01 +02:00
|
|
|
unique_together = ("event", "musician")
|
2013-06-30 16:55:00 +02:00
|
|
|
permissions = (
|
|
|
|
("change_others_participation", _("Can modify participation status of other users") ),
|
|
|
|
)
|
|
|
|
|
2013-06-18 22:49:01 +02:00
|
|
|
|
|
|
|
|