def get_arguments_by_conclusion(self): arguments = attacks.get_arguments_by_conclusion(1, True) self.assertTrue(1 in arguments) self.assertTrue(10 in arguments) self.assertTrue(11 in arguments) arguments = attacks.get_arguments_by_conclusion(1, False) self.assertTrue(2 in 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: """ LOG.debug("Entering get_array_for_justify_statement") 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: sarray = self.__get_statement_array_for_justify_statement(db_user, history, argument, uids, _tn, _um) statements_array.append(sarray) 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)}}
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) } }