Re-enable timezones and add iCal converstion to UTC.

This should work on Google Cal but won't be able to test till in production.
This commit is contained in:
Tom Price
2015-05-18 23:41:17 +01:00
parent a0a30b73e4
commit ff4dd46c87
2 changed files with 16 additions and 5 deletions

View File

@@ -180,7 +180,7 @@ USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = False USE_TZ = True
DATETIME_INPUT_FORMATS = ('%Y-%m-%dT%H:%M','%Y-%m-%dT%H:%M:%S') DATETIME_INPUT_FORMATS = ('%Y-%m-%dT%H:%M','%Y-%m-%dT%H:%M:%S')

View File

@@ -2,19 +2,26 @@ from RIGS import models, forms
from django_ical.views import ICalFeed from django_ical.views import ICalFeed
from django.db.models import Q from django.db.models import Q
from django.core.urlresolvers import reverse_lazy, reverse, NoReverseMatch from django.core.urlresolvers import reverse_lazy, reverse, NoReverseMatch
from django.utils import timezone
from django.conf import settings
import datetime import datetime, pytz
class CalendarICS(ICalFeed): class CalendarICS(ICalFeed):
""" """
A simple event calender A simple event calender
""" """
#Metadata which is passed on to clients #Metadata which is passed on to clients
product_id = 'PyRIGS' product_id = 'RIGS'
title = 'PyRIGS Calendar' title = 'RIGS Calendar'
timezone = 'Europe/London' timezone = 'UTC'
file_name = "rigs.ics" file_name = "rigs.ics"
def get(self, *args, **kwargs):
timezone.activate(timezone.UTC)
return super(CalendarICS, self).get(*args, **kwargs)
def items(self): def items(self):
#include events from up to 1 year ago #include events from up to 1 year ago
start = datetime.datetime.now() - datetime.timedelta(days=365) start = datetime.datetime.now() - datetime.timedelta(days=365)
@@ -51,6 +58,8 @@ class CalendarICS(ICalFeed):
startDateTime = item.access_at startDateTime = item.access_at
elif item.has_start_time: elif item.has_start_time:
startDateTime = datetime.datetime.combine(item.start_date,item.start_time) startDateTime = datetime.datetime.combine(item.start_date,item.start_time)
tz = pytz.timezone(settings.TIME_ZONE)
startDateTime = tz.normalize(tz.localize(startDateTime)).astimezone(pytz.timezone(self.timezone))
else: else:
startDateTime = item.start_date startDateTime = item.start_date
@@ -66,6 +75,8 @@ class CalendarICS(ICalFeed):
if item.has_start_time and item.has_end_time: # don't allow an event with specific end but no specific start if item.has_start_time and item.has_end_time: # don't allow an event with specific end but no specific start
endDateTime = datetime.datetime.combine(endDateTime,item.end_time) endDateTime = datetime.datetime.combine(endDateTime,item.end_time)
tz = pytz.timezone(settings.TIME_ZONE)
endDateTime = tz.normalize(tz.localize(endDateTime)).astimezone(pytz.timezone(self.timezone))
elif item.has_end_time: # if there's a start time specified then an end time should also be specified elif item.has_end_time: # if there's a start time specified then an end time should also be specified
endDateTime = datetime.datetime.combine(endDateTime+datetime.timedelta(days=1),datetime.time(00, 00)) endDateTime = datetime.datetime.combine(endDateTime+datetime.timedelta(days=1),datetime.time(00, 00))
#elif item.end_time: # end time but no start time - this is weird - don't think ICS will like it so ignoring #elif item.end_time: # end time but no start time - this is weird - don't think ICS will like it so ignoring