From b7120aa8f36c9e050cc7c3a9e02b6a1558fc9321 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sat, 18 Apr 2015 23:12:57 +0100 Subject: [PATCH] Tidied up & added comments --- RIGS/ical.py | 24 +++++++++++++++++------- RIGS/urls.py | 4 ++-- RIGS/views.py | 1 - 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/RIGS/ical.py b/RIGS/ical.py index 728f8485..6f0c72f7 100644 --- a/RIGS/ical.py +++ b/RIGS/ical.py @@ -8,21 +8,23 @@ class CalendarICS(ICalFeed): """ A simple event calender """ + #Metadata which is passed on to clients product_id = 'PyRIGS' title = 'PyRIGS Calendar' timezone = 'UTC' file_name = "rigs.ics" def items(self): - #get events for today +- 1 year - start = datetime.datetime.now() - datetime.timedelta(days=31*3) - end = datetime.date.today() + datetime.timedelta(days=31*3) + #include events from up to 1 year ago + start = datetime.datetime.now() - datetime.timedelta(days=365) filter = Q(start_date__gte=start) - return models.Event.objects.filter(filter).select_related('person', 'organisation', 'venue', 'mic').order_by('-start_date') + return models.Event.objects.filter(filter).order_by('-start_date').select_related('person', 'organisation', 'venue', 'mic') def item_title(self, item): title = '' + + # Prefix title with status (if it's a critical status) if item.cancelled: title += 'CANCELLED: ' @@ -32,8 +34,10 @@ class CalendarICS(ICalFeed): if item.dry_hire: title += 'DRY HIRE: ' + # Add the rig name title += item.name + # Add the status title += ' ('+str(item.get_status_display())+')' return title @@ -52,8 +56,10 @@ class CalendarICS(ICalFeed): return startDateTime def item_end_datetime(self, item): + # Assume end is same as start endDateTime = item.start_date + # If end date defined then use it if item.end_date: endDateTime = item.end_date @@ -70,6 +76,9 @@ class CalendarICS(ICalFeed): return item.venue def item_description(self, item): + # Create a nice information-rich description + # note: only making use of information available to "non-keyholders" + desc = 'Rig ID = '+str(item.pk)+'\n' desc += 'Event = ' + item.name + '\n' desc += 'Venue = ' + (item.venue.name if item.venue else '---') + '\n' @@ -99,13 +108,14 @@ class CalendarICS(ICalFeed): return desc def item_link(self, item): + # Make a link to the event in the web interface return '/event/'+str(item.pk)+'/' - # def item_created(self, item): #TODO - Implement created date-time (using django-reversion?) + # def item_created(self, item): #TODO - Implement created date-time (using django-reversion?) - not really necessary though # return '' - def item_updated(self, item): + def item_updated(self, item): # some ical clients will display this return item.last_edited_at - def item_guid(self, item): + 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/urls.py b/RIGS/urls.py index f25dbfa6..12cc015d 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -114,8 +114,8 @@ urlpatterns = patterns('', url(r'^user/edit/$', login_required(views.ProfileUpdateSelf.as_view()), name='profile_update_self'), - # ICS Calendar - url(r'^calendar/rigs.ics$', (ical.CalendarICS()), name="ics_calendar"), + # ICS Calendar - no authentication! + url(r'^ical/rigs.ics$', (ical.CalendarICS()), name="ics_calendar"), # API url(r'^api/(?P\w+)/$', (views.SecureAPIRequest.as_view()), name="api_secure"), diff --git a/RIGS/views.py b/RIGS/views.py index e1f78979..57feffaa 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -8,7 +8,6 @@ from django.shortcuts import get_object_or_404 from django.core import serializers import simplejson from django.contrib import messages -import datetime from RIGS import models, forms