Ejemplo n.º 1
0
def add_like():
    wish_id = request.form['wish_id']
    user = User.query.filter_by(id=session['id']).first()
    if not Like.like_exists(wish_id, user):
        try:
            Like.like(wish_id, user)
        except exc.SQLAlchemyError:
            return ErrorMessage.message(error_body='Oops something went wrong')
    else:
        try:
            Like.unlike(wish_id, user)
        except exc.SQLAlchemyError:
            return ErrorMessage.message(error_body='Oops something went wrong')
    return json.dumps({
        'num_of_likes':
        len(WishListItem.query.filter_by(id=wish_id).first().likes)
    })
Ejemplo n.º 2
0
def add_wish():
    form = WishlistForm()
    if form.validate_on_submit():
        try:
            new_wish_item = WishListItem(authors=form.authors.data,
                                         item_type=form.type.data,
                                         title=form.title.data,
                                         pub_year=datetime.strptime(
                                             form.pub_date.data, "%Y").date())

            db.session.add(new_wish_item)
            db.session.commit()
            return redirect(url_for('library.wishlist'))
        except exc.SQLAlchemyError:
            return ErrorMessage.message(error_body='Oops something went wrong')
    return render_template('wishlist_add.html', form=form, error=form.errors)
Ejemplo n.º 3
0
def delete_wish(wish_id):
    try:
        WishListItem.delete_wish(wish_id)
    except exc.SQLAlchemyError:
        return ErrorMessage.message(error_body='Oops something went wrong')
    return redirect(url_for('library.wishlist'))