Permalink
Browse files

Merge branch 'master' of github.com:ezl/hnofficehours

  • Loading branch information...
2 parents 760377f + 74164c0 commit fd27963f5d40096e0a355fcebc59f03ce041c79f E committed Aug 9, 2010
Showing with 41 additions and 10 deletions.
  1. +22 −1 apps/officehours/forms.py
  2. +2 −1 apps/officehours/views.py
  3. +1 −1 templates/schedule/create_event.html
  4. +16 −7 templates/schedule/event.html
View
@@ -4,6 +4,7 @@
from django.utils.translation import ugettext_lazy as _
from schedule.forms import *
from schedule.models import Event
+from timezones import utils as tz_utils
# If we ever go international, FIRST_DAY_OF_WEEK needs to be a user setting.
@@ -26,8 +27,28 @@ class Meta:
fields = ('start', 'end', 'repeats', 'end_recurring_period',
'repeats_on',)
- def __init__(self, hour24=False, *args, **kwargs):
+ def __init__(self, creator, hour24=False, *args, **kwargs):
+ self.creator = creator
super(EventForm, self).__init__(*args, **kwargs)
+
+ def coerce_datetime_tz(self, datetime):
+ server_tz = settings.TIME_ZONE
+ if self.instance is None or self.instance.creator is None:
+ user_tz = self.creator.get_profile().timezone
+ else:
+ user_tz = self.instance.creator.get_profile().timezone
+ return tz_utils.adjust_datetime_to_timezone(datetime, user_tz, server_tz)
+
+ def clean_start(self):
+ # user was instructed to give us times in his time zone, so we
+ # need to convert them to the server's.
+ return self.coerce_datetime_tz(self.cleaned_data['start'])
+
+ def clean_end(self):
+ # user was instructed to give us times in his time zone, so we
+ # need to convert them to the server's.
+ return self.coerce_datetime_tz(self.cleaned_data['end'])
+
def clean(self):
if self.cleaned_data.get('repeats', False):
@@ -16,6 +16,7 @@
@check_event_permissions
+@login_required
def create_or_edit_event(request, calendar_slug, event_id=None, next=None,
template_name='schedule/create_event.html', form_class = EventForm):
"""
@@ -70,7 +71,7 @@ def create_or_edit_event(request, calendar_slug, event_id=None, next=None,
calendar = get_object_or_404(Calendar, slug=calendar_slug)
form = form_class(data=request.POST or None, instance=instance,
- hour24=True, initial=initial_data)
+ hour24=True, creator=request.user, initial=initial_data)
if form.is_valid():
event = form.save(commit=False)
@@ -6,7 +6,7 @@
{% block body %}
<form action="" method="post"> {% csrf_token %}
<div class="pretty">
-<p class="help">{% trans "Create or change event. All fields are required." %}</p>
+<p class="help">{% trans "Create or change event. Enter all times local to your timezone." %}</p>
@@ -1,7 +1,7 @@
{% extends "schedule/base.html" %}
{% load i18n %}
{% load scheduletags %} {% load officehourstags %}
-
+{% load timezone_filters %}
{% block body %}
<div class="navigation pretty">
<h2>View</h2>
@@ -29,12 +29,21 @@ <h2 align="center">{{event.title}}</h2>
</thead>
<tbody>
<tr>
- <td>Starts</td>
- <td>{% blocktrans with event.start|date:_("DATETIME_FORMAT") as start_date %}{{ start_date }}{% endblocktrans %}</td>
- </tr>
- <tr>
- <td>Ends</td>
- <td>{% blocktrans with event.end|date:_("DATETIME_FORMAT") as end_date %}{{ end_date }}{% endblocktrans %}</td>
+ {% if request.user.is_authenticated %}
+ <td>Starts</td>
+ <td>{% blocktrans with event.start|localtime:request.user.get_profile.timezone|date:_("DATETIME_FORMAT") as start_date %}{{ start_date }}{% endblocktrans %}</td>
+ </tr>
+ <tr>
+ <td>Ends</td>
+ <td>{% blocktrans with event.end|localtime:request.user.get_profile.timezone|date:_("DATETIME_FORMAT") as end_date %}{{ end_date }}{% endblocktrans %}</td>
+ {% else %}
+ <td>Starts</td>
+ <td>{% blocktrans with event.start|date:_("DATETIME_FORMAT") as start_date %}{{ start_date }}{% endblocktrans %} (US Central Time)</td>
+ </tr>
+ <tr>
+ <td>Ends</td>
+ <td>{% blocktrans with event.end|date:_("DATETIME_FORMAT") as end_date %}{{ end_date }}{% endblocktrans %} (US Central Time)</td>
+ {% endif %}
</tr>
<tr>
<td>Reoccurs</td>

0 comments on commit fd27963

Please sign in to comment.