comparison gpp/gcalendar/models.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children 9c18250972d5
comparison
equal deleted inserted replaced
0:900ba3c7b765 1:dbd703f7d63a
1 """
2 Models for the gcalendar application.
3 """
4 from django.db import models
5 from django.db.models import Q
6 from django.contrib.auth.models import User
7 from django.template.loader import render_to_string
8
9
10 class PendingEventManager(models.Manager):
11 """A manager for pending events."""
12
13 def get_query_set(self):
14 """Returns a queryset of events that have been approved to update
15 the Google calendar."""
16 return super(PendingEventManager, self).get_query_set().filter(
17 Q(status=Event.NEW_APRV) | \
18 Q(status=Event.EDIT_APRV) | \
19 Q(status=Event.DEL_APRV)
20 )
21
22
23 class Event(models.Model):
24 """Model to represent calendar events."""
25
26 # Event status codes:
27 (NEW, NEW_APRV, EDIT_REQ, EDIT_APRV, DEL_REQ, DEL_APRV, ON_CAL) = range(7)
28
29 STATUS_CHOICES = (
30 (NEW, 'New'),
31 (NEW_APRV, 'New Approved'),
32 (EDIT_REQ, 'Edit Request'),
33 (EDIT_APRV, 'Edit Approved'),
34 (DEL_REQ, 'Delete Request'),
35 (DEL_APRV, 'Delete Approved'),
36 (ON_CAL, 'On Calendar'),
37 )
38
39 REPEAT_CHOICES = (
40 ('none', 'Does not repeat'),
41 ('daily', 'Daily'),
42 ('weekly', 'Weekly'),
43 ('monthly', 'Monthly'),
44 ('yearly', 'Yearly')
45 )
46
47 user = models.ForeignKey(User)
48 what = models.CharField(max_length=255)
49 start_date = models.DateField()
50 start_time = models.TimeField(null=True, blank=True)
51 end_date = models.DateField()
52 end_time = models.TimeField(null=True, blank=True)
53 time_zone = models.CharField(max_length=64, blank=True)
54 all_day = models.BooleanField(default=False)
55 repeat = models.CharField(max_length=7, choices=REPEAT_CHOICES)
56 repeat_interval = models.IntegerField(null=True, blank=True,
57 help_text='Only valid for repeating events.')
58 until_date = models.DateField(null=True, blank=True,
59 help_text='Only valid for repeating events; leave blank for no end date.')
60 weekly_sun = models.BooleanField(default=False, verbose_name='Weekly on Sun',
61 help_text='Only valid for weekly repeats.')
62 weekly_mon = models.BooleanField(default=False, verbose_name='Weekly on Mon',
63 help_text='Only valid for weekly repeats.')
64 weekly_tue = models.BooleanField(default=False, verbose_name='Weekly on Tue',
65 help_text='Only valid for weekly repeats.')
66 weekly_wed = models.BooleanField(default=False, verbose_name='Weekly on Wed',
67 help_text='Only valid for weekly repeats.')
68 weekly_thu = models.BooleanField(default=False, verbose_name='Weekly on Thu',
69 help_text='Only valid for weekly repeats.')
70 weekly_fri = models.BooleanField(default=False, verbose_name='Weekly on Fri',
71 help_text='Only valid for weekly repeats.')
72 weekly_sat = models.BooleanField(default=False, verbose_name='Weekly on Sat',
73 help_text='Only valid for weekly repeats.')
74 monthly_by_day = models.BooleanField(default=False,
75 help_text='Only valid for monthly repeats; Checked: By day of the month, Unchecked: By day of the week.')
76 where = models.CharField(max_length=255, blank=True)
77 description = models.TextField(blank=True)
78 html = models.TextField(blank=True)
79 date_submitted = models.DateTimeField(auto_now_add=True)
80 google_id = models.CharField(max_length=255, blank=True)
81 status = models.SmallIntegerField(choices=STATUS_CHOICES, default=NEW, db_index=True)
82
83 objects = models.Manager()
84 pending_events = PendingEventManager()
85
86 def __unicode__(self):
87 return self.what
88
89 class Meta:
90 ordering = ('-date_submitted', )
91
92 def save(self, *args, **kwargs):
93 html = render_to_string('gcalendar/markdown.html', {'data': self.description})
94 self.html = html.strip()
95 super(Event, self).save(*args, **kwargs)
96
97 def needs_approval(self):
98 return self.status in (self.NEW, self.EDIT_REQ, self.DEL_REQ)
99
100
101 # vim: ts=4 sw=4