Ejemplo n.º 1
0
def editCourse(category_id, course_id):
    category = Category.query.filter_by(id=category_id).one()
    course = Item.query.filter_by(id=course_id).one()
    form = TitleDescriptionForm()
    #NOTE validate_on_submit also checks if 'POST'
    if form.validate_on_submit():
        course.name = form.name.data
        course.url = form.url.data
        course.description = form.description.data
        db.session.commit()
        flash('* Course item %s edited successfully.' % (course.name))
        return redirect('/')
    elif form.errors:
        first_msg = str(form.errors[form.errors.keys()[0]][0])
        flash('! There was a problem with %s. %s' %
            (form.errors.keys()[0].upper(), first_msg))
    return render_template('course-detail.html', category=category, course=course, form=form)
Ejemplo n.º 2
0
def addCourse(category_id):
    # submitted course displayed both in Course list AND Recent Posts
    category = Category.query.filter_by(id=category_id).one()
    form = TitleDescriptionForm()
    if form.validate_on_submit():
        # if validation is passed add item to the db
        # must set user id based on currently logged-in user
        new_item = Item(name=form.name.data,
                url=form.url.data,
                description=form.description.data,
                category_id=category.id,
                user_id=getUserID())
        db.session.add(new_item)
        db.session.commit()
        flash('* New course item %s successfully added to %s.' %
            (new_item.name, category.name))
        return redirect('/')
    elif form.errors:
        first_msg = str(form.errors[form.errors.keys()[0]][0])
        flash('! There was a problem with %s. %s' %
            (form.errors.keys()[0].upper(), first_msg))
    return render_template('add-course.html', category=category, form=form)
Ejemplo n.º 3
0
def addCourse(category_id):
    # check if user is logged in
    if 'user_name' not in login_session:
        flash('Hey, ya gotta log in first.')
        return redirect('/')
    # submitted course is displayed both in Course list AND Recent Posts list
    category = Category.query.filter_by(id=category_id).one()
    form = TitleDescriptionForm()
    if form.validate_on_submit():
        # if validation is passed add item to the db
        # must set user id based on currently logged-in user
        new_item = Item(name=form.name.data,
                url=form.url.data,
                description=form.description.data,
                category_id=category.id,
                user_id=getUserID())
        db.session.add(new_item)
        db.session.commit()
        flash('* New course item %s successfully added to %s.' %
            (new_item.name, category.name))
        return redirect('/')
    if form.errors:
        flash('! There was a problem...%s' % (form.errors))
    return render_template('add-course.html', category=category, form=form)