def review_vote_delete_handler(review_id, user): """Delete your vote for a specified review. **OAuth scope:** vote **Request Example:** .. code-block:: bash $ curl "https://critiquebrainz.org/ws/1/review/9cb11424-d070-4ac1-8771-a8703ae5cccd/vote" \\ -X DELETE \\ -H "Authorization: Bearer <access token>" **Response Example:** .. code-block:: json { "message": "Request processed successfully" } :resheader Content-Type: *application/json* """ review = get_review_or_404(review_id) if review["is_hidden"]: raise NotFound("Review has been hidden.") try: vote = db_vote.get(user_id=user.id, revision_id=review["last_revision"]["id"]) except db_exceptions.NoDataFoundException: raise InvalidRequest("Review is not rated yet.") db_vote.delete(user_id=vote["user_id"], revision_id=vote["revision_id"]) return jsonify(message="Request processed successfully")
def review_vote_delete_handler(review_id, user): """Delete your vote for a specified review. **OAuth scope:** vote **Request Example:** .. code-block:: bash $ curl "https://critiquebrainz.org/ws/1/review/9cb11424-d070-4ac1-8771-a8703ae5cccd/vote" \\ -X DELETE \\ -H "Authorization: Bearer <access token>" **Response Example:** .. code-block:: json { "message": "Request processed successfully" } :resheader Content-Type: *application/json* """ review = get_review_or_404(review_id) if review["is_hidden"]: raise NotFound("Review has been hidden.") try: vote = db_vote.get(user_id=user.id, revision_id=review["last_revision"]["id"]) except db_exceptions.NoDataFoundException: raise InvalidRequest("Review is not rated yet.") db_vote.delete(user_id=vote["user_id"], revision_id=vote["revision_id"]) return jsonify(message="Request processed successfully")
def vote_delete(id): review = get_review_or_404(id) if review["is_hidden"] and not current_user.is_admin(): raise NotFound(gettext("Review has been hidden.")) try: vote = db_vote.get(user_id=current_user.id, revision_id=review["last_revision"]["id"]) flash.success(gettext("You have deleted your vote for this review!")) db_vote.delete(user_id=vote["user_id"], revision_id=vote["revision_id"]) except db_exceptions.NoDataFoundException: flash.error(gettext("This review is not rated yet.")) return redirect(url_for('.entity', id=id))
def test_delete(self): vote.submit(self.user_1.id, self.review["last_revision"]["id"], True) self.assertEqual(vote.get_count(), 1) vote.delete(self.user_1.id, self.review["last_revision"]["id"]) self.assertEqual(vote.get_count(), 0)