def like(tid): u = current_user() Like.like(u.id, tid) t = Topic.one(id=tid) Topic.update(tid, heat=t.heat + 3) flash('点赞影评成功') return redirect(url_for('.detail', tid=tid))
def create_like(user_id): liked_user = User.get_by_id(user_id) # Check if user exists has_photo = Like.able_to_like( g.current_user.id) # Check if user has profile image is_blocked = User.user_is_blocked(g.current_user.id, user_id) # Check if user was blocked if is_blocked: abort(http.HTTPStatus.FORBIDDEN) if not has_photo: abort(http.HTTPStatus.FORBIDDEN) if liked_user and has_photo: Like.like(g.current_user.id, user_id) # If user is not blocked [blocked, blocker] # Notification if not is_blocked: text = Notification.notification_text('like', g.current_user) notification = Notification.from_dict({ "user_id": user_id, "text": text, "type": "like" }) notification.create() return jsonify(ok=True) abort(http.HTTPStatus.BAD_REQUEST)