Esempio n. 1
0
def submit_alt_desc(dept, course_id, methods=['POST', 'GET']):
    formatted_id = id_from_url(course_id)
    form = AltDescForm(request.args)
    if form.validate():
        print 'form validated'
        alt_desc = AltDesc(next_alt_desc_id(dbsession), False,
                           datetime.date.fromtimestamp(time.time()),
                           form.content.data, str(formatted_id))
        db.session.add(alt_desc)
        db.session.commit()
        flash('Thanks for submitting an alternative description')
    return redirect('/catalog/' + dept + "/" + course_id)
Esempio n. 2
0
def course_page(dept, course_id):
    try:  #format id, else tell user that id is invalid
        formatted_id = id_from_url(course_id)
    except ValueError:
        return '\'' + course_id + '\' is not a valid course id.'

    try:
        res = dbsession.query(Course)
        course = res.filter(Course.id == formatted_id).one()
    except:
        return 'Course \'' + course_id + '\' does not exist.'

    #get alt descs for course
    res = dbsession.query(AltDesc)
    alt_desc_list = list(res.filter(AltDesc.course_id == formatted_id))

    #get alt descs for courses that are the same (like CS220 and MATH220)
    #and concatenate them together
    for same_course in listify(course.same_as):
        additional_alt_descs = dbsession.query(AltDesc).filter(
            AltDesc.course_id == same_course)
        alt_desc_list += list(additional_alt_descs)

    #remove unapproved alt descs
    alt_desc_list = filter(lambda alt_desc: alt_desc.approved, alt_desc_list)

    sections = dbsession.query(Section).\
                         filter( Section.course_id == formatted_id )
    term_offerings = OrderedDict()
    for term in terms:
        term_offerings[term] = sections.filter(Section.term == term)
        term_offerings[term] = list(term_offerings[term])

    course = search(dbsession, course_id=course.id)
    course = course[course.keys()[0]]

    form = AltDescForm()

    #Appends course title to history
    history = History()
    history.add(course)
    #Sets history cookie
    resp = make_response(
        render_template("course.html",
                        course=course,
                        form=form,
                        alt_descs=alt_desc_list,
                        terms=term_offerings,
                        history=history))
    resp.set_cookie('history', str(history),
                    max_age=365 * 24 * 60 * 60)  #cookie lasts a year
    return resp
Esempio n. 3
0
def submit_alt_desc(dept, course_id, methods=['POST','GET']):
    formatted_id = id_from_url(course_id)
    form = AltDescForm(request.args)
    if form.validate():
        print 'form validated'
        alt_desc = AltDesc(next_alt_desc_id(dbsession),
                           False,
                           datetime.date.fromtimestamp(time.time()),
                           form.content.data,
                           str(formatted_id))
        db.session.add(alt_desc)
        db.session.commit()
        flash('Thanks for submitting an alternative description')
    return redirect('/catalog/'+dept+"/"+course_id)
Esempio n. 4
0
def course_page(dept, course_id):
    try: #format id, else tell user that id is invalid
        formatted_id = id_from_url(course_id)
    except ValueError:
        return '\''+course_id+'\' is not a valid course id.'

    try:
        res = dbsession.query(Course)
        course = res.filter(Course.id == formatted_id).one()
    except:
        return 'Course \'' + course_id + '\' does not exist.'

    #get alt descs for course
    res = dbsession.query(AltDesc)
    alt_desc_list = list(res.filter(AltDesc.course_id == formatted_id))

    #get alt descs for courses that are the same (like CS220 and MATH220)
    #and concatenate them together
    for same_course in listify(course.same_as):
        additional_alt_descs = dbsession.query(AltDesc).filter(AltDesc.course_id == same_course)
        alt_desc_list += list(additional_alt_descs)

    #remove unapproved alt descs
    alt_desc_list = filter(lambda alt_desc: alt_desc.approved, alt_desc_list)

    sections = dbsession.query(Section).\
                         filter( Section.course_id == formatted_id )
    term_offerings = OrderedDict()
    for term in terms:
        term_offerings[term] = sections.filter(Section.term==term)
        term_offerings[term] = list(term_offerings[term])

    course = search(dbsession, course_id = course.id)
    course = course[course.keys()[0]]

    form = AltDescForm()

    #Appends course title to history
    history = History()
    history.add(course)
    #Sets history cookie
    resp = make_response( render_template("course.html",
                                          course=course,
                                          form=form,
                                          alt_descs=alt_desc_list,
                                          terms=term_offerings,
                                          history=history) )
    resp.set_cookie('history', str(history), max_age=365*24*60*60) #cookie lasts a year
    return resp