コード例 #1
0
ファイル: views.py プロジェクト: joshgrib/sitstuff
def my_form_post():
    """
    Gets input from form, puts it in a list, gets the schedules,
    send JSON of course combinations and send then to /sched as
    a cookie
    """
    text_list = []
    #make list of form inputs
    for i in range(1, AMOUNT_OF_COURSES + 1):
        form_num = 'text' + str(i)
        text_list.append(request.form[form_num])
    #remove items with no input, generate string of courses
    final_list = []
    for text in text_list:
        if not text == "":
            final_list.append(text)
    courses_str = ""
    for course in final_list[:-1]:
        courses_str += (str(course) + ',')
    courses_str += str(final_list[-1])
    courses_str = courses_str.upper()
    #turn string of courses entered into list
    c_list = courses_str.split(',')
    #get the schedules
    #print "\nCourse list:"
    #print str(c_list) + "\n"
    my_combos = scheduler.schedule(c_list)
    resp = make_response(redirect('/sched'))
    resp.set_cookie('course_combos', '', expires=0)
    resp.set_cookie('course_combos', json.dumps(my_combos))
    return resp
コード例 #2
0
ファイル: views.py プロジェクト: joshgrib/sitstuff
def getCombosAPI():
    """
    Upon a GET request containing csv course names in a query string...
    Find the combos and send them as JSON
    """
    all_args = request.args.lists()
    course_list = all_args[0][1][0].split(",")
    u_COURSE_LIST = map((lambda x: x.upper()), course_list)#make all caps just in case
    COURSE_LIST = map( str, u_COURSE_LIST)#unicode list -> list of python strs
    combos = scheduler.schedule(COURSE_LIST)
    return jsonify(combos)