2017-01-20 15:18:10 +00:00
|
|
|
from django.contrib.postgres.fields import DateTimeRangeField
|
2016-07-13 17:13:47 +00:00
|
|
|
from django.db import models
|
2016-08-07 13:49:30 +00:00
|
|
|
from django.utils.text import slugify
|
2017-01-22 11:59:57 +00:00
|
|
|
from django.conf import settings
|
2016-07-13 17:13:47 +00:00
|
|
|
from utils.models import CreatedUpdatedModel
|
2017-01-22 11:59:57 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from datetime import timedelta
|
2016-07-13 17:13:47 +00:00
|
|
|
|
|
|
|
|
2017-02-08 22:34:24 +00:00
|
|
|
class EventLocation(CreatedUpdatedModel):
|
|
|
|
""" The places where stuff happens """
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
slug = models.SlugField()
|
|
|
|
icon = models.CharField(max_length=100)
|
|
|
|
camp = models.ForeignKey('camps.Camp', null=True, related_name="eventlocations")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = (('camp', 'slug'), ('camp', 'name'))
|
|
|
|
|
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
class EventType(CreatedUpdatedModel):
|
2016-07-13 19:44:09 +00:00
|
|
|
""" Every event needs to have a type. """
|
2017-01-28 17:43:55 +00:00
|
|
|
name = models.CharField(max_length=100, unique=True)
|
2016-07-13 17:13:47 +00:00
|
|
|
slug = models.SlugField()
|
2016-08-04 21:03:39 +00:00
|
|
|
color = models.CharField(max_length=50)
|
|
|
|
light_text = models.BooleanField(default=False)
|
2017-02-02 13:37:17 +00:00
|
|
|
notifications = models.BooleanField(default=False)
|
2016-07-13 17:13:47 +00:00
|
|
|
|
2017-01-31 22:39:49 +00:00
|
|
|
def __str__(self):
|
2016-07-13 20:37:20 +00:00
|
|
|
return self.name
|
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
|
|
|
|
class Event(CreatedUpdatedModel):
|
2017-01-20 15:18:10 +00:00
|
|
|
""" Something that is on the program one or more times. """
|
2016-07-13 17:13:47 +00:00
|
|
|
title = models.CharField(max_length=255)
|
2016-08-07 13:49:30 +00:00
|
|
|
slug = models.SlugField(blank=True, max_length=255)
|
|
|
|
abstract = models.TextField()
|
2016-07-13 19:44:09 +00:00
|
|
|
event_type = models.ForeignKey(EventType)
|
2017-01-22 11:59:57 +00:00
|
|
|
camp = models.ForeignKey('camps.Camp', null=True, related_name="events")
|
2016-08-08 17:36:13 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['title']
|
2017-01-28 17:43:55 +00:00
|
|
|
unique_together = (('camp', 'slug'), ('camp', 'title'))
|
2016-07-13 19:44:09 +00:00
|
|
|
|
2017-01-31 22:39:49 +00:00
|
|
|
def __str__(self):
|
2017-01-22 11:59:57 +00:00
|
|
|
return '%s (%s)' % (self.title, self.camp.title)
|
2016-07-13 20:37:20 +00:00
|
|
|
|
2016-08-07 13:49:30 +00:00
|
|
|
def save(self, **kwargs):
|
|
|
|
if not self.slug:
|
2016-08-08 19:56:54 +00:00
|
|
|
self.slug = slugify(self.title)
|
2016-08-07 13:49:30 +00:00
|
|
|
super(Event, self).save(**kwargs)
|
|
|
|
|
2017-01-24 23:24:04 +00:00
|
|
|
@property
|
|
|
|
def speakers_list(self):
|
|
|
|
if self.speakers.exists():
|
|
|
|
return ", ".join(self.speakers.all().values_list('name', flat=True))
|
|
|
|
return False
|
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
class EventInstance(CreatedUpdatedModel):
|
|
|
|
""" An instance of an event """
|
|
|
|
event = models.ForeignKey('program.event', related_name='instances')
|
2017-01-20 15:18:10 +00:00
|
|
|
when = DateTimeRangeField()
|
2017-02-02 13:37:17 +00:00
|
|
|
notifications_sent = models.BooleanField(default=False)
|
2017-02-08 22:34:24 +00:00
|
|
|
location = models.ForeignKey('program.EventLocation', related_name='eventinstances')
|
2016-12-25 14:52:55 +00:00
|
|
|
|
|
|
|
class Meta:
|
2017-01-20 15:18:10 +00:00
|
|
|
ordering = ['when']
|
2016-12-25 14:52:55 +00:00
|
|
|
|
2017-01-31 22:39:49 +00:00
|
|
|
def __str__(self):
|
2017-01-20 15:18:10 +00:00
|
|
|
return '%s (%s)' % (self.event, self.when)
|
2016-12-25 14:52:55 +00:00
|
|
|
|
2017-01-22 11:59:57 +00:00
|
|
|
def __clean__(self):
|
|
|
|
errors = []
|
2017-02-08 22:34:24 +00:00
|
|
|
if self.location.camp != self.event.camp:
|
|
|
|
errors.append(ValidationError({'location', "Error: This location belongs to a different camp"}))
|
2017-01-22 11:59:57 +00:00
|
|
|
|
|
|
|
if errors:
|
2017-02-08 22:34:24 +00:00
|
|
|
raise ValidationError(errors)
|
2017-01-22 11:59:57 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def schedule_date(self):
|
|
|
|
"""
|
|
|
|
Returns the schedule date of this eventinstance. Schedule date is determined by substracting
|
|
|
|
settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS from the eventinstance start time. This means that if
|
|
|
|
an event is scheduled for 00:30 wednesday evening (technically thursday) then the date
|
2017-02-08 22:34:24 +00:00
|
|
|
after substracting 5 hours would be wednesdays date, not thursdays
|
|
|
|
(given settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS=5)
|
2017-01-22 11:59:57 +00:00
|
|
|
"""
|
|
|
|
return (self.when.lower-timedelta(hours=settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS)).date()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def timeslots(self):
|
|
|
|
"""
|
|
|
|
Find the number of timeslots this eventinstance takes up
|
|
|
|
"""
|
|
|
|
seconds = (self.when.upper-self.when.lower).seconds
|
|
|
|
minutes = seconds / 60
|
|
|
|
return minutes / settings.SCHEDULE_TIMESLOT_LENGTH_MINUTES
|
|
|
|
|
2016-12-25 14:52:55 +00:00
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
class Speaker(CreatedUpdatedModel):
|
2017-01-20 15:18:10 +00:00
|
|
|
""" A Person anchoring an event. """
|
2016-07-13 17:13:47 +00:00
|
|
|
name = models.CharField(max_length=150)
|
|
|
|
biography = models.TextField()
|
2017-02-18 11:30:26 +00:00
|
|
|
picture_small = models.ImageField(null=True, blank=True)
|
|
|
|
picture_large = models.ImageField(null=True, blank=True)
|
2016-08-08 17:36:13 +00:00
|
|
|
slug = models.SlugField(blank=True, max_length=255)
|
2017-01-23 17:57:30 +00:00
|
|
|
camp = models.ForeignKey('camps.Camp', null=True, related_name="speakers")
|
2016-07-13 17:13:47 +00:00
|
|
|
events = models.ManyToManyField(
|
|
|
|
Event,
|
2016-08-04 21:03:39 +00:00
|
|
|
blank=True,
|
2016-07-13 19:44:09 +00:00
|
|
|
)
|
2016-07-13 20:37:20 +00:00
|
|
|
|
2016-08-08 17:36:13 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
2017-01-28 17:43:55 +00:00
|
|
|
unique_together = (('camp', 'name'), ('camp', 'slug'))
|
2016-08-08 17:36:13 +00:00
|
|
|
|
2017-02-18 11:30:26 +00:00
|
|
|
def __str__(self):
|
2017-01-23 22:58:41 +00:00
|
|
|
return '%s (%s)' % (self.name, self.camp)
|
2016-08-08 17:36:13 +00:00
|
|
|
|
|
|
|
def save(self, **kwargs):
|
|
|
|
if not self.slug:
|
2016-08-08 19:56:54 +00:00
|
|
|
self.slug = slugify(self.name)
|
2016-08-08 18:15:04 +00:00
|
|
|
super(Speaker, self).save(**kwargs)
|
2016-08-08 17:36:13 +00:00
|
|
|
|