Mercurial > public > sg101
comparison gpp/gcalendar/models.py @ 228:d77e0dc772ad
Implement #88; add option to create a new forum thread from a new calendar entry.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 11 Jul 2010 21:03:41 +0000 |
parents | e04d91babfcf |
children | 5be072292e2d |
comparison
equal
deleted
inserted
replaced
227:423c39ee44e0 | 228:d77e0dc772ad |
---|---|
4 from django.db import models | 4 from django.db import models |
5 from django.db.models import Q | 5 from django.db.models import Q |
6 from django.contrib.auth.models import User | 6 from django.contrib.auth.models import User |
7 | 7 |
8 from core.markup import site_markup | 8 from core.markup import site_markup |
9 import forums.tools | |
9 | 10 |
11 | |
12 GIG_FORUM_SLUG = "gigs" | |
10 | 13 |
11 class PendingEventManager(models.Manager): | 14 class PendingEventManager(models.Manager): |
12 """A manager for pending events.""" | 15 """A manager for pending events.""" |
13 | 16 |
14 def get_query_set(self): | 17 def get_query_set(self): |
35 (DEL_REQ, 'Delete Request'), | 38 (DEL_REQ, 'Delete Request'), |
36 (DEL_APRV, 'Delete Approved'), | 39 (DEL_APRV, 'Delete Approved'), |
37 (ON_CAL, 'On Calendar'), | 40 (ON_CAL, 'On Calendar'), |
38 ) | 41 ) |
39 | 42 |
40 REPEAT_CHOICES = ( | |
41 ('none', 'Does not repeat'), | |
42 ('daily', 'Daily'), | |
43 ('weekly', 'Weekly'), | |
44 ('monthly', 'Monthly'), | |
45 ('yearly', 'Yearly') | |
46 ) | |
47 | |
48 user = models.ForeignKey(User) | 43 user = models.ForeignKey(User) |
49 what = models.CharField(max_length=255) | 44 what = models.CharField(max_length=255) |
50 start_date = models.DateField() | 45 start_date = models.DateField() |
51 start_time = models.TimeField(null=True, blank=True) | 46 start_time = models.TimeField(null=True, blank=True) |
52 end_date = models.DateField() | 47 end_date = models.DateField() |
53 end_time = models.TimeField(null=True, blank=True) | 48 end_time = models.TimeField(null=True, blank=True) |
54 time_zone = models.CharField(max_length=64, blank=True) | 49 time_zone = models.CharField(max_length=64, blank=True) |
55 all_day = models.BooleanField(default=False) | 50 all_day = models.BooleanField(default=False) |
56 repeat = models.CharField(max_length=7, choices=REPEAT_CHOICES) | |
57 repeat_interval = models.IntegerField(null=True, blank=True, | |
58 help_text='Only valid for repeating events.') | |
59 until_date = models.DateField(null=True, blank=True, | |
60 help_text='Only valid for repeating events; leave blank for no end date.') | |
61 weekly_sun = models.BooleanField(default=False, verbose_name='Weekly on Sun', | |
62 help_text='Only valid for weekly repeats.') | |
63 weekly_mon = models.BooleanField(default=False, verbose_name='Weekly on Mon', | |
64 help_text='Only valid for weekly repeats.') | |
65 weekly_tue = models.BooleanField(default=False, verbose_name='Weekly on Tue', | |
66 help_text='Only valid for weekly repeats.') | |
67 weekly_wed = models.BooleanField(default=False, verbose_name='Weekly on Wed', | |
68 help_text='Only valid for weekly repeats.') | |
69 weekly_thu = models.BooleanField(default=False, verbose_name='Weekly on Thu', | |
70 help_text='Only valid for weekly repeats.') | |
71 weekly_fri = models.BooleanField(default=False, verbose_name='Weekly on Fri', | |
72 help_text='Only valid for weekly repeats.') | |
73 weekly_sat = models.BooleanField(default=False, verbose_name='Weekly on Sat', | |
74 help_text='Only valid for weekly repeats.') | |
75 monthly_by_day = models.BooleanField(default=False, | |
76 help_text='Only valid for monthly repeats; Checked: By day of the month, Unchecked: By day of the week.') | |
77 where = models.CharField(max_length=255, blank=True) | 51 where = models.CharField(max_length=255, blank=True) |
78 description = models.TextField(blank=True) | 52 description = models.TextField(blank=True) |
79 html = models.TextField(blank=True) | 53 html = models.TextField(blank=True) |
80 date_submitted = models.DateTimeField(auto_now_add=True) | 54 date_submitted = models.DateTimeField(auto_now_add=True) |
81 google_id = models.CharField(max_length=255, blank=True) | 55 google_id = models.CharField(max_length=255, blank=True) |
82 status = models.SmallIntegerField(choices=STATUS_CHOICES, default=NEW, db_index=True) | 56 google_url = models.URLField(verify_exists=False, max_length=255, |
57 blank=True) | |
58 status = models.SmallIntegerField(choices=STATUS_CHOICES, default=NEW, | |
59 db_index=True) | |
60 create_forum_thread = models.BooleanField(default=False) | |
83 | 61 |
84 objects = models.Manager() | 62 objects = models.Manager() |
85 pending_events = PendingEventManager() | 63 pending_events = PendingEventManager() |
86 | 64 |
87 def __unicode__(self): | 65 def __unicode__(self): |
96 | 74 |
97 def is_approved(self): | 75 def is_approved(self): |
98 return self.status not in (self.NEW, self.EDIT_REQ, self.DEL_REQ) | 76 return self.status not in (self.NEW, self.EDIT_REQ, self.DEL_REQ) |
99 is_approved.boolean = True | 77 is_approved.boolean = True |
100 | 78 |
79 def google_html(self): | |
80 """Returns a HTML <a> tag to the event if it exits.""" | |
81 if self.google_url: | |
82 return u'<a href="%s">On Google</a>' % self.google_url | |
83 return u'' | |
84 google_html.allow_tags = True | |
85 google_html.short_description = 'Google Link' | |
86 | |
87 def notify_on_calendar(self): | |
88 """ | |
89 This function should be called when the event has been added to the | |
90 Google calendar for the first time. This gives us a chance to perform | |
91 any first-time processing, like creating a forum thread. | |
92 """ | |
93 if self.create_forum_thread: | |
94 topic_name = '%s: %s' % (self.start_date.strftime('%m/%d/%Y'), | |
95 self.what) | |
96 post_body = "%s\n\n[Link to event on Google Calendar](%s)" % ( | |
97 self.description, self.google_url) | |
98 | |
99 forums.tools.create_topic( | |
100 forum_slug=GIG_FORUM_SLUG, | |
101 user=self.user, | |
102 topic_name=topic_name, | |
103 post_body=post_body) | |
104 | |
105 self.create_forum_thread = False | |
106 self.save() |