annotate gpp/gcalendar/models.py @ 197:2baadae33f2e

Got autocomplete working for the member search. Updated django and ran into a bug where url tags with comma separated kwargs starting consuming tons of CPU throughput. The work-around is to cut over to using spaces between arguments. This is now allowed to be consistent with other tags. Did some query optimization for the news app.
author Brian Neal <bgneal@gmail.com>
date Sat, 10 Apr 2010 04:32:24 +0000
parents e04d91babfcf
children d77e0dc772ad
rev   line source
gremmie@1 1 """
gremmie@1 2 Models for the gcalendar application.
gremmie@1 3 """
gremmie@1 4 from django.db import models
gremmie@1 5 from django.db.models import Q
gremmie@1 6 from django.contrib.auth.models import User
bgneal@124 7
bgneal@128 8 from core.markup import site_markup
gremmie@1 9
gremmie@1 10
gremmie@1 11 class PendingEventManager(models.Manager):
gremmie@1 12 """A manager for pending events."""
gremmie@1 13
gremmie@1 14 def get_query_set(self):
gremmie@1 15 """Returns a queryset of events that have been approved to update
gremmie@1 16 the Google calendar."""
gremmie@1 17 return super(PendingEventManager, self).get_query_set().filter(
gremmie@1 18 Q(status=Event.NEW_APRV) | \
gremmie@1 19 Q(status=Event.EDIT_APRV) | \
gremmie@1 20 Q(status=Event.DEL_APRV)
gremmie@1 21 )
gremmie@1 22
gremmie@1 23
gremmie@1 24 class Event(models.Model):
gremmie@1 25 """Model to represent calendar events."""
gremmie@1 26
gremmie@1 27 # Event status codes:
gremmie@1 28 (NEW, NEW_APRV, EDIT_REQ, EDIT_APRV, DEL_REQ, DEL_APRV, ON_CAL) = range(7)
gremmie@1 29
gremmie@1 30 STATUS_CHOICES = (
gremmie@1 31 (NEW, 'New'),
gremmie@1 32 (NEW_APRV, 'New Approved'),
gremmie@1 33 (EDIT_REQ, 'Edit Request'),
gremmie@1 34 (EDIT_APRV, 'Edit Approved'),
gremmie@1 35 (DEL_REQ, 'Delete Request'),
gremmie@1 36 (DEL_APRV, 'Delete Approved'),
gremmie@1 37 (ON_CAL, 'On Calendar'),
gremmie@1 38 )
gremmie@1 39
gremmie@1 40 REPEAT_CHOICES = (
gremmie@1 41 ('none', 'Does not repeat'),
gremmie@1 42 ('daily', 'Daily'),
gremmie@1 43 ('weekly', 'Weekly'),
gremmie@1 44 ('monthly', 'Monthly'),
gremmie@1 45 ('yearly', 'Yearly')
gremmie@1 46 )
gremmie@1 47
gremmie@1 48 user = models.ForeignKey(User)
gremmie@1 49 what = models.CharField(max_length=255)
gremmie@1 50 start_date = models.DateField()
gremmie@1 51 start_time = models.TimeField(null=True, blank=True)
gremmie@1 52 end_date = models.DateField()
gremmie@1 53 end_time = models.TimeField(null=True, blank=True)
gremmie@1 54 time_zone = models.CharField(max_length=64, blank=True)
gremmie@1 55 all_day = models.BooleanField(default=False)
gremmie@1 56 repeat = models.CharField(max_length=7, choices=REPEAT_CHOICES)
gremmie@1 57 repeat_interval = models.IntegerField(null=True, blank=True,
gremmie@1 58 help_text='Only valid for repeating events.')
gremmie@1 59 until_date = models.DateField(null=True, blank=True,
gremmie@1 60 help_text='Only valid for repeating events; leave blank for no end date.')
gremmie@1 61 weekly_sun = models.BooleanField(default=False, verbose_name='Weekly on Sun',
gremmie@1 62 help_text='Only valid for weekly repeats.')
gremmie@1 63 weekly_mon = models.BooleanField(default=False, verbose_name='Weekly on Mon',
gremmie@1 64 help_text='Only valid for weekly repeats.')
gremmie@1 65 weekly_tue = models.BooleanField(default=False, verbose_name='Weekly on Tue',
gremmie@1 66 help_text='Only valid for weekly repeats.')
gremmie@1 67 weekly_wed = models.BooleanField(default=False, verbose_name='Weekly on Wed',
gremmie@1 68 help_text='Only valid for weekly repeats.')
gremmie@1 69 weekly_thu = models.BooleanField(default=False, verbose_name='Weekly on Thu',
gremmie@1 70 help_text='Only valid for weekly repeats.')
gremmie@1 71 weekly_fri = models.BooleanField(default=False, verbose_name='Weekly on Fri',
gremmie@1 72 help_text='Only valid for weekly repeats.')
gremmie@1 73 weekly_sat = models.BooleanField(default=False, verbose_name='Weekly on Sat',
gremmie@1 74 help_text='Only valid for weekly repeats.')
gremmie@1 75 monthly_by_day = models.BooleanField(default=False,
gremmie@1 76 help_text='Only valid for monthly repeats; Checked: By day of the month, Unchecked: By day of the week.')
gremmie@1 77 where = models.CharField(max_length=255, blank=True)
gremmie@1 78 description = models.TextField(blank=True)
gremmie@1 79 html = models.TextField(blank=True)
gremmie@1 80 date_submitted = models.DateTimeField(auto_now_add=True)
gremmie@1 81 google_id = models.CharField(max_length=255, blank=True)
gremmie@1 82 status = models.SmallIntegerField(choices=STATUS_CHOICES, default=NEW, db_index=True)
gremmie@1 83
gremmie@1 84 objects = models.Manager()
gremmie@1 85 pending_events = PendingEventManager()
gremmie@1 86
gremmie@1 87 def __unicode__(self):
gremmie@1 88 return self.what
gremmie@1 89
gremmie@1 90 class Meta:
gremmie@1 91 ordering = ('-date_submitted', )
gremmie@1 92
gremmie@1 93 def save(self, *args, **kwargs):
bgneal@128 94 self.html = site_markup(self.description)
gremmie@1 95 super(Event, self).save(*args, **kwargs)
gremmie@1 96
bgneal@139 97 def is_approved(self):
bgneal@139 98 return self.status not in (self.NEW, self.EDIT_REQ, self.DEL_REQ)
bgneal@139 99 is_approved.boolean = True
gremmie@1 100