Source code for hitchin.conference.models

from django.template import Template, Context, RequestContext
from django.contrib.auth.models import User
from conference.countries  import transl
from misc.tools import send_backup_mail


def changes(self):
    fields = [x.name for x in self._meta._fields()]
[docs] if not self.id: return [(x, getattr(self, x)) for x in fields] old = self.__class__.objects.get(id=self.id) return [ (x, (unicode(getattr(self, x)),unicode(getattr(old, x)))) for x in fields if getattr(self, x) != getattr(old, x)] models.Model.changes = changes
class Hotel(models.Model): name = models.CharField(max_length = 50)
[docs] address = models.TextField(max_length=350, blank=True) url = models.URLField(blank=True) info = models.TextField(max_length=1500, blank=True) num_reservations = models.IntegerField() # google maps coordinates glat1 = models.FloatField(blank=True, null=True) glat2 = models.FloatField(blank=True, null=True) # price price_per_night = models.IntegerField(default=0) price_per_night_dz = models.IntegerField(default=0) price_remarks = models.TextField(blank=True, null=True) def __unicode__(self): return u'%s' % self.name def overbooked(self): if self.num_reservations < self.participant_set.count(): return True
[docs] else: return False class ParticipantManager(models.Manager):
[docs] def active(self): qs = super(ParticipantManager, self).get_query_set()
[docs] return qs.filter(models.Q(accepted=True) & models.Q(cancelled=False)) class Participant(models.Model): user = models.ForeignKey(User, unique=True)
[docs] institution = models.CharField(max_length = 100, blank=True) address = models.TextField(max_length = 350, blank=True) country = models.CharField(max_length=80, blank=True) homepage = models.URLField(blank=True) password = models.CharField(max_length=10) STATUS_CHOICES = ( ('S', 'Speaker'), ('P', 'Participant')) status = models.CharField(max_length=1, choices = STATUS_CHOICES, default='P') NONE, STUDENT, POSTDOC, PROFESSOR = range(4) CAREER_CHOICES = ( (NONE, ''), (STUDENT, 'Student'), (POSTDOC, 'Post-Doc'), (PROFESSOR, 'Professor') ) career = models.PositiveSmallIntegerField(choices = CAREER_CHOICES, default=0) arrival = models.DateField(default=date(2010, 7, 25)) departure = models.DateField(default=date(2010, 7, 31)) hotel_reservation = models.BooleanField() hotel_assigned = models.ForeignKey(Hotel, blank=True, null=True) hotel_final = models.BooleanField(default=False) funding_requested_hotel = models.BooleanField() funding_requested_travel = models.IntegerField(default=0, blank=True, null=True) funding_hotel = models.NullBooleanField(blank=True, null=True) funding_hotel_complete = models.NullBooleanField(blank=True, null=True) funding_travel = models.IntegerField(blank=True, null=True) funding_final = models.BooleanField(default=False) SPONSOR_CHOICES = ( ('-', 'None'), ('E', 'ERC'), ('S', 'SFB'), ('H', 'HUM'), ('O', 'Oth'), ) sponsor = models.CharField(max_length=1, choices = SPONSOR_CHOICES, default='-') in_participant_list = models.BooleanField(default=True) accepted = models.BooleanField(default=False) # moderation of registrations cancelled = models.BooleanField(default=False) time_created = models.DateTimeField(auto_now_add=True) time_lastchanged = models.DateTimeField(auto_now=True) added_by_admin = models.BooleanField(default=False) salutation = models.CharField(max_length=100, blank=True, null=True) def delete(self): self.user.delete()
[docs] models.Model.delete(self) def save(self): # set default values
[docs] if not self.salutation: self.salutation = 'Dear ' + { Participant.NONE: self.get_full_name(), Participant.STUDENT: self.get_full_name(), Participant.POSTDOC: 'Dr. ' + self.user.last_name, Participant.PROFESSOR: 'Prof. ' + self.user.last_name, }[int(self.career)] # remove hotel_final in case of problematic changes ... FIXME is here the right place to do this? super(Participant, self).save() def __unicode__(self): return u"%s %s (%s) (%s to %s)" % (self.user.first_name, self.user.last_name, self.status, self.arrival, self.departure)
def get_full_name(self): return u"%s %s" % (self.user.first_name, self.user.last_name,)
[docs] get_full_name.short_description = 'Name'
def get_duration_of_stay(self): return u"%s to %s" % (self.arrival, self.departure)
[docs] get_duration_of_stay.short_description = 'Duration of stay'
def support_granted_as_requested(self): if not self.funding_final: return True
[docs] if self.funding_requested_hotel and not self.funding_hotel: return False sft = self.funding_travel or 0 if self.funding_requested_travel > sft: return False return True def double(self): hf_double = HotelFeature.objects.get(tag__exact='double')
[docs] return HotelFeaturePart.objects.filter(participant=self, feature__exact=hf_double).count() > 0 def late(self): hf_late = HotelFeature.objects.get(tag__exact='late')
[docs] return ', '.join([ hfp.notes for hfp in HotelFeaturePart.objects.filter(participant=self, feature__exact=hf_late)]) def special(self): hf_special = HotelFeature.objects.get(tag__exact='special')
[docs] return ', '.join([ hfp.notes for hfp in HotelFeaturePart.objects.filter(participant=self, feature__exact=hf_special)]) def dinner(self): sp_dinner = SocialEvent.objects.get(tag__exact='dinner')
[docs] try: dinner_p = SocialEventPart.objects.get(participant=self, event=sp_dinner) except: return 0 return dinner_p.num_persons def zechezollv(self): sp_zechezollv = SocialEvent.objects.get(tag__exact='zechezollv')
[docs] try: zechezollv_p = SocialEventPart.objects.get(participant=self, event=sp_zechezollv) except: return 0 return zechezollv_p.num_persons def talk_title_given(self): if self.status != 'S': return
[docs] from speaker.models import Speaker, Talk sp = Speaker.objects.get(participant=self) t = Talk.objects.get(speaker=sp) if t.title: return True return False def isspeaker(self): return self.status == 'S'
[docs] def tex_address(self): if not self.address: return ''
[docs] st = '' if self.status == '3': st = 'Prof. ' elif self.status == '2': st = 'Dr. ' return unicode(u'\\\\\n'.join([ st + self.user.get_full_name() ] + self.address.split('\n') + [ transl(self.country) ])) def funding_requested(self): return self.funding_requested_hotel or self.funding_requested_travel
[docs] def arrival_le_14(self): return self.arrival <= date(2010, 7, 24)
[docs] def select(self): return '<input type="checkbox" name="participant" value="%s"/>' % self.id
[docs] select.allow_tags = True select.short_description = ''
def get_participantorgcomments_available(self): from messages.models import ParticipantOrgComment
[docs] pocs = ParticipantOrgComment.objects.active() for poc in pocs: if poc.relevant_for(self): return True return False def get_participantorgcomments(self): from messages.models import ParticipantOrgComment
[docs] result = [] pocs = ParticipantOrgComment.objects.active() for poc in pocs: if poc.relevant_for(self): result.append({ 'title': poc.title, 'text': Template(poc.template).render(Context({ 'p': self })) }) return result def get_participantorgcomments_admin(self): from messages.models import ParticipantOrgComment
[docs] result = [] pocs = ParticipantOrgComment.objects.filter(date__lte=date.today) for poc in pocs: if poc.relevant_for(self): result.append({ 'title': poc.title, 'text': Template(poc.template).render(Context({ 'p': self })), 'active': poc.active }) return result objects = ParticipantManager()
class ChangeRequestHotel(models.Model):
[docs] participant = models.ForeignKey(Participant) author = models.ForeignKey(User) date = models.DateTimeField(auto_now_add=True) arrival = models.DateField() departure = models.DateField() seen = models.BooleanField(default=False) settled = models.BooleanField(default=False) final_comment = models.TextField(blank=True, null=True) class Meta: ordering = ['-date'] class HotelFeature(models.Model): tag = models.CharField(max_length=10)
[docs] description = models.CharField(max_length=200) participants = models.ManyToManyField(Participant, through="HotelFeaturePart") help_text = models.CharField(max_length=400, blank=True, default='') # if != '', a "notes" field is displayed in the EditForm, where the participant can add a remark about this specific feature (i.e. expected late arrival time) # In that case, help_text is displayed as a help text. def __unicode__(self): return self.tag class HotelFeaturePart(models.Model): participant = models.ForeignKey(Participant)
[docs] feature = models.ForeignKey(HotelFeature) notes = models.TextField(blank=True, null=True, default='') class HotelFeatureCR(models.Model): crequ = models.ForeignKey(ChangeRequestHotel)
[docs] feature = models.ForeignKey(HotelFeature) notes = models.TextField(blank=True, null=True) class SocialEvent(models.Model): tag = models.CharField(max_length=10)
[docs] title = models.CharField(max_length=200) description = models.TextField(blank=True, null=True) # mark-up(?), w/ referral to image(s) date = models.DateTimeField() # date of event participants = models.ManyToManyField(Participant, through="SocialEventPart") def __unicode__(self): return self.title + ', ' + unicode(self.date) class SocialEventPart(models.Model): event = models.ForeignKey(SocialEvent)
[docs] participant = models.ForeignKey(Participant) num_persons = models.IntegerField(default=1)