diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index ed423717..9b8c0546 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -174,7 +174,7 @@ else: LANGUAGE_CODE = 'en-gb' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Europe/London' FORMAT_MODULE_PATH = 'PyRIGS.formats' diff --git a/RIGS/ical.py b/RIGS/ical.py index b7ecbee4..20434c12 100644 --- a/RIGS/ical.py +++ b/RIGS/ical.py @@ -2,18 +2,26 @@ from RIGS import models, forms from django_ical.views import ICalFeed from django.db.models import Q 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): """ A simple event calender """ #Metadata which is passed on to clients - product_id = 'PyRIGS' - title = 'PyRIGS Calendar' + product_id = 'RIGS' + title = 'RIGS Calendar' + timezone = settings.TIME_ZONE file_name = "rigs.ics" + def get(self, *args, **kwargs): + timezone.activate(timezone.UTC) + return super(CalendarICS, self).get(*args, **kwargs) + + def items(self): #include events from up to 1 year ago start = datetime.datetime.now() - datetime.timedelta(days=365) @@ -45,11 +53,13 @@ class CalendarICS(ICalFeed): def item_start_datetime(self, item): #set start date to the earliest defined time for the event if item.meet_at: - startDateTime = item.meet_at.replace(tzinfo=None) + startDateTime = item.meet_at elif item.access_at: - startDateTime = item.access_at.replace(tzinfo=None) + startDateTime = item.access_at elif item.has_start_time: - startDateTime = datetime.datetime.combine(item.start_date,item.start_time).replace(tzinfo=None) + 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: startDateTime = item.start_date @@ -64,9 +74,11 @@ class CalendarICS(ICalFeed): endDateTime = item.end_date 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).replace(tzinfo=None) + 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 - endDateTime = datetime.datetime.combine(endDateTime+datetime.timedelta(days=1),datetime.time(00, 00)).replace(tzinfo=None) + 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 # do nothing @@ -90,7 +102,7 @@ class CalendarICS(ICalFeed): desc += '\n' if item.meet_at: - desc += 'Crew Meet = ' + item.meet_at.strftime('%Y-%m-%d %H:%M') + (('('+item.meet_info+')') if item.meet_info else '---') + '\n' + desc += 'Crew Meet = ' + (item.meet_at.strftime('%Y-%m-%d %H:%M') if item.meet_at else '---') + '\n' if item.access_at: desc += 'Access At = ' + item.access_at.strftime('%Y-%m-%d %H:%M') + '\n' if item.start_date: @@ -104,7 +116,7 @@ class CalendarICS(ICalFeed): if item.notes: desc += 'Notes:\n'+item.notes+'\n\n' - base_url = "https://pyrigs.nottinghamtec.co.uk" + base_url = "http://rigs.nottinghamtec.co.uk" desc += 'URL = '+base_url+str(item.get_absolute_url()) return desc @@ -118,7 +130,7 @@ class CalendarICS(ICalFeed): # return '' def item_updated(self, item): # some ical clients will display this - return item.last_edited_at.replace(tzinfo=None) + return item.last_edited_at def item_guid(self, item): # use the rig-id as the ical unique event identifier return item.pk \ No newline at end of file diff --git a/RIGS/templates/RIGS/event_table.html b/RIGS/templates/RIGS/event_table.html index 3cd5144f..49e4ec6f 100644 --- a/RIGS/templates/RIGS/event_table.html +++ b/RIGS/templates/RIGS/event_table.html @@ -80,12 +80,12 @@ {% endif %} - {% if event.mic or not event.is_rig %} + {% if event.mic %} {{ event.mic.initials }}
- {% else %} + {% elif event.is_rig %} {% endif %}