Merge lp:~mhall119/loco-team-portal/team-events-localtime into lp:loco-team-portal
- team-events-localtime
- Merge into 0.2
Proposed by
Michael Hall
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Michael Hall | ||||
Approved revision: | 332 | ||||
Merged at revision: | 327 | ||||
Proposed branch: | lp:~mhall119/loco-team-portal/team-events-localtime | ||||
Merge into: | lp:loco-team-portal | ||||
Diff against target: |
338 lines (+165/-13) 11 files modified
INSTALL (+1/-1) loco_directory/events/forms.py (+13/-0) loco_directory/events/models.py (+38/-4) loco_directory/templates/events/global_event_detail_basic.inc.html (+2/-2) loco_directory/templates/events/team_event_detail_basic.inc.html (+3/-3) loco_directory/templates/events/team_event_detail_comments.inc.html (+1/-1) loco_directory/templates/events/team_event_list.inc.html (+2/-2) loco_directory/templates/venues/venue_detail_basic.inc.html (+6/-0) loco_directory/userprofiles/models.py (+17/-0) loco_directory/venues/migrations/0005_add_venue_timezone.py (+47/-0) loco_directory/venues/models.py (+35/-0) |
||||
To merge this branch: | bzr merge lp:~mhall119/loco-team-portal/team-events-localtime | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Johnston | Approve | ||
Daniel Holbach (community) | Approve | ||
Review via email: mp+41306@code.launchpad.net |
Commit message
Description of the change
Requires a minor db schema change to add tz CharField to Venue model.
To post a comment you must log in.
Revision history for this message
Michael Hall (mhall119) wrote : | # |
- 331. By Michael Hall
-
Check for date difference between begin and end using localtime instead of UTC
- 332. By Michael Hall
-
Add python-tz to the list of packages to apt-get install
Revision history for this message
Daniel Holbach (dholbach) wrote : | # |
Looks good to me.
Can somebody else try this out too? I didn't test with old data.
review:
Approve
Revision history for this message
Chris Johnston (cjohnston) wrote : | # |
It looks good to me.. Tested with events already scheduled, going back and changing the TZ of the venue, which seemed to work perfectly. Then went and created new events and new venues, which also worked well.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'INSTALL' | |||
2 | --- INSTALL 2010-07-01 06:27:09 +0000 | |||
3 | +++ INSTALL 2010-11-19 13:47:33 +0000 | |||
4 | @@ -8,7 +8,7 @@ | |||
5 | 8 | - sudo -u postgres createdb -O postgres loco_directory | 8 | - sudo -u postgres createdb -O postgres loco_directory |
6 | 9 | 9 | ||
7 | 10 | Generally: | 10 | Generally: |
9 | 11 | - sudo apt-get install python-django python-launchpadlib libjs-jquery-ui python-django-openid-auth python-django-south iso-codes | 11 | - sudo apt-get install python-django python-launchpadlib libjs-jquery-ui python-django-openid-auth python-django-south iso-codes python-tz |
10 | 12 | - cd loco_directory | 12 | - cd loco_directory |
11 | 13 | - cp local_settings.py.sample local_settings.py | 13 | - cp local_settings.py.sample local_settings.py |
12 | 14 | # edit local_settings.py and set DATABASE_USER, DATABASE_PASSWORD, SECRET_KEY | 14 | # edit local_settings.py and set DATABASE_USER, DATABASE_PASSWORD, SECRET_KEY |
13 | 15 | 15 | ||
14 | === modified file 'loco_directory/events/forms.py' | |||
15 | --- loco_directory/events/forms.py 2010-10-21 16:13:05 +0000 | |||
16 | +++ loco_directory/events/forms.py 2010-11-19 13:47:33 +0000 | |||
17 | @@ -8,6 +8,8 @@ | |||
18 | 8 | from venues.models import Venue | 8 | from venues.models import Venue |
19 | 9 | from common.forms import RenderableMixin | 9 | from common.forms import RenderableMixin |
20 | 10 | 10 | ||
21 | 11 | import pytz | ||
22 | 12 | |||
23 | 11 | def validate_tag(tag): | 13 | def validate_tag(tag): |
24 | 12 | if tag.startswith('#'): | 14 | if tag.startswith('#'): |
25 | 13 | tag = tag[1:] | 15 | tag = tag[1:] |
26 | @@ -64,6 +66,17 @@ | |||
27 | 64 | self.fields['venue'].choices = self.grouped_venue_list() | 66 | self.fields['venue'].choices = self.grouped_venue_list() |
28 | 65 | from common.widgets import PopupRelatedFieldWidgetWrapper | 67 | from common.widgets import PopupRelatedFieldWidgetWrapper |
29 | 66 | self.fields['venue'].widget = PopupRelatedFieldWidgetWrapper(self.fields['venue'].widget, reverse('venue-new')) | 68 | self.fields['venue'].widget = PopupRelatedFieldWidgetWrapper(self.fields['venue'].widget, reverse('venue-new')) |
30 | 69 | |||
31 | 70 | self.initial['date_begin'] = self.instance.local_date_begin | ||
32 | 71 | self.initial['date_end'] = self.instance.local_date_end | ||
33 | 72 | |||
34 | 73 | def clean(self): | ||
35 | 74 | venue = self.cleaned_data.get('venue') | ||
36 | 75 | begin = self.cleaned_data.get('date_begin') | ||
37 | 76 | end = self.cleaned_data.get('date_end') | ||
38 | 77 | self.cleaned_data['date_begin'] = venue.fromlocaltime(begin) | ||
39 | 78 | self.cleaned_data['date_end'] = venue.fromlocaltime(end) | ||
40 | 79 | return self.cleaned_data | ||
41 | 67 | 80 | ||
42 | 68 | def grouped_venue_list(self): | 81 | def grouped_venue_list(self): |
43 | 69 | """ | 82 | """ |
44 | 70 | 83 | ||
45 | === modified file 'loco_directory/events/models.py' | |||
46 | --- loco_directory/events/models.py 2010-10-14 20:26:51 +0000 | |||
47 | +++ loco_directory/events/models.py 2010-11-19 13:47:33 +0000 | |||
48 | @@ -86,13 +86,11 @@ | |||
49 | 86 | """ manager for a team event """ | 86 | """ manager for a team event """ |
50 | 87 | def next_5_events(self): | 87 | def next_5_events(self): |
51 | 88 | """ a list with the next 5 events """ | 88 | """ a list with the next 5 events """ |
54 | 89 | # XXX: Workaround for https://bugs.launchpad.net/loco-directory/+bug/531970 | 89 | return self.filter(date_end__gt=datetime.datetime.now()).order_by('date_end')[:5] |
53 | 90 | return self.filter(date_end__gt=datetime.datetime.now()-datetime.timedelta(days=1)).order_by('date_end')[:5] | ||
55 | 91 | 90 | ||
56 | 92 | def next_events(self): | 91 | def next_events(self): |
57 | 93 | """ a list with all upcoming team events """ | 92 | """ a list with all upcoming team events """ |
60 | 94 | # XXX: Workaround for https://bugs.launchpad.net/loco-directory/+bug/531970 | 93 | return self.filter(date_end__gt=datetime.datetime.now()).order_by('date_end') |
59 | 95 | return self.filter(date_end__gt=datetime.datetime.now()-datetime.timedelta(days=1)).order_by('date_end') | ||
61 | 96 | 94 | ||
62 | 97 | def history_events(self): | 95 | def history_events(self): |
63 | 98 | """ all team events in history """ | 96 | """ all team events in history """ |
64 | @@ -114,6 +112,30 @@ | |||
65 | 114 | def __unicode__(self): | 112 | def __unicode__(self): |
66 | 115 | return "%s %s %s" % (self.name, self.venue, self.date_begin or "") | 113 | return "%s %s %s" % (self.name, self.venue, self.date_begin or "") |
67 | 116 | 114 | ||
68 | 115 | def get_local_begin(self): | ||
69 | 116 | if self.venue: | ||
70 | 117 | return self.venue.tolocaltime(self.date_begin) | ||
71 | 118 | else: | ||
72 | 119 | return self.date_begin | ||
73 | 120 | def set_local_begin(self, local_begin): | ||
74 | 121 | if self.venue: | ||
75 | 122 | self.date_begin = self.venue.fromlocaltime(local_begin) | ||
76 | 123 | else: | ||
77 | 124 | self.date_begin = local_begin | ||
78 | 125 | local_date_begin = property(get_local_begin) | ||
79 | 126 | |||
80 | 127 | def get_local_end(self): | ||
81 | 128 | if self.venue: | ||
82 | 129 | return self.venue.tolocaltime(self.date_end) | ||
83 | 130 | else: | ||
84 | 131 | return self.date_end | ||
85 | 132 | def set_local_end(self, local_end): | ||
86 | 133 | if self.venue: | ||
87 | 134 | self.date_end = self.venue.fromlocaltime(local_end) | ||
88 | 135 | else: | ||
89 | 136 | self.date_end = local_end | ||
90 | 137 | local_date_end = property(get_local_end, set_local_end) | ||
91 | 138 | |||
92 | 117 | @models.permalink | 139 | @models.permalink |
93 | 118 | def get_absolute_url(self): | 140 | def get_absolute_url(self): |
94 | 119 | return ('team-event-detail', [str(self.id)]) | 141 | return ('team-event-detail', [str(self.id)]) |
95 | @@ -148,6 +170,18 @@ | |||
96 | 148 | commenter_profile = models.ForeignKey(UserProfile, null=True) | 170 | commenter_profile = models.ForeignKey(UserProfile, null=True) |
97 | 149 | comment = models.TextField(help_text=_('Comment this Event'), db_index=True) | 171 | comment = models.TextField(help_text=_('Comment this Event'), db_index=True) |
98 | 150 | 172 | ||
99 | 173 | def get_local_created(self): | ||
100 | 174 | if self.team_event.venue: | ||
101 | 175 | return self.team_event.venue.tolocaltime(self.date_created) | ||
102 | 176 | else: | ||
103 | 177 | return self.date_created | ||
104 | 178 | def set_local_created(self, local_created): | ||
105 | 179 | if self.team_event.venue: | ||
106 | 180 | self.date_created = self.team_event.venue.fromlocaltime(local_created) | ||
107 | 181 | else: | ||
108 | 182 | self.date_created = local_created | ||
109 | 183 | local_date_created = property(get_local_created, set_local_created) | ||
110 | 184 | |||
111 | 151 | def __unicode__(self): | 185 | def __unicode__(self): |
112 | 152 | return "Team Event: %s . Comment: %s" % (self.team_event.name, self.comment) | 186 | return "Team Event: %s . Comment: %s" % (self.team_event.name, self.comment) |
113 | 153 | 187 | ||
114 | 154 | 188 | ||
115 | === modified file 'loco_directory/templates/events/global_event_detail_basic.inc.html' | |||
116 | --- loco_directory/templates/events/global_event_detail_basic.inc.html 2010-09-09 19:39:40 +0000 | |||
117 | +++ loco_directory/templates/events/global_event_detail_basic.inc.html 2010-11-19 13:47:33 +0000 | |||
118 | @@ -6,9 +6,9 @@ | |||
119 | 6 | <th class="form-item-label" scope="row"><label>{% trans "When:" %}</label></th> | 6 | <th class="form-item-label" scope="row"><label>{% trans "When:" %}</label></th> |
120 | 7 | <td class="form-item-value"> | 7 | <td class="form-item-value"> |
121 | 8 | {% ifequal global_event_object.date_begin|date global_event_object.date_end|date %} | 8 | {% ifequal global_event_object.date_begin|date global_event_object.date_end|date %} |
123 | 9 | {{ global_event_object.date_begin|date:"D, d N Y H:i" }} - {{ global_event_object.date_end|date:"H:i O" }} | 9 | {{ global_event_object.date_begin|date:"D, d N Y H:i" }} - {{ global_event_object.date_end|date:"H:i T"}} |
124 | 10 | {% else %} | 10 | {% else %} |
126 | 11 | {{ global_event_object.date_begin|date:"D, d N Y H:i" }} - {{ global_event_object.date_end|date:"D, d N Y H:i O" }} | 11 | {{ global_event_object.date_begin|date:"D, d N Y H:i" }} - {{ global_event_object.date_end|date:"D, d N Y H:i T"}} |
127 | 12 | {% endifequal %} | 12 | {% endifequal %} |
128 | 13 | </td> | 13 | </td> |
129 | 14 | </tr> | 14 | </tr> |
130 | 15 | 15 | ||
131 | === modified file 'loco_directory/templates/events/team_event_detail_basic.inc.html' | |||
132 | --- loco_directory/templates/events/team_event_detail_basic.inc.html 2010-08-17 08:48:39 +0000 | |||
133 | +++ loco_directory/templates/events/team_event_detail_basic.inc.html 2010-11-19 13:47:33 +0000 | |||
134 | @@ -5,10 +5,10 @@ | |||
135 | 5 | <tr> | 5 | <tr> |
136 | 6 | <th class="form-item-label" scope="row"><label>{% trans "When:" %}</label></th> | 6 | <th class="form-item-label" scope="row"><label>{% trans "When:" %}</label></th> |
137 | 7 | <td class="form-item-value"> | 7 | <td class="form-item-value"> |
140 | 8 | {% ifequal team_event_object.date_begin|date team_event_object.date_end|date %} | 8 | {% ifequal team_event_object.local_date_begin|date team_event_object.local_date_end|date %} |
141 | 9 | {{ team_event_object.date_begin|date:"D, d N Y H:i" }} - {{ team_event_object.date_end|date:"H:i O" }} | 9 | {{ team_event_object.local_date_begin|date:"D, d N Y H:i" }} - {{ team_event_object.local_date_end|date:"H:i T (O)" }} |
142 | 10 | {% else %} | 10 | {% else %} |
144 | 11 | {{ team_event_object.date_begin|date:"D, d N Y H:i" }} - {{ team_event_object.date_end|date:"D, d N Y H:i O" }} | 11 | {{ team_event_object.local_date_begin|date:"D, d N Y H:i" }} - {{ team_event_object.local_date_end|date:"D, d N Y H:i T (O)" }} |
145 | 12 | {% endifequal %} | 12 | {% endifequal %} |
146 | 13 | </td> | 13 | </td> |
147 | 14 | </tr> | 14 | </tr> |
148 | 15 | 15 | ||
149 | === modified file 'loco_directory/templates/events/team_event_detail_comments.inc.html' | |||
150 | --- loco_directory/templates/events/team_event_detail_comments.inc.html 2010-11-12 11:26:24 +0000 | |||
151 | +++ loco_directory/templates/events/team_event_detail_comments.inc.html 2010-11-19 13:47:33 +0000 | |||
152 | @@ -6,7 +6,7 @@ | |||
153 | 6 | <a href="{% url team-event-comment-new team_event_object.id %}#comment">{% trans "Add Comment" %}</a> | 6 | <a href="{% url team-event-comment-new team_event_object.id %}#comment">{% trans "Add Comment" %}</a> |
154 | 7 | </td> | 7 | </td> |
155 | 8 | </tr> | 8 | </tr> |
157 | 9 | {% regroup team_event_object.teameventcomment_set.all by date_created|date:"D d M Y" as comment_list %} | 9 | {% regroup team_event_object.teameventcomment_set.all by local_date_created|date:"D d M Y" as comment_list %} |
158 | 10 | 10 | ||
159 | 11 | {% for comment_date in comment_list %} | 11 | {% for comment_date in comment_list %} |
160 | 12 | <tr> | 12 | <tr> |
161 | 13 | 13 | ||
162 | === modified file 'loco_directory/templates/events/team_event_list.inc.html' | |||
163 | --- loco_directory/templates/events/team_event_list.inc.html 2010-08-17 00:25:27 +0000 | |||
164 | +++ loco_directory/templates/events/team_event_list.inc.html 2010-11-19 13:47:33 +0000 | |||
165 | @@ -10,8 +10,8 @@ | |||
166 | 10 | {% for team_event in team_event_list %} | 10 | {% for team_event in team_event_list %} |
167 | 11 | <tr class="team_event_list_row {% cycle "odd" "even" %}"> | 11 | <tr class="team_event_list_row {% cycle "odd" "even" %}"> |
168 | 12 | <td class="event_name"><a title="{% trans "more information about this event" %}" href="{{ team_event.get_absolute_url }}">{{ team_event.name }}</a></td> | 12 | <td class="event_name"><a title="{% trans "more information about this event" %}" href="{{ team_event.get_absolute_url }}">{{ team_event.name }}</a></td> |
171 | 13 | <td class="event_begin">{{team_event.date_begin|date}} {{ team_event.date_begin|date:"H:i T"}}</td> | 13 | <td class="event_begin">{{team_event.local_date_begin|date}} {{ team_event.local_date_begin|date:"H:i T"}}</td> |
172 | 14 | <td class="event_end">{{team_event.date_end|date}} {{ team_event.date_end|date:"H:i T"}}</td> | 14 | <td class="event_end">{{team_event.local_date_end|date}} {{ team_event.local_date_end|date:"H:i T"}}</td> |
173 | 15 | <td class="event_global">{% if team_event.global_event %}<a href="{{ team_event.global_event.get_absolute_url }}">{{ team_event.global_event.name}}</a>{% else %}--{% endif %}</td> | 15 | <td class="event_global">{% if team_event.global_event %}<a href="{{ team_event.global_event.get_absolute_url }}">{{ team_event.global_event.name}}</a>{% else %}--{% endif %}</td> |
174 | 16 | <td class="event_teams">{% for team in team_event.teams.all %}<a title="{% trans "more information about this team" %}" href="{{ team.get_absolute_url }}">{{ team.name }}</a>{% if not forloop.last %}<br/>{% endif %}{% endfor %}</td> | 16 | <td class="event_teams">{% for team in team_event.teams.all %}<a title="{% trans "more information about this team" %}" href="{{ team.get_absolute_url }}">{{ team.name }}</a>{% if not forloop.last %}<br/>{% endif %}{% endfor %}</td> |
175 | 17 | </tr> | 17 | </tr> |
176 | 18 | 18 | ||
177 | === modified file 'loco_directory/templates/venues/venue_detail_basic.inc.html' | |||
178 | --- loco_directory/templates/venues/venue_detail_basic.inc.html 2010-08-19 23:02:12 +0000 | |||
179 | +++ loco_directory/templates/venues/venue_detail_basic.inc.html 2010-11-19 13:47:33 +0000 | |||
180 | @@ -25,6 +25,12 @@ | |||
181 | 25 | <td class="form-item-value">{{ venue_object.country }}</td> | 25 | <td class="form-item-value">{{ venue_object.country }}</td> |
182 | 26 | </tr> | 26 | </tr> |
183 | 27 | {% endif %} | 27 | {% endif %} |
184 | 28 | {% if venue_object.tz %} | ||
185 | 29 | <tr> | ||
186 | 30 | <th class="form-item-label" scope="row"><label>{% trans "Timezone:" %}</label></th> | ||
187 | 31 | <td class="form-item-value">{{ venue_object.tz }}</td> | ||
188 | 32 | </tr> | ||
189 | 33 | {% endif %} | ||
190 | 28 | {% if venue_object.venue_url %} | 34 | {% if venue_object.venue_url %} |
191 | 29 | <tr> | 35 | <tr> |
192 | 30 | <th class="form-item-label" scope="row"><label>{% trans "Homepage:" %}</label></th> | 36 | <th class="form-item-label" scope="row"><label>{% trans "Homepage:" %}</label></th> |
193 | 31 | 37 | ||
194 | === modified file 'loco_directory/userprofiles/models.py' | |||
195 | --- loco_directory/userprofiles/models.py 2010-08-28 17:43:41 +0000 | |||
196 | +++ loco_directory/userprofiles/models.py 2010-11-19 13:47:33 +0000 | |||
197 | @@ -3,6 +3,8 @@ | |||
198 | 3 | from django.contrib.auth import models as auth_models | 3 | from django.contrib.auth import models as auth_models |
199 | 4 | # Create your models here. | 4 | # Create your models here. |
200 | 5 | 5 | ||
201 | 6 | import pytz | ||
202 | 7 | |||
203 | 6 | class UserProfile(models.Model): | 8 | class UserProfile(models.Model): |
204 | 7 | " Store profile information about a user " | 9 | " Store profile information about a user " |
205 | 8 | 10 | ||
206 | @@ -27,6 +29,21 @@ | |||
207 | 27 | return "%s" % self.user.username | 29 | return "%s" % self.user.username |
208 | 28 | except: | 30 | except: |
209 | 29 | return "Unknown Profile" | 31 | return "Unknown Profile" |
210 | 32 | |||
211 | 33 | def get_timezone(self): | ||
212 | 34 | try: | ||
213 | 35 | return pytz.timezone(self.tz) | ||
214 | 36 | except: | ||
215 | 37 | return pytz.utc | ||
216 | 38 | timezone = property(get_timezone) | ||
217 | 39 | |||
218 | 40 | def tolocaltime(self, dt): | ||
219 | 41 | as_utc = pytz.utc.localize(dt) | ||
220 | 42 | return as_utc.astimezone(self.timezone) | ||
221 | 43 | |||
222 | 44 | def fromlocaltime(self, dt): | ||
223 | 45 | local = self.timezone.localize(dt) | ||
224 | 46 | return local.astimezone(pytz.utc) | ||
225 | 30 | 47 | ||
226 | 31 | def _getUserProfile(self): | 48 | def _getUserProfile(self): |
227 | 32 | if not self.is_authenticated(): | 49 | if not self.is_authenticated(): |
228 | 33 | 50 | ||
229 | === added file 'loco_directory/venues/migrations/0005_add_venue_timezone.py' | |||
230 | --- loco_directory/venues/migrations/0005_add_venue_timezone.py 1970-01-01 00:00:00 +0000 | |||
231 | +++ loco_directory/venues/migrations/0005_add_venue_timezone.py 2010-11-19 13:47:33 +0000 | |||
232 | @@ -0,0 +1,47 @@ | |||
233 | 1 | |||
234 | 2 | from south.db import db | ||
235 | 3 | from django.db import models | ||
236 | 4 | from venues.models import * | ||
237 | 5 | |||
238 | 6 | class Migration: | ||
239 | 7 | |||
240 | 8 | def forwards(self, orm): | ||
241 | 9 | |||
242 | 10 | # Adding field 'Venue.tz' | ||
243 | 11 | db.add_column('venues_venue', 'tz', orm['venues.venue:tz']) | ||
244 | 12 | |||
245 | 13 | |||
246 | 14 | |||
247 | 15 | def backwards(self, orm): | ||
248 | 16 | |||
249 | 17 | # Deleting field 'Venue.tz' | ||
250 | 18 | db.delete_column('venues_venue', 'tz') | ||
251 | 19 | |||
252 | 20 | |||
253 | 21 | |||
254 | 22 | models = { | ||
255 | 23 | 'teams.continent': { | ||
256 | 24 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
257 | 25 | 'name': ('django.db.models.fields.TextField', [], {'max_length': '50'}) | ||
258 | 26 | }, | ||
259 | 27 | 'teams.country': { | ||
260 | 28 | 'continents': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['teams.Continent']", 'symmetrical': 'False'}), | ||
261 | 29 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
262 | 30 | 'name': ('django.db.models.fields.TextField', [], {'max_length': '100'}) | ||
263 | 31 | }, | ||
264 | 32 | 'venues.venue': { | ||
265 | 33 | 'Meta': {'unique_together': "(('name', 'country', 'city'), ('longitude', 'latitude'))"}, | ||
266 | 34 | 'address': ('django.db.models.fields.CharField', [], {'max_length': '150', 'null': 'True', 'blank': 'True'}), | ||
267 | 35 | 'city': ('django.db.models.fields.CharField', [], {'max_length': '150', 'null': 'True', 'blank': 'True'}), | ||
268 | 36 | 'comment': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), | ||
269 | 37 | 'country': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['teams.Country']", 'null': 'True'}), | ||
270 | 38 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
271 | 39 | 'latitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), | ||
272 | 40 | 'longitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), | ||
273 | 41 | 'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}), | ||
274 | 42 | 'tz': ('django.db.models.fields.CharField', [], {'default': "'UTC'", 'max_length': '32'}), | ||
275 | 43 | 'venue_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}) | ||
276 | 44 | } | ||
277 | 45 | } | ||
278 | 46 | |||
279 | 47 | complete_apps = ['venues'] | ||
280 | 0 | 48 | ||
281 | === modified file 'loco_directory/venues/models.py' | |||
282 | --- loco_directory/venues/models.py 2010-07-29 13:54:09 +0000 | |||
283 | +++ loco_directory/venues/models.py 2010-11-19 13:47:33 +0000 | |||
284 | @@ -3,6 +3,8 @@ | |||
285 | 3 | from django.db.models import permalink | 3 | from django.db.models import permalink |
286 | 4 | 4 | ||
287 | 5 | from teams.models import Country | 5 | from teams.models import Country |
288 | 6 | import pytz | ||
289 | 7 | |||
290 | 6 | 8 | ||
291 | 7 | class VenueManager(models.Manager): | 9 | class VenueManager(models.Manager): |
292 | 8 | """ | 10 | """ |
293 | @@ -20,6 +22,7 @@ | |||
294 | 20 | address = models.CharField(help_text=_('Address with Street and Number'), max_length=150, null=True, blank=True) | 22 | address = models.CharField(help_text=_('Address with Street and Number'), max_length=150, null=True, blank=True) |
295 | 21 | longitude = models.FloatField(help_text=_('Longitude in Degrees East'), null=True, blank=True) | 23 | longitude = models.FloatField(help_text=_('Longitude in Degrees East'), null=True, blank=True) |
296 | 22 | latitude = models.FloatField(help_text=_('Latitude in Degrees North'), null=True, blank=True) | 24 | latitude = models.FloatField(help_text=_('Latitude in Degrees North'), null=True, blank=True) |
297 | 25 | tz = models.CharField(max_length=32, verbose_name=_('Timezone'), default='UTC', choices=[(tz, tz) for tz in pytz.all_timezones], blank=False, null=False) | ||
298 | 23 | venue_url = models.URLField(help_text=_('URL for the Venue Homepage'), verbose_name=_('URL of the Venue'), max_length=200, verify_exists=False, blank=True, null=True) | 26 | venue_url = models.URLField(help_text=_('URL for the Venue Homepage'), verbose_name=_('URL of the Venue'), max_length=200, verify_exists=False, blank=True, null=True) |
299 | 24 | comment = models.TextField(help_text=_('Comment about the Venue'), blank=True, null=True) | 27 | comment = models.TextField(help_text=_('Comment about the Venue'), blank=True, null=True) |
300 | 25 | 28 | ||
301 | @@ -40,5 +43,37 @@ | |||
302 | 40 | """ get the absolute url for the venue """ | 43 | """ get the absolute url for the venue """ |
303 | 41 | return ('venue-detail', [self.id]) | 44 | return ('venue-detail', [self.id]) |
304 | 42 | 45 | ||
305 | 46 | def get_timezone(self): | ||
306 | 47 | try: | ||
307 | 48 | return pytz.timezone(self.tz) | ||
308 | 49 | except: | ||
309 | 50 | return pytz.utc | ||
310 | 51 | timezone = property(get_timezone) | ||
311 | 52 | |||
312 | 53 | def tolocaltime(self, dt): | ||
313 | 54 | as_utc = pytz.utc.localize(dt) | ||
314 | 55 | return as_utc.astimezone(self.timezone) | ||
315 | 56 | |||
316 | 57 | def fromlocaltime(self, dt): | ||
317 | 58 | local = self.timezone.localize(dt) | ||
318 | 59 | return local.astimezone(pytz.utc) | ||
319 | 60 | |||
320 | 61 | def save(self, *args, **kargs): | ||
321 | 62 | if self.id: | ||
322 | 63 | from events.models import TeamEvent | ||
323 | 64 | old = Venue.objects.get(id=self.id) | ||
324 | 65 | retval = super(Venue, self).save(*args, **kargs) | ||
325 | 66 | if old.tz != self.tz: | ||
326 | 67 | events = TeamEvent.objects.filter(venue=self) | ||
327 | 68 | for e in events: | ||
328 | 69 | old_offset = old.tolocaltime(e.date_begin).utcoffset() | ||
329 | 70 | new_offset = self.tolocaltime(e.date_begin).utcoffset() | ||
330 | 71 | e.date_begin = e.date_begin + (old_offset - new_offset) | ||
331 | 72 | e.date_end = e.date_end + (old_offset - new_offset) | ||
332 | 73 | e.save() | ||
333 | 74 | else: | ||
334 | 75 | retval = super(Venue, self).save(*args, **kargs) | ||
335 | 76 | return retval | ||
336 | 77 | |||
337 | 43 | def venues_without_country(): | 78 | def venues_without_country(): |
338 | 44 | return Venue.objects.filter(country__isnull=True) | 79 | return Venue.objects.filter(country__isnull=True) |
May need python-tz installed on the server before deploying