Exemplo n.º 1
0
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) )
Exemplo n.º 2
0
def reset_sections():
    update_user_schedule(session['userid'], [])
    sections = get_user_info(session)['sections']
    return simplejson.dumps(sections)