def get_array_for_dont_know_reaction(self, argument_uid, db_user, gender): """ Prepares the dict with all items for the third step, where a supportive argument will be presented. :param argument_uid: Argument.uid :param db_user: User :param gender: m, f or n :return: """ LOG.debug("Entering get_array_for_dont_know_reaction") slug = self.db_issue.slug statements_array = [] db_arguments = get_enabled_arguments_as_query() db_argument = db_arguments.filter_by(uid=argument_uid).first() if not db_argument: return {'elements': statements_array, 'extras': {'cropped_list': False}} # set real argument in history tmp_path = self.path.replace('/justify/{}/d'.format(db_argument.conclusion_uid), '/justify/{}/d'.format(argument_uid)) _um = UrlManager(slug, history=tmp_path) if db_user and db_user.nickname != nick_of_anonymous_user: # add seen by if the statement is visible add_seen_argument(argument_uid, db_user) rel_dict = get_relation_text_dict_with_substitution(self.lang, False, is_dont_know=True, gender=gender) relation = Relations.UNDERMINE.value url = self.__get_dont_know_item_for_undermine(db_argument, Attitudes.DISAGREE, _um) d = self.__create_answer_dict(relation, [{'title': rel_dict[relation + '_text'], 'id': relation}], relation, url) statements_array.append(d) relation = Relations.SUPPORT.value url = self.__get_dont_know_item_for_support(argument_uid, _um) d = self.__create_answer_dict(relation, [{'title': rel_dict[relation + '_text'], 'id': relation}], relation, url) statements_array.append(d) relation = Relations.UNDERCUT.value url = self.__get_dont_know_item_for_undercut(argument_uid, Attitudes.AGREE, _um) d = self.__create_answer_dict(relation, [{'title': rel_dict[relation + '_text'], 'id': relation}], relation, url) statements_array.append(d) relation = Relations.REBUT.value url = self.__get_dont_know_item_for_rebut(db_argument, Attitudes.DISAGREE, _um) d = self.__create_answer_dict(relation, [{'title': rel_dict[relation + '_text'], 'id': relation}], relation, url) statements_array.append(d) return {'elements': statements_array, 'extras': {'cropped_list': False}}
def __get_statement_array_for_justify_argument(self, argument_uid, attack_type, db_user, history, argument, uids, _um): if db_user and db_user.nickname != nick_of_anonymous_user: # add seen by if the statement is visible add_seen_argument(argument_uid, db_user) # get all premises in this group db_premises = DBDiscussionSession.query(Premise).filter_by( premisegroup_uid=argument.premisegroup_uid).all() premises_array = [] for premise in db_premises: text = premise.get_text() premises_array.append({ 'id': premise.statement_uid, 'title': text }) # for each justifying premise, we need a new confrontation: (restriction is based on fix #38) is_undermine = Relations.UNDERMINE if attack_type == Relations.UNDERMINE else None attacking_arg_uids = get_all_attacking_arg_uids_from_history(self.path) arg_id_sys, attack = attacks.get_attack_for_argument(argument.uid, last_attack=is_undermine, restrictive_arg_uids=attacking_arg_uids, history=self.path) the_other_one = True url = '' # with a chance of 50% or at the end we will seed the new "support step" if not attack: new_arg = get_another_argument_with_same_conclusion(argument.uid, history) the_other_one = new_arg is None if new_arg: the_other_one = False url = _um.get_url_for_support_each_other(argument.uid, new_arg.uid) if the_other_one: url = _um.get_url_for_reaction_on_argument(argument.uid, attack, arg_id_sys) return self.__create_answer_dict(argument.uid, premises_array, 'justify', url, is_markable=True, is_editable=not EditQueue().is_arguments_premise_in_edit_queue(argument), is_author=is_author_of_argument(db_user, argument.uid), is_visible=argument.uid in uids, attack_url=_um.get_url_for_jump(argument.uid))
def set_seen_statements(uids, path, db_user) -> dict: """ Marks several statements as already seen. :param uids: Uids of statements which should be marked as seen :param path: Current path of the user :param db_user: User :rtype: dict :return: Dictionary with an error field """ # are the statements connected to an argument? if 'justify' in path: url = path[path.index('justify/') + len('justify/'):] additional_argument = int(url[:url.index('/')]) add_seen_argument(additional_argument, db_user) for uid in uids: # we get the premise group id's only if is_integer(uid): add_seen_statement(uid, db_user) return {'status': 'success'}
def __get_statement_array_for_justify_statement(self, db_user, history, argument, uids, _tn, _um): if db_user and argument.uid in uids: # add seen by if the statement is visible add_seen_argument(argument.uid, db_user) # get all premises in the premisegroup of this argument db_premises = DBDiscussionSession.query(Premise).filter_by( premisegroup_uid=argument.premisegroup_uid).all() premise_array = [] for premise in db_premises: text = premise.get_text() premise_array.append({'title': text, 'id': premise.statement_uid}) # filter forbidden attacks forbidden_attacks = attacks.get_forbidden_attacks_based_on_history(self.path) # get attack for each premise, so the urls will be unique arg_id_sys, attack = attacks.get_attack_for_argument(argument.uid, history=self.path, restrictive_arg_uids=forbidden_attacks) already_used = 'reaction/' + str(argument.uid) + '/' in self.path additional_text = '(' + _tn.get(_.youUsedThisEarlier) + ')' url = _um.get_url_for_discussion_finish( argument.uid) # finish the discussion if D-BAS can't find something to talk about if attack: # if there is an attack get the url to a reaction url = _um.get_url_for_reaction_on_argument(argument.uid, attack.value, arg_id_sys) else: # if there is no attack, search for an argument to ask the user about new_arg = get_another_argument_with_same_conclusion(argument.uid, history) if new_arg: # if one is found: get the url url = _um.get_url_for_support_each_other(argument.uid, new_arg.uid) return self.__create_answer_dict(str(argument.uid), premise_array, 'justify', url, already_used=already_used, already_used_text=additional_text, is_editable=not EditQueue().is_arguments_premise_in_edit_queue(argument), is_markable=True, is_author=is_author_of_argument(db_user, argument.uid), is_visible=argument.uid in uids, attack_url=_um.get_url_for_jump(argument.uid))
def test_add_seen_argument(self): self.clear_every_vote() self.check_tables_of_user_for_n_rows(self.user, 0, 0, 0, 0) val = add_seen_argument([], 1100) self.assertFalse(val) val = add_seen_argument([], self.user) self.assertFalse(val) val = add_seen_argument([0], self.user) self.assertFalse(val) val = add_seen_argument([1], self.user) self.assertFalse(val) val = add_seen_argument(None, self.user) self.assertFalse(val) val = add_seen_argument('a', self.user) self.assertFalse(val) val = add_seen_argument(1, 1100) self.assertFalse(val) val = add_seen_argument(0, 1) self.assertFalse(val) self.check_tables_of_user_for_n_rows(self.user, 0, 0, 0, 0) val = add_seen_argument(1, self.user) self.assertTrue(val) self.check_tables_of_user_for_n_rows(self.user, 0, 0, 2, 1) val = add_seen_argument(2, self.user) self.assertTrue(val) self.check_tables_of_user_for_n_rows(self.user, 0, 0, 3, 2) val = add_seen_argument(2, self.user) self.assertTrue(val) self.check_tables_of_user_for_n_rows(self.user, 0, 0, 3, 2) self.clear_every_vote() self.check_tables_of_user_for_n_rows(self.user, 0, 0, 0, 0)
def get_array_for_justify_argument(self, argument_uid, attack_type, db_user, history): """ Prepares the dict with all items for a step in discussion, where the user justifies his attack she has done. :param argument_uid: Argument.uid :param attack_type: String :param db_user: :param history: :return: """ logger('ItemDictHelper', 'def: arg {}, attack {}'.format(argument_uid, attack_type)) statements_array = [] _tn = Translator(self.lang) slug = self.db_issue.slug # description in docs: dbas/logic db_arguments = self.__get_arguments_based_on_attack( attack_type, argument_uid) uids = [argument.uid for argument in db_arguments if db_arguments] _um = UrlManager(slug, history=self.path) for argument in db_arguments: if db_user and db_user.nickname != nick_of_anonymous_user: # add seen by if the statement is visible add_seen_argument(argument_uid, db_user) # get all premises in this group db_premises = DBDiscussionSession.query(Premise).filter_by( premisegroup_uid=argument.premisegroup_uid).all() premises_array = [] for premise in db_premises: text = premise.get_text() premises_array.append({ 'id': premise.statement_uid, 'title': text }) # for each justifying premise, we need a new confrontation: (restriction is based on fix #38) is_undermine = Relations.UNDERMINE if attack_type == Relations.UNDERMINE else None attacking_arg_uids = get_all_attacking_arg_uids_from_history( self.path) arg_id_sys, attack = attacks.get_attack_for_argument( argument.uid, last_attack=is_undermine, restrictive_arg_uids=attacking_arg_uids, history=self.path) the_other_one = True url = '' # with a chance of 50% or at the end we will seed the new "support step" if not attack: new_arg = get_another_argument_with_same_conclusion( argument.uid, history) the_other_one = new_arg is None if new_arg: the_other_one = False url = _um.get_url_for_support_each_other( argument.uid, new_arg.uid) if the_other_one: url = _um.get_url_for_reaction_on_argument( argument.uid, attack, arg_id_sys) statements_array.append( self.__create_answer_dict( argument.uid, premises_array, 'justify', url, is_markable=True, is_editable=not is_arguments_premise_in_edit_queue( argument), is_author=is_author_of_argument(db_user, argument.uid), is_visible=argument.uid in uids, attack_url=_um.get_url_for_jump(argument.uid))) shuffle_list_by_user(db_user, statements_array) if not self.issue_read_only: if db_user and db_user.nickname != nick_of_anonymous_user: text = _tn.get(_.newPremiseRadioButtonText) if len(statements_array) == 0: text = _tn.get(_.newPremiseRadioButtonTextAsFirstOne) a_dict = self.__create_answer_dict('justify_premise', [{ 'id': '0', 'title': text }], 'justify', 'add') statements_array.append(a_dict) else: # elif len(statements_array) == 1: a_dict = self.__create_answer_dict( 'login', [{ 'id': '0', 'title': _tn.get(_.onlyOneItem) }], 'justify', 'login') statements_array.append(a_dict) return { 'elements': statements_array, 'extras': { 'cropped_list': len(uids) < len(db_arguments) } }
def get_array_for_justify_statement(self, db_statement: Statement, db_user: User, is_supportive: bool, history): """ Prepares the dict with all items for the third step in discussion, where the user justifies his position. :param db_statement: Statement :param db_user: User :param is_supportive: Boolean :param history: history :return: """ logger('ItemDictHelper', 'def') statements_array = [] _tn = Translator(self.lang) slug = self.db_issue.slug db_arguments: List[Argument] = attacks.get_arguments_by_conclusion( db_statement.uid, is_supportive) uids: List[int] = [ argument.uid for argument in db_arguments if db_arguments ] _um = UrlManager(slug, history=self.path) for argument in db_arguments: if db_user and argument.uid in uids: # add seen by if the statement is visible add_seen_argument(argument.uid, db_user) # get all premises in the premisegroup of this argument db_premises = DBDiscussionSession.query(Premise).filter_by( premisegroup_uid=argument.premisegroup_uid).all() premise_array = [] for premise in db_premises: text = premise.get_text() premise_array.append({ 'title': text, 'id': premise.statement_uid }) # filter forbidden attacks forbidden_attacks = attacks.get_forbidden_attacks_based_on_history( self.path) # get attack for each premise, so the urls will be unique arg_id_sys, attack = attacks.get_attack_for_argument( argument.uid, history=self.path, restrictive_arg_uids=forbidden_attacks) already_used = 'reaction/' + str(argument.uid) + '/' in self.path additional_text = '(' + _tn.get(_.youUsedThisEarlier) + ')' new_arg = None url = None if not attack: new_arg = get_another_argument_with_same_conclusion( argument.uid, history) if new_arg: url = _um.get_url_for_support_each_other( argument.uid, new_arg.uid) if attack or new_arg is None or url is None: url = _um.get_url_for_reaction_on_argument( argument.uid, attack.value, arg_id_sys) statements_array.append( self.__create_answer_dict( str(argument.uid), premise_array, 'justify', url, already_used=already_used, already_used_text=additional_text, is_editable=not is_arguments_premise_in_edit_queue( argument), is_markable=True, is_author=is_author_of_argument(db_user, argument.uid), is_visible=argument.uid in uids, attack_url=_um.get_url_for_jump(argument.uid))) shuffle_list_by_user(db_user, statements_array) if not self.issue_read_only: if db_user and db_user.nickname != nick_of_anonymous_user: statements_array.append( self.__create_answer_dict( 'start_premise', [{ 'title': _tn.get(_.newPremiseRadioButtonText), 'id': 0 }], 'justify', 'add')) else: statements_array.append( self.__create_answer_dict( 'login', [{ 'id': '0', 'title': _tn.get(_.onlyOneItem) }], 'justify', 'login')) return { 'elements': statements_array, 'extras': { 'cropped_list': len(uids) < len(db_arguments) } }