def course_page(subject_id, course_id): """ Single course detail page Displays information about the course, its sections, textbooks etc. """ # TODO: Redirect to uppercase subject_id and course_id try: subject = search.subject(subject_id) course = search.course(subject_id, course_id) textbooks = search.textbooks(subject_id, course_id) sections = search.sections(subject_id, course_id) except NotFoundError: return abort(404, "There doesn't appear to be a course named {} {}".format(subject_id, course_id)) terms = {} for section in sections: # section['_id'] TODO: Ensure this is set term_name = "{year} {season}".format(**section) # Add it to that term's list term = terms.get(term_name, []) term.append(section) terms[term_name] = term sorted_terms = sorted(terms.iteritems(), key=lambda x: util.term_ordering(x[0])) course_query = "subject: {} number: {}".format(subject_id, course_id) return render_template( "course.html", subject=subject, course=course, terms=sorted_terms, textbooks=textbooks, query=course_query )
def is_oldterm(term): """ Returns True if the term is old """ now = datetime.now() now_rank = now.year * 3 + (now.month - 1) // 4 return now_rank > util.term_ordering(term)