2012-02-06 02:59:14 +00:00
|
|
|
from django.db import models
|
2012-02-19 18:54:36 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2012-02-06 02:59:14 +00:00
|
|
|
|
|
|
|
from timezones.fields import TimeZoneField
|
|
|
|
|
|
|
|
|
2012-02-06 03:34:12 +00:00
|
|
|
CONFERENCE_CACHE = {}
|
|
|
|
|
|
|
|
|
2012-02-06 02:59:14 +00:00
|
|
|
class Conference(models.Model):
|
|
|
|
"""
|
|
|
|
the full conference for a specific year, e.g. US PyCon 2012.
|
|
|
|
"""
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-22 22:37:05 +00:00
|
|
|
title = models.CharField(_("title"), max_length=100)
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-06 02:59:14 +00:00
|
|
|
# when the conference runs
|
2012-02-22 22:37:05 +00:00
|
|
|
start_date = models.DateField(_("start date"), null=True, blank=True)
|
|
|
|
end_date = models.DateField(_("end date"), null=True, blank=True)
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-06 02:59:14 +00:00
|
|
|
# timezone the conference is in
|
2012-02-22 22:37:05 +00:00
|
|
|
timezone = TimeZoneField(_("timezone"), blank=True)
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-06 02:59:14 +00:00
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-06 03:34:12 +00:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
super(Conference, self).save(*args, **kwargs)
|
|
|
|
if self.id in CONFERENCE_CACHE:
|
|
|
|
del CONFERENCE_CACHE[self.id]
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-06 03:34:12 +00:00
|
|
|
def delete(self):
|
|
|
|
pk = self.pk
|
|
|
|
super(Conference, self).delete()
|
|
|
|
try:
|
|
|
|
del CONFERENCE_CACHE[pk]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-19 18:54:36 +00:00
|
|
|
class Meta(object):
|
2012-02-22 22:37:05 +00:00
|
|
|
verbose_name = _("conference")
|
|
|
|
verbose_name_plural = _("conferences")
|
2012-02-19 18:54:36 +00:00
|
|
|
|
2012-02-06 02:59:14 +00:00
|
|
|
|
|
|
|
class Section(models.Model):
|
|
|
|
"""
|
|
|
|
a section of the conference such as "Tutorials", "Workshops",
|
|
|
|
"Talks", "Expo", "Sprints", that may have its own review and
|
|
|
|
scheduling process.
|
|
|
|
"""
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-22 22:37:05 +00:00
|
|
|
conference = models.ForeignKey(Conference, verbose_name=_("conference"))
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-22 22:37:05 +00:00
|
|
|
name = models.CharField(_("name"), max_length=100)
|
2012-07-12 04:38:01 +00:00
|
|
|
slug = models.SlugField()
|
|
|
|
|
2012-02-06 02:59:14 +00:00
|
|
|
# when the section runs
|
2012-02-22 22:37:05 +00:00
|
|
|
start_date = models.DateField(_("start date"), null=True, blank=True)
|
|
|
|
end_date = models.DateField(_("end date"), null=True, blank=True)
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-06 02:59:14 +00:00
|
|
|
def __unicode__(self):
|
2012-07-12 04:38:01 +00:00
|
|
|
return "%s %s" % (self.conference, self.name)
|
2014-01-14 14:47:49 +00:00
|
|
|
|
2012-02-19 18:54:36 +00:00
|
|
|
class Meta(object):
|
2012-02-22 22:37:05 +00:00
|
|
|
verbose_name = _("section")
|
|
|
|
verbose_name_plural = _("sections")
|
2013-01-27 09:48:11 +00:00
|
|
|
ordering = ["start_date"]
|
2012-02-19 18:54:36 +00:00
|
|
|
|
2012-02-06 03:34:12 +00:00
|
|
|
|
|
|
|
def current_conference():
|
|
|
|
from django.conf import settings
|
|
|
|
try:
|
|
|
|
conf_id = settings.CONFERENCE_ID
|
|
|
|
except AttributeError:
|
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
raise ImproperlyConfigured("You must set the CONFERENCE_ID setting.")
|
|
|
|
try:
|
|
|
|
current_conf = CONFERENCE_CACHE[conf_id]
|
|
|
|
except KeyError:
|
|
|
|
current_conf = Conference.objects.get(pk=conf_id)
|
|
|
|
CONFERENCE_CACHE[conf_id] = current_conf
|
|
|
|
return current_conf
|