def handle_section(section): userinfo = get_user_info(session) sections = set(userinfo['sections']) if request.method == 'DELETE': # Removing a course try: sections.remove(section) except: pass sections = list(sections) update_user_schedule(session['userid'], sections) return simplejson.dumps(sections) else: # Adding a course allTimes = {} conflictDetected = False if section in sections: return simplejson.dumps( get_sections_for_user(session) ) for s in sections: allTimes[s] = convertTimeStringToDictionary(get_times_for_section(g.db, s)) if not (noConflict(allTimes, convertTimeStringToDictionary(get_times_for_section(g.db, section)))): conflictDetected = True break if conflictDetected: return "Conflict detected", 400 else: sections.add(section) update_user_schedule(session['userid'], list(sections)) return simplejson.dumps( get_sections_for_user(session) )
def get_sections_for_user(session): userinfo = get_user_info(session) sections = set(userinfo['sections']) ret = {} for section in sections: ret[section] = convertTimeStringToDictionary(get_times_for_section(g.db, section)) return ret
def course_schedule(courseid): sections = get_sections_for_course(g.db, courseid) times = {} for section in sections: times['section'] = convertTimeStringToDictionary(get_times_for_section(g.db, section)) return simplejson.dumps(times)