def get(self): if is_status_down(): render_gehol_down(self, "You asked an iCalendar file for a particular professor.") else: parsed = urlparse.urlparse(self.request.uri) staff_member_id = parsed.path.split("/")[4].rstrip(".ics") term = parsed.path.split("/")[3] logging.info("------") if term in ("q1", "q2", "january_exams", "june_exams", "september_exams"): try: logging.info("*** rendering staff/" + term) cal = self.calendar_fetch_funcs[term](staff_member_id) except DownloadError, e: logging.error("Could not fetch page before deadline") render_deadline_exceeded_page(self) cal = None if cal: ical_data = convert_professor_calendar_to_ical_string(cal) professor_name = cal.header_data["teacher_name"] ical_filename = "ULB - " + term.upper() + " - " + professor_name.encode("iso-8859-1") self.response.headers["Content-Type"] = "text/calendar; charset=utf-8" self.response.headers["Content-disposition"] = "attachment; filename=%s.ics" % ical_filename self.response.out.write(ical_data) else: render_professor_notfound_page(self, resource_type="iCal file") else:
def _render_calendar_summary(self, cal, staff_member_id): logging.info("got a calendar from staff member id: %s" % staff_member_id) professor_name = cal.header_data["teacher_name"] ical_urls = ["/staff/ical/%s/%s.ics" % (q, staff_member_id) for q in ("q1", "q2")] ical_url_titles = ["ULB - %s - %s" % (q, professor_name) for q in ("Q1", "Q2")] q1_span = convert_weekspan_to_dates(conf.Q1_WEEKSPAN, conf.FIRST_MONDAY) q2_span = convert_weekspan_to_dates(conf.Q2_WEEKSPAN, conf.FIRST_MONDAY) template_values = { "gehol_is_down": is_status_down(), "last_status_update": get_last_status_update(), "version": version.VERSION, "gehol_url": make_professor_gehol_url(staff_member_id, conf.Q2_WEEKSPAN), "professor_name": professor_name, "ical_q1_url": ical_urls[0], "ical_q2_url": ical_urls[1], "ical_q1_url_title": ical_url_titles[0], "ical_q2_url_title": ical_url_titles[1], "q1_span": "from %s to %s" % tuple([q1_span[i].strftime("%B %d, %Y") for i in (0, 1)]), "q2_span": "from %s to %s" % tuple([q2_span[i].strftime("%B %d, %Y") for i in (0, 1)]), } current_session_name = conf.CURRENT_EXAM_SESSION exam_session = None if current_session_name: exam_session = self._extract_current_session_info(current_session_name, staff_member_id) template_values["exam_session"] = exam_session # self._save_successful_request(professor_name, "/staff/%s" % staff_member_id) path = os.path.join(os.path.dirname(__file__), "templates/staff.html") self.response.out.write(template.render(path, template_values))
def render_deadline_exceeded_page(request_handler): template_values = {'gehol_is_down': is_status_down(), 'last_status_update': get_last_status_update(), 'version':version.VERSION } path = os.path.join(os.path.dirname(__file__), 'templates/deadline_exceeded.html') request_handler.response.out.write(template.render(path, template_values))
def render_studentset_notfound_page(request_handler, resource_type): template_values = {'gehol_is_down': is_status_down(), 'last_status_update': get_last_status_update(), 'resource_type':resource_type, 'version':version.VERSION } path = os.path.join(os.path.dirname(__file__), 'templates/studentset_notfound.html') request_handler.response.out.write(template.render(path, template_values))
def render_professor_notfound_page(request_handler, resource_type): template_values = { "gehol_is_down": is_status_down(), "last_status_update": get_last_status_update(), "resource_type": resource_type, "version": version.VERSION, } path = os.path.join(os.path.dirname(__file__), "templates/professor_notfound.html") request_handler.response.out.write(template.render(path, template_values))
def _render_gehol_down_page(self, course_mnemo): reason = "You asked the schedule for the following course : %s." % course_mnemo template_values = {'gehol_is_down': is_status_down(), 'last_status_update': get_last_status_update(), 'request':reason, 'version':version.VERSION } path = os.path.join(os.path.dirname(__file__), 'templates/gehol_down.html') self.response.out.write(template.render(path, template_values))
def _render_calendar_summary(self, cal, course_mnemo): ical_url, csv_url = self._build_file_urls(course_mnemo) start, end = convert_weekspan_to_dates(conf.Q2_WEEKSPAN, conf.FIRST_MONDAY) template_values = {'version':version.VERSION, 'gehol_is_down': is_status_down(), 'last_status_update': get_last_status_update(), 'mnemo':course_mnemo, 'ical_url':ical_url, 'csv_url':csv_url, 'gehol_url': make_course_gehol_url(course_mnemo), 'start_time':start.strftime("%B %d, %Y"), 'end_time':end.strftime("%B %d, %Y"), 'has_events':cal.has_events() } 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))
def _render_calendar_summary(self, cal, group_id): logging.info("got a calendar from group id: %s" % group_id) faculty, student_profile = (cal.header_data['faculty'], cal.header_data['student_profile']) ical_urls = ["/student_set/ical/%s/%s.ics" % (q, group_id) for q in ("q1", "q2")] ical_url_titles = ["ULB - %s - %s" % (q, student_profile) for q in ("Q1", "Q2")] q1_span = convert_weekspan_to_dates(conf.Q1_WEEKSPAN, conf.FIRST_MONDAY) q2_span = convert_weekspan_to_dates(conf.Q2_WEEKSPAN, conf.FIRST_MONDAY) template_values = {'gehol_is_down': is_status_down(), 'last_status_update': get_last_status_update(), 'version':version.VERSION, 'gehol_url':make_studentset_gehol_url(group_id, conf.Q1_WEEKSPAN), 'cal_faculty':faculty, 'cal_student_profile':student_profile, 'ical_q1_url':ical_urls[0], 'ical_q2_url':ical_urls[1], 'ical_q1_url_title':ical_url_titles[0], 'ical_q2_url_title':ical_url_titles[1], 'q1_span': "from %s to %s" % tuple([q1_span[i].strftime("%B %d, %Y") for i in (0, 1)]), 'q2_span': "from %s to %s" % tuple([q2_span[i].strftime("%B %d, %Y") for i in (0, 1)]), 'qrcode_page_url': "/student_set/qrcode/%s" % group_id, 'qrcode_img_url': conf.STUDENTSET_QRCODE_URL_TEMPLATE % (group_id[3:], 256, 256), 'mobile_page_url': '/student_set/m/%s' % group_id[3:], } current_session_name = conf.CURRENT_EXAM_SESSION exam_session = None if current_session_name: exam_session = self._extract_current_session_info(current_session_name, group_id, student_profile) template_values['exam_session'] = exam_session self._save_successful_request(student_profile, "/student_set/%s" % group_id) path = os.path.join(os.path.dirname(__file__), 'templates/student.html') self.response.out.write(template.render(path, template_values))
def get(self): parsed = urlparse.urlparse(self.request.uri) staff_member_id = parsed.path.split("/")[2] if is_status_down(): render_gehol_down(self, "You asked the schedule for a particular student profile.") else: if is_staff_member_id_valid(staff_member_id): logging.debug("staff member '%s' id is valid" % staff_member_id) try: cal = get_professor_q1_calendar(staff_member_id) except DownloadError, e: logging.error("Could not fetch page before deadline") render_deadline_exceeded_page(self) return if cal: self._render_calendar_summary(cal, staff_member_id) else: logging.debug("did not receive a calendar") self._render_not_found_page() else:
def get(self): parsed = urlparse.urlparse(self.request.uri) course_mnemo = parsed.path.split("/")[3].rstrip(".ics") if is_course_mnemo_valid(course_mnemo): if is_status_down(): self._render_gehol_down_page(course_mnemo) else: try: cal = get_calendar(course_mnemo, conf.Q2_WEEKSPAN) except DownloadError,e: logging.error("Could not fetch page before deadline") render_deadline_exceeded_page(self) return if cal: ical_content = convert_course_calendar_to_ical(cal) 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(ical_content) else: self._render_not_found_page(course_mnemo)
def get(self): parsed = urlparse.urlparse(self.request.uri) course_mnemo = self._get_course_mnemo(parsed.path) if is_course_mnemo_valid(course_mnemo): if is_status_down(): self._render_gehol_down_page(course_mnemo) else: try: cal = get_calendar(course_mnemo, conf.Q2_WEEKSPAN) except DownloadError,e: logging.error("Could not fetch page before deadline") render_deadline_exceeded_page(self) cal = None if cal: self._render_calendar_summary(cal, course_mnemo) self._save_successful_request(course_mnemo) else: self._render_not_found_page(course_mnemo)
def get(self): parsed = urlparse.urlparse(self.request.uri) group_id = parsed.path.split("/")[3] if is_status_down(): render_gehol_down(self, "You asked for the QRCode page of a particular student profile.") else: if is_studentset_groupid_valid(group_id): logging.info("group '%s' id is valid" % group_id) try: cal = get_student_q1_calendar(group_id) except DownloadError,e: logging.info("Could not fetch remote calendar before deadline") render_deadline_exceeded_page(self) return if cal: self._render_qrcode_page(cal, group_id) else: logging.info("did not receive a calendar") self._render_not_found_page() else:
def get(self): parsed = urlparse.urlparse(self.request.uri) group_id = parsed.path.split("/")[3] group_id = "%23" + group_id if is_status_down(): render_gehol_down(self, "You asked the schedule for a particular student profile.") else: if is_studentset_groupid_valid(group_id): logging.info("group '%s' id is valid" % group_id) try: cal = get_student_q1_calendar(group_id) except DownloadError,e: logging.error("Could not fetch page before deadline") render_deadline_exceeded_page(self) cal = None if cal: self._render_calendar_summary(cal, group_id) else: logging.info("did not receive a calendar") self._render_not_found_page() else: