def __keep_the_element_of_optimization_review( db_review: ReviewOptimization, main_page: str, translator: Translator): """ Adds row for LastReviewerOptimization :param db_review: ReviewOptimization :param main_page: URL :param translator: Translator :return: None """ # add new vote db_user_created_flag = DBDiscussionSession.query(User).get( db_review.detector_uid) # get all keep and delete votes db_keep_version = DBDiscussionSession.query( LastReviewerOptimization).filter( LastReviewerOptimization.review_uid == db_review.uid, LastReviewerOptimization.is_okay == True).all() if len(db_keep_version) > max_votes: add_reputation_and_send_popup( db_user_created_flag, get_reason_by_action(ReputationReasons.bad_flag), main_page, translator) db_review.set_executed(True) db_review.update_timestamp() DBDiscussionSession.add(db_review) DBDiscussionSession.flush() transaction.commit()
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
def test_add_reputation_and_send_popup(self): db_reason = get_reason_by_action(ReputationReasons.success_flag) self.assertFalse( add_reputation_and_send_popup(self.user_torben, db_reason, 'asd', Translator('en'))) DBDiscussionSession.query(ReputationHistory).filter_by( reputator_uid=9).delete() DBDiscussionSession.flush() transaction.commit()