Repository: fossasia/open-event-server

Issue:
Standardize ical export
In reference to #106, the ical export method should try to use standard fields (see iCalendar specification below) for compatibility with existing calendar services. 
Example - Fields like 'start time' and 'end time' are non-standard and 'dtstart' and 'dtend' should be used in their place.

Some helpful links 
- [Google Calendar ICS export](https://support.google.com/calendar/answer/37118?hl=en)
- [Wikipedia iCalendar](https://en.wikipedia.org/wiki/ICalendar)
- [iCalendar specification](https://tools.ietf.org/html/rfc5545#section-3.8.1.7)

[BUG] Inconsistent data returned by api/export/iCal
**Issue**
The data returned by `api/../export/iCal` for a track or an event is wrong at times. Actually duplicate events are added to the returned data.

**Steps to reproduce**
- Open a `api/export/iCal` page in the browser . For example http://open-event.herokuapp.com/api/v1/track/5/export/iCal
- Continuously refresh it with F5. 
- You will notice that the returned data changes at times.



Discussion:

Resolving patch:
diff --git a/open_event/views/views.py b/open_event/views/views.py
--- a/open_event/views/views.py
+++ b/open_event/views/views.py
@@ -17,7 +17,6 @@
 import icalendar
 
 auto=Autodoc()
-cal=Calendar()
 
 app = Blueprint('', __name__)
 @app.route('/', methods=['GET'])
@@ -244,21 +243,21 @@ def get_speakers_at_event(event_id, speaker_name):
 @auto.doc()
 @cross_origin()
 def generate_icalender_event(event_id):
-	"""Takes an event id and returns the event in iCal format"""		
+	"""Takes an event id and returns the event in iCal format"""
+	cal=Calendar()
 	event=icalendar.Event()
 	matching_event=Event.query.get(event_id)
 	if matching_event == None:
 		return "Sorry,the event does not exist"
-	event.add('name',matching_event.name)
-	event.add('latitude',matching_event.latitude)
-	event.add('longitude',matching_event.longitude)
+	event.add('summary',matching_event.name)
+	event.add('geo',(matching_event.latitude, matching_event.longitude))
 	event.add('location',matching_event.location_name)
-	event.add('color',matching_event.color)	
-	event.add('start time',matching_event.start_time)
-	event.add('end time',matching_event.end_time)	
+	event.add('color',matching_event.color)
+	event.add('dtstart',matching_event.start_time)
+	event.add('dtend',matching_event.end_time)	
 	event.add('logo',matching_event.logo)
 	event.add('email',matching_event.email)
-	event.add('slogan',matching_event.slogan)
+	event.add('description',matching_event.slogan)
 	event.add('url',matching_event.url)
 	cal.add_component(event)
 	return cal.to_ical()
@@ -267,14 +266,15 @@ def generate_icalender_event(event_id):
 @auto.doc()
 @cross_origin()
 def generate_icalender_track(track_id):
-	"""Takes a track id and returns the track in iCal format"""		
+	"""Takes a track id and returns the track in iCal format"""
+	cal=Calendar()
 	track=icalendar.Event()
 	matching_track=Track.query.get(track_id)	
 	if matching_track==None:
 		return "Sorry,the track does not exist"	
-	track.add('name',matching_track.name)	
+	track.add('summary',matching_track.name)	
 	track.add('description',matching_track.description)
-	track.add('image url',matching_track.track_image_url)
+	track.add('url',matching_track.track_image_url)
 	cal.add_component(track)
 	return cal.to_ical()
 


Test patch: