コード例 #1
0
ファイル: routes.py プロジェクト: nguyenpham98/Goup
def like_photo_action(photo_id, action):
    photo = Photo.query.filter_by(id=photo_id).first_or_404()
    if action == 'like':
        current_user.like_photo(photo)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_photo(photo)
        db.session.commit()
    return redirect(request.referrer)
コード例 #2
0
def unlike_photo(id):
    # unlike photo in likes page.
    photo = Photo.query.filter_by(id=id).first()
    if photo is None:
        flash(u'无效的图片。', 'warning')
        return redirect(url_for('.likes', username=current_user.username))
    if current_user.is_like_photo(photo):
        current_user.unlike_photo(photo)
        photo.author.liked -= 1
    return (''), 204
コード例 #3
0
def like_photo(id):
    photo = Photo.query.filter_by(id=id).first()
    album = photo.album
    if photo is None:
        flash(u'无效的图片。', 'warning')
        return redirect(url_for('.album', id=album))
    if current_user.is_like_photo(photo):
        current_user.unlike_photo(photo)
        photo.author.liked -= 1
        redirect(url_for('.photo', id=id))
    else:
        current_user.like_photo(photo)
        photo.author.liked += 1
    return redirect(url_for('.photo', id=id))