symposion_app/symposion/schedule/models.py
Patrick Altman f3614fcf52 Merge branch 'master' of https://github.com/pyohio/symposion into pyohio-master
Conflicts:
	README.md
	symposion/boxes/urls.py
	symposion/cms/urls.py
	symposion/proposals/actions.py
	symposion/proposals/urls.py
	symposion/proposals/views.py
	symposion/reviews/tests.py
	symposion/reviews/urls.py
	symposion/reviews/views.py
	symposion/schedule/forms.py
	symposion/schedule/models.py
	symposion/schedule/views.py
	symposion/speakers/fixture_gen.py
	symposion/sponsorship/urls.py
	symposion/templates/cms/file_create.html
	symposion/templates/cms/file_index.html
	symposion/templates/conference/user_list.html
	symposion/templates/dashboard.html
	symposion/templates/emails/proposal_new_message/message.html
	symposion/templates/emails/proposal_updated/message.html
	symposion/templates/emails/speaker_addition/message.html
	symposion/templates/emails/speaker_invite/message.html
	symposion/templates/proposals/_pending_proposal_row.html
	symposion/templates/proposals/_proposal_fields.html
	symposion/templates/proposals/_proposal_row.html
	symposion/templates/proposals/proposal_cancel.html
	symposion/templates/proposals/proposal_detail.html
	symposion/templates/proposals/proposal_edit.html
	symposion/templates/proposals/proposal_speaker_manage.html
	symposion/templates/proposals/proposal_submit.html
	symposion/templates/reviews/_review_table.html
	symposion/templates/reviews/base.html
	symposion/templates/reviews/result_notification.html
	symposion/templates/reviews/result_notification_prepare.html
	symposion/templates/reviews/review_admin.html
	symposion/templates/reviews/review_assignment.html
	symposion/templates/reviews/review_detail.html
	symposion/templates/reviews/review_review.html
	symposion/templates/reviews/review_stats.html
	symposion/templates/schedule/_edit_grid.html
	symposion/templates/schedule/_grid.html
	symposion/templates/schedule/_slot_edit.html
	symposion/templates/schedule/presentation_detail.html
	symposion/templates/schedule/schedule_list.html
	symposion/templates/speakers/speaker_create.html
	symposion/templates/speakers/speaker_edit.html
	symposion/templates/speakers/speaker_profile.html
	symposion/templates/sponsorship/add.html
	symposion/templates/sponsorship/apply.html
	symposion/templates/sponsorship/detail.html
	symposion/templates/sponsorship/list.html
	symposion/templates/teams/team_detail.html
2014-12-15 16:07:37 -06:00

181 lines
4.7 KiB
Python

import datetime
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from markitup.fields import MarkupField
from symposion.proposals.models import ProposalBase
from symposion.conference.models import Section
class Schedule(models.Model):
section = models.OneToOneField(Section)
published = models.BooleanField(default=True)
hidden = models.BooleanField("Hide schedule from overall conference view", default=False)
def __unicode__(self):
return "%s Schedule" % self.section
class Meta:
ordering = ["section"]
class Day(models.Model):
schedule = models.ForeignKey(Schedule)
date = models.DateField()
def __unicode__(self):
return "%s" % self.date
class Meta:
unique_together = [("schedule", "date")]
ordering = ["date"]
class Room(models.Model):
schedule = models.ForeignKey(Schedule)
name = models.CharField(max_length=65)
order = models.PositiveIntegerField()
def __unicode__(self):
return self.name
class SlotKind(models.Model):
"""
A slot kind represents what kind a slot is. For example, a slot can be a
break, lunch, or X-minute talk.
"""
schedule = models.ForeignKey(Schedule)
label = models.CharField(max_length=50)
def __unicode__(self):
return self.label
class Slot(models.Model):
day = models.ForeignKey(Day)
kind = models.ForeignKey(SlotKind)
start = models.TimeField()
end = models.TimeField()
content_override = MarkupField(blank=True)
def assign(self, content):
"""
Assign the given content to this slot and if a previous slot content
was given we need to unlink it to avoid integrity errors.
"""
self.unassign()
content.slot = self
content.save()
def unassign(self):
"""
Unassign the associated content with this slot.
"""
content = self.content
if content and content.slot_id:
content.slot = None
content.save()
@property
def content(self):
"""
Return the content this slot represents.
@@@ hard-coded for presentation for now
"""
try:
return self.content_ptr
except ObjectDoesNotExist:
return None
@property
def start_datetime(self):
return datetime.datetime(
self.day.date.year,
self.day.date.month,
self.day.date.day,
self.start.hour,
self.start.minute)
@property
def end_datetime(self):
return datetime.datetime(
self.day.date.year,
self.day.date.month,
self.day.date.day,
self.end.hour,
self.end.minute)
@property
def length_in_minutes(self):
return int(
(self.end_datetime - self.start_datetime).total_seconds() / 60)
@property
def rooms(self):
return Room.objects.filter(pk__in=self.slotroom_set.values("room"))
def __unicode__(self):
return "%s %s (%s - %s)" % (self.day, self.kind, self.start, self.end)
class Meta:
ordering = ["day", "start", "end"]
class SlotRoom(models.Model):
"""
Links a slot with a room.
"""
slot = models.ForeignKey(Slot)
room = models.ForeignKey(Room)
def __unicode__(self):
return "%s %s" % (self.room, self.slot)
class Meta:
unique_together = [("slot", "room")]
ordering = ["slot", "room__order"]
class Presentation(models.Model):
slot = models.OneToOneField(Slot, null=True, blank=True, related_name="content_ptr")
title = models.CharField(max_length=100)
description = MarkupField()
abstract = MarkupField()
speaker = models.ForeignKey("speakers.Speaker", related_name="presentations")
additional_speakers = models.ManyToManyField("speakers.Speaker", related_name="copresentations",
blank=True)
cancelled = models.BooleanField(default=False)
proposal_base = models.OneToOneField(ProposalBase, related_name="presentation")
section = models.ForeignKey(Section, related_name="presentations")
@property
def number(self):
return self.proposal.number
@property
def proposal(self):
if self.proposal_base_id is None:
return None
return ProposalBase.objects.get_subclass(pk=self.proposal_base_id)
def speakers(self):
yield self.speaker
for speaker in self.additional_speakers.all():
if speaker.user:
yield speaker
def __unicode__(self):
return "#%s %s (%s)" % (self.number, self.title, self.speaker)
class Meta:
ordering = ["slot"]