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
|
2017-02-23 20:51:36 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-03-07 20:44:30 +00:00
|
|
|
from utils.models import CreatedUpdatedModel, CampRelatedModel
|
2017-01-22 11:59:57 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from datetime import timedelta
|
2017-03-07 23:00:17 +00:00
|
|
|
from django.core.urlresolvers import reverse_lazy
|
2017-03-12 14:43:41 +00:00
|
|
|
import uuid
|
2017-03-07 23:00:17 +00:00
|
|
|
|
|
|
|
|
2017-03-07 23:07:12 +00:00
|
|
|
class UserSubmittedModel(CampRelatedModel):
|
2017-03-12 14:43:41 +00:00
|
|
|
"""
|
|
|
|
An abstract model containing the stuff that is shared
|
|
|
|
between the SpeakerSubmission and EventSubmission models.
|
|
|
|
"""
|
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
uuid = models.UUIDField(
|
|
|
|
primary_key=True,
|
|
|
|
default=uuid.uuid4,
|
|
|
|
editable=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
user = models.ForeignKey(
|
|
|
|
'auth.User',
|
|
|
|
)
|
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
SUBMISSION_DRAFT = 'draft'
|
|
|
|
SUBMISSION_PENDING = 'pending'
|
|
|
|
SUBMISSION_APPROVED = 'approved'
|
|
|
|
SUBMISSION_REJECTED = 'rejected'
|
|
|
|
|
|
|
|
SUBMISSION_STATUSES = [
|
|
|
|
SUBMISSION_DRAFT,
|
|
|
|
SUBMISSION_PENDING,
|
|
|
|
SUBMISSION_APPROVED,
|
|
|
|
SUBMISSION_REJECTED
|
|
|
|
]
|
|
|
|
|
|
|
|
SUBMISSION_STATUS_CHOICES = [
|
|
|
|
(SUBMISSION_DRAFT, 'Draft'),
|
|
|
|
(SUBMISSION_PENDING, 'Pending approval'),
|
|
|
|
(SUBMISSION_APPROVED, 'Approved'),
|
|
|
|
(SUBMISSION_REJECTED, 'Rejected'),
|
|
|
|
]
|
|
|
|
|
|
|
|
submission_status = models.CharField(
|
|
|
|
max_length=50,
|
|
|
|
choices=SUBMISSION_STATUS_CHOICES,
|
|
|
|
default=SUBMISSION_DRAFT,
|
|
|
|
)
|
2016-07-13 17:13:47 +00:00
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
def __str__(self):
|
|
|
|
return '%s (submitted by: %s, status: %s)' % (self.headline, self.user, self.submission_status)
|
|
|
|
|
|
|
|
|
|
|
|
def get_speakersubmission_picture_upload_path(instance, filename):
|
|
|
|
""" We want speakersubmission pictures saved as MEDIA_ROOT/public/speakersubmissions/camp-slug/submission-uuid/filename """
|
|
|
|
return 'public/speakersubmissions/%(campslug)s/%(submissionuuid)s/%(filename)s' % {
|
|
|
|
'campslug': instance.camp.slug,
|
|
|
|
'submissionuuidd': instance.uuid,
|
|
|
|
'filename': filename
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SpeakerSubmission(UserSubmittedModel):
|
|
|
|
""" A speaker submission """
|
|
|
|
|
|
|
|
camp = models.ForeignKey(
|
|
|
|
'camps.Camp',
|
|
|
|
related_name='speakersubmissions'
|
|
|
|
)
|
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
max_length=150,
|
|
|
|
help_text='Name or alias of the speaker',
|
|
|
|
)
|
|
|
|
|
|
|
|
biography = models.TextField(
|
|
|
|
help_text='Markdown is supported.'
|
|
|
|
)
|
|
|
|
|
|
|
|
picture_large = models.ImageField(
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
upload_to=get_speakersubmission_picture_upload_path,
|
|
|
|
help_text='A picture of the speaker'
|
|
|
|
)
|
|
|
|
|
|
|
|
picture_small = models.ImageField(
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
upload_to=get_speakersubmission_picture_upload_path,
|
|
|
|
help_text='A thumbnail of the speaker picture'
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def headline(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy('speakersubmission_detail', kwargs={'camp_slug': self.camp.slug, 'pk': self.uuid})
|
|
|
|
|
|
|
|
|
|
|
|
class EventSubmission(UserSubmittedModel):
|
|
|
|
""" An event submission """
|
|
|
|
|
|
|
|
camp = models.ForeignKey(
|
|
|
|
'camps.Camp',
|
|
|
|
related_name='eventsubmissions'
|
|
|
|
)
|
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
help_text='The title of this event',
|
|
|
|
)
|
|
|
|
|
|
|
|
abstract = models.TextField(
|
|
|
|
help_text='The abstract for this event'
|
|
|
|
)
|
|
|
|
|
|
|
|
event_type = models.ForeignKey(
|
|
|
|
'program.EventType',
|
|
|
|
help_text='The type of event',
|
|
|
|
)
|
|
|
|
|
|
|
|
speakers = models.ManyToManyField(
|
|
|
|
'program.SpeakerSubmission',
|
|
|
|
blank=True,
|
|
|
|
help_text='Pick the speaker(s) for this event',
|
|
|
|
)
|
|
|
|
|
2017-03-09 23:45:50 +00:00
|
|
|
@property
|
2017-03-12 14:43:41 +00:00
|
|
|
def headline(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy('eventsubmission_detail', kwargs={'camp_slug': self.camp.slug, 'pk': self.uuid})
|
|
|
|
|
|
|
|
|
|
|
|
#############################################################################################
|
2017-03-09 23:45:50 +00:00
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
|
2017-03-07 23:24:14 +00:00
|
|
|
class EventLocation(CampRelatedModel):
|
2017-02-08 22:34:24 +00:00
|
|
|
""" The places where stuff happens """
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
max_length=100
|
|
|
|
)
|
|
|
|
|
2017-02-08 22:34:24 +00:00
|
|
|
slug = models.SlugField()
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
icon = models.CharField(
|
|
|
|
max_length=100
|
|
|
|
)
|
|
|
|
|
|
|
|
camp = models.ForeignKey(
|
|
|
|
'camps.Camp',
|
|
|
|
related_name='eventlocations'
|
|
|
|
)
|
2017-02-08 22:34:24 +00:00
|
|
|
|
|
|
|
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-03-12 14:43:41 +00:00
|
|
|
name = models.CharField(
|
|
|
|
max_length=100,
|
2017-03-12 15:16:24 +00:00
|
|
|
unique=True,
|
|
|
|
help_text='The name of this event type',
|
2017-03-12 14:43:41 +00:00
|
|
|
)
|
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
slug = models.SlugField()
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
color = models.CharField(
|
2017-03-12 15:16:24 +00:00
|
|
|
max_length=50,
|
|
|
|
help_text='The background color of this event type',
|
2017-03-12 14:43:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
light_text = models.BooleanField(
|
2017-03-12 15:16:24 +00:00
|
|
|
default=False,
|
|
|
|
help_text='Check if this event type should use white text color',
|
2017-03-12 14:43:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
notifications = models.BooleanField(
|
2017-03-12 15:16:24 +00:00
|
|
|
default=False,
|
|
|
|
help_text='Check to send notifications for this event type',
|
|
|
|
)
|
|
|
|
|
|
|
|
public = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
help_text='Check to permit users to submit events of this type',
|
2017-03-12 14:43:41 +00:00
|
|
|
)
|
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
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
class Event(CampRelatedModel):
|
2017-01-20 15:18:10 +00:00
|
|
|
""" Something that is on the program one or more times. """
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
help_text='The title of this event',
|
|
|
|
)
|
|
|
|
|
|
|
|
abstract = models.TextField(
|
|
|
|
help_text='The abstract for this event'
|
|
|
|
)
|
|
|
|
|
|
|
|
event_type = models.ForeignKey(
|
|
|
|
'program.EventType',
|
|
|
|
help_text='The type of this event',
|
|
|
|
)
|
|
|
|
|
|
|
|
slug = models.SlugField(
|
|
|
|
blank=True,
|
|
|
|
max_length=255,
|
|
|
|
help_text='The slug for this event, created automatically',
|
|
|
|
)
|
|
|
|
|
|
|
|
camp = models.ForeignKey(
|
|
|
|
'camps.Camp',
|
|
|
|
related_name='events',
|
|
|
|
help_text='The camp this event belongs to',
|
|
|
|
)
|
2016-08-08 17:36:13 +00:00
|
|
|
|
2017-02-23 20:51:36 +00:00
|
|
|
video_url = models.URLField(
|
|
|
|
max_length=1000,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
2017-03-12 14:43:41 +00:00
|
|
|
help_text='URL to the recording'
|
2017-02-23 20:51:36 +00:00
|
|
|
)
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-02-23 20:51:36 +00:00
|
|
|
video_recording = models.BooleanField(
|
|
|
|
default=True,
|
2017-03-12 14:43:41 +00:00
|
|
|
help_text='Do we intend to record video of this event?'
|
2017-02-23 20:51:36 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy('event_detail', kwargs={'camp_slug': self.camp.slug, 'slug': self.slug})
|
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
|
2017-03-07 23:24:14 +00:00
|
|
|
class EventInstance(CampRelatedModel):
|
2016-12-25 14:52:55 +00:00
|
|
|
""" An instance of an event """
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
event = models.ForeignKey(
|
|
|
|
'program.event',
|
|
|
|
related_name='instances'
|
|
|
|
)
|
|
|
|
|
2017-01-20 15:18:10 +00:00
|
|
|
when = DateTimeRangeField()
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
notifications_sent = models.BooleanField(
|
|
|
|
default=False
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-07 20:44:30 +00:00
|
|
|
@property
|
|
|
|
def camp(self):
|
|
|
|
return self.event.camp
|
|
|
|
|
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
|
|
|
|
2017-02-18 11:44:12 +00:00
|
|
|
def get_speaker_picture_upload_path(instance, filename):
|
2017-02-19 13:05:26 +00:00
|
|
|
""" We want speaker pictures are saved as MEDIA_ROOT/public/speakers/camp-slug/speaker-slug/filename """
|
|
|
|
return 'public/speakers/%(campslug)s/%(speakerslug)s/%(filename)s' % {
|
2017-02-19 12:15:55 +00:00
|
|
|
'campslug': instance.camp.slug,
|
|
|
|
'speakerslug': instance.slug,
|
|
|
|
'filename': filename
|
|
|
|
}
|
2017-02-18 11:44:12 +00:00
|
|
|
|
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
class Speaker(CampRelatedModel):
|
|
|
|
""" A Person (co)anchoring one or more events on a camp. """
|
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
max_length=150,
|
|
|
|
help_text='Name or alias of the speaker',
|
|
|
|
)
|
|
|
|
|
2017-03-11 11:12:07 +00:00
|
|
|
biography = models.TextField(
|
|
|
|
help_text='Markdown is supported.'
|
|
|
|
)
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-03-11 11:12:07 +00:00
|
|
|
picture_small = models.ImageField(
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
upload_to=get_speaker_picture_upload_path,
|
2017-03-12 14:43:41 +00:00
|
|
|
help_text='A thumbnail of the speaker picture'
|
2017-03-11 11:12:07 +00:00
|
|
|
)
|
2017-03-12 14:43:41 +00:00
|
|
|
|
2017-03-11 11:12:07 +00:00
|
|
|
picture_large = models.ImageField(
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
upload_to=get_speaker_picture_upload_path,
|
2017-03-12 14:43:41 +00:00
|
|
|
help_text='A picture of the speaker'
|
2017-03-11 11:12:07 +00:00
|
|
|
)
|
2017-03-12 14:43:41 +00:00
|
|
|
|
|
|
|
slug = models.SlugField(
|
|
|
|
blank=True,
|
|
|
|
max_length=255,
|
|
|
|
help_text='The slug for this speaker, will be autocreated',
|
|
|
|
)
|
|
|
|
|
|
|
|
camp = models.ForeignKey(
|
|
|
|
'camps.Camp',
|
|
|
|
null=True,
|
|
|
|
related_name='speakers',
|
|
|
|
help_text='The camp this speaker belongs to',
|
|
|
|
)
|
|
|
|
|
2016-07-13 17:13:47 +00:00
|
|
|
events = models.ManyToManyField(
|
|
|
|
Event,
|
2016-08-04 21:03:39 +00:00
|
|
|
blank=True,
|
2017-03-12 14:43:41 +00:00
|
|
|
help_text='The event(s) this speaker is anchoring',
|
2016-07-13 19:44:09 +00:00
|
|
|
)
|
2016-07-13 20:37:20 +00:00
|
|
|
|
2017-03-12 14:43:41 +00:00
|
|
|
submission = models.OneToOneField(
|
|
|
|
'program.SpeakerSubmission',
|
2017-03-07 23:00:17 +00:00
|
|
|
null=True,
|
2017-03-12 14:43:41 +00:00
|
|
|
blank=True,
|
|
|
|
help_text='The speaker submission object this speaker was created from',
|
2017-03-07 23:00:17 +00:00
|
|
|
)
|
|
|
|
|
2016-08-08 17:36:13 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
2017-03-12 14:43:41 +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
|
|
|
|
2017-03-07 23:00:17 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy('speaker_detail', kwargs={'camp_slug': self.camp.slug, 'slug': self.slug})
|
|
|
|
|
2017-02-18 11:44:12 +00:00
|
|
|
|