Files
postgres-web/pgweb/events/models.py
Magnus Hagander 5055c330c7 Add checkbox for "is online" on events
This gets rid of the annoying requirement to specify things like
"online, United States" for events that are online.

This requires some SQL to run on existing installations:
ALTER TABLE events_event ADD COLUMN isonline boolean NOT NULL DEFAULT 'f';
ALTER TABLE events_event ALTER COLUMN isonline DROP DEFAULT;
ALTER TABLE events_event ALTER COLUMN country_id DROP NOT NULL;

Fixes #166
2013-01-30 14:07:48 +01:00

73 lines
2.5 KiB
Python

from django.db import models
from django.contrib.auth.models import User
from datetime import date
from pgweb.util.bases import PgModel
from core.models import Country, Organisation
class Event(PgModel, models.Model):
approved = models.BooleanField(null=False, blank=False, default=False)
org = models.ForeignKey(Organisation, null=False, blank=False, verbose_name="Organisation", help_text="If no organisations are listed, please check the <a href=\"/account/orglist/\">organisation list</a> and contact the organisation manager or webmaster@postgresql.org if none are listed.")
title = models.CharField(max_length=100, null=False, blank=False)
isonline = models.BooleanField(null=False, default=False, verbose_name="Online event")
city = models.CharField(max_length=50, null=False, blank=True)
state = models.CharField(max_length=50, null=False, blank=True)
country = models.ForeignKey(Country, null=True, blank=True)
training = models.BooleanField(null=False, blank=False, default=False)
startdate = models.DateField(null=False, blank=False, verbose_name="Start date")
enddate = models.DateField(null=False, blank=False, verbose_name="End date")
summary = models.TextField(blank=False, null=False, help_text="A short introduction (shown on the events listing page)")
details = models.TextField(blank=False, null=False, help_text="Complete event description")
send_notification = True
markdown_fields = ('details', 'summary', )
def purge_urls(self):
yield '/about/event/%s/' % self.pk
yield '/about/eventarchive/'
yield '/events.rss'
# FIXME: when to expire the front page?
yield '/$'
def __unicode__(self):
return "%s: %s" % (self.startdate, self.title)
def verify_submitter(self, user):
return (len(self.org.managers.filter(pk=user.pk)) == 1)
@property
def has_organisation(self):
mgrs = self.org.managers.all()
if len(mgrs) == 1:
if mgrs[0].pk == 0:
return False # Migration organisation
else:
return True # Has an actual organisation
elif len(mgrs) > 1:
# More than one manager means it must be new
return True
return False # Has no organisastion at all
@property
def displaydate(self):
if self.startdate == self.enddate:
return self.startdate
else:
return "%s &ndash; %s" % (self.startdate, self.enddate)
@property
def locationstring(self):
if self.isonline:
return "online"
elif self.state:
return "%s, %s, %s" % (self.city, self.state, self.country)
else:
return "%s, %s" % (self.city, self.country)
class Meta:
ordering = ('-startdate','-enddate',)