def add_vote(self, db_user: User, db_review: ReviewDuplicate, is_okay: bool, application_url: str, translator: Translator, **kwargs): """ Adds an vote for this queue. If any (positive or negative) limit is reached, the flagged element will disabled and the origin will be set as root for any relative :param db_user: current user who votes :param db_review: the review, which is voted vor :param is_okay: True, if the element is rightly flagged :param application_url: the app url :param translator: a instance of a translator :param kwargs: optional, keyworded arguments :return: """ LOG.debug("Adding vote for review with id %s. Duplicate? %s", db_review.uid, is_okay) db_user_created_flag = DBDiscussionSession.query(User).get( db_review.detector_uid) rep_reason = None # add new vote add_vote_for(db_user, db_review, is_okay, LastReviewerDuplicate) # get all keep and delete votes count_of_reset, count_of_keep = self.get_review_count(db_review.uid) # do we reached any limit? reached_max = max(count_of_keep, count_of_reset) >= max_votes if reached_max: if count_of_reset > count_of_keep: # disable the flagged part self.__bend_objects_of_review(db_review) rep_reason = get_reason_by_action( ReputationReasons.success_duplicate) else: # just close the review rep_reason = get_reason_by_action( ReputationReasons.bad_duplicate) db_review.set_executed(True) db_review.update_timestamp() elif count_of_keep - count_of_reset >= min_difference: # just close the review rep_reason = get_reason_by_action(ReputationReasons.bad_duplicate) db_review.set_executed(True) db_review.update_timestamp() elif count_of_reset - count_of_keep >= min_difference: # disable the flagged part self.__bend_objects_of_review(db_review) rep_reason = get_reason_by_action( ReputationReasons.success_duplicate) db_review.set_executed(True) db_review.update_timestamp() if rep_reason: add_reputation_and_send_popup(db_user_created_flag, rep_reason, application_url, translator) DBDiscussionSession.add(db_review) DBDiscussionSession.flush() transaction.commit() return True
def add_vote(self, db_user: User, db_review: ReviewEdit, is_okay: bool, application_url: str, translator: Translator, **kwargs): """ Adds an vote for this queue. If any (positive or negative) limit is reached, the flagged element get a new textversion :param db_user: current user who votes :param db_review: the review, which is voted vor :param is_okay: True, if the element is rightly flagged :param application_url: the app url :param translator: a instance of a translator :param kwargs: optional, keyworded arguments :return: """ LOG.debug("Add a vote for edit queue") db_user_created_flag = DBDiscussionSession.query(User).get( db_review.detector_uid) rep_reason = None # add new vote add_vote_for(db_user, db_review, is_okay, LastReviewerEdit) # get all keep and delete votes count_of_edit, count_of_dont_edit = self.get_review_count( db_review.uid) # do we reached any limit? reached_max = max(count_of_edit, count_of_dont_edit) >= max_votes if reached_max: if count_of_dont_edit < count_of_edit: # accept the edit self.__accept_edit_review(db_review) rep_reason = get_reason_by_action( ReputationReasons.success_edit) else: # just close the review rep_reason = get_reason_by_action(ReputationReasons.bad_edit) db_review.set_executed(True) db_review.update_timestamp() elif count_of_edit - count_of_dont_edit >= min_difference: # accept the edit self.__accept_edit_review(db_review) rep_reason = get_reason_by_action(ReputationReasons.success_edit) db_review.set_executed(True) db_review.update_timestamp() elif count_of_dont_edit - count_of_edit >= min_difference: # decline edit rep_reason = get_reason_by_action(ReputationReasons.bad_edit) db_review.set_executed(True) db_review.update_timestamp() if rep_reason: add_reputation_and_send_popup(db_user_created_flag, rep_reason, application_url, translator) DBDiscussionSession.add(db_review) DBDiscussionSession.flush() transaction.commit() return True