Commits

Frederic De Groef  committed db85254

some more error handling

  • Participants
  • Parent commits f800864
  • Tags v0.1.4.1

Comments (0)

Files changed (4)

File coursecalendar.py

 
         if is_course_mnemo_valid(course_mnemo):
             cal = get_calendar(course_mnemo)
-            ical_url, csv_url = self._build_file_urls(course_mnemo)
+            if cal:
+                ical_url, csv_url = self._build_file_urls(course_mnemo)
 
-            template_values = {'gehol_is_down': is_status_down(),
-                               'last_status_update': get_last_status_update(),
-                               'mnemo':course_mnemo,
-                               'ical_url':ical_url,
-                               'csv_url':csv_url
-            }
+                template_values = {'gehol_is_down': is_status_down(),
+                                 'last_status_update': get_last_status_update(),
+                                'mnemo':course_mnemo,
+                                'ical_url':ical_url,
+                                'csv_url':csv_url
+                }
 
-            template_values.update(cal.metadata)
+                template_values.update(cal.metadata)
 
-            path = os.path.join(os.path.dirname(__file__), 'templates/course.html')
-            self.response.out.write(template.render(path, template_values))
+                path = os.path.join(os.path.dirname(__file__), 'templates/course.html')
+                self.response.out.write(template.render(path, template_values))
 
-            request = PreviousRequest()
-            request.content = course_mnemo
-            request.put()
-
+                request = PreviousRequest()
+                request.content = course_mnemo
+                request.put()
+            else:
+                self._render_not_found_page(course_mnemo)
         else:
             self._render_not_found_page(course_mnemo)
-
+            
 
     def _render_not_found_page(self, course_mnemo):
         template_values = {'gehol_is_down': is_status_down(),

File csvrenderer.py

         if is_course_mnemo_valid(course_mnemo):
             cal = get_calendar(course_mnemo)
 
-            error,csv,ical = convert_calendar(cal)
-            events_csv = csv
+            if cal:
+                error,csv,ical = convert_calendar(cal)
+                events_csv = csv
 
-            self.response.headers['Content-Type'] = "text/csv;  charset=utf-8"
-            self.response.headers['Content-disposition'] = "attachment; filename=%s.csv" % course_mnemo
-            self.response.out.write(events_csv)
+                self.response.headers['Content-Type'] = "text/csv;  charset=utf-8"
+                self.response.headers['Content-disposition'] = "attachment; filename=%s.csv" % course_mnemo
+                self.response.out.write(events_csv)
+            else:
+                self._render_not_found_page(course_mnemo)
         else:
             self._render_not_found_page(course_mnemo)
 
+
             
     def _render_not_found_page(self, course_mnemo):
         template_values = {'gehol_is_down': is_status_down(),

File gehol2csv.py

 import sys
 sys.path.append('./dependencies')
-from gehol.coursecalendar import CourseCalendar
+from gehol.coursecalendar import CourseCalendar, GeholException
 from gehol.converters.csvwriter import to_csv
 from gehol.converters.icalwriter import to_ical
 from gehol import GeholProxy
     gehol_proxy = GeholProxy(host)
     try:
         return gehol_proxy.get_course_calendar(course_mnemonic)
-    except Exception:
+    except GeholException:
         return None
 
 

File icalrenderer.py

 
         if is_course_mnemo_valid(course_mnemo):
             cal = get_calendar(course_mnemo)
+            if cal:
+                error,csv,ical = convert_calendar(cal)
+                events_ical = ical
 
-            error,csv,ical = convert_calendar(cal)
-            events_ical = ical
-
-            self.response.headers['Content-Type'] = "text/calendar;  charset=utf-8"
-            self.response.headers['Content-disposition'] = "attachment; filename=%s.ics" % course_mnemo
-            self.response.out.write(events_ical)
+                self.response.headers['Content-Type'] = "text/calendar;  charset=utf-8"
+                self.response.headers['Content-disposition'] = "attachment; filename=%s.ics" % course_mnemo
+                self.response.out.write(events_ical)
+            else:
+                self._render_not_found_page(course_mnemo)
         else:
             self._render_not_found_page(course_mnemo)
 
 
+
     def _render_not_found_page(self, course_mnemo):
 
         template_values = {'gehol_is_down': is_status_down(),