Ejemplo n.º 1
0
    def __get_choose_array_for_pgroup(self, is_argument: bool, is_supportive: bool, conclusion_uid: int,
                                      argument_uid: int, db_user: User, group_id: int, _um: UrlManager):
        db_premises = DBDiscussionSession.query(Premise).filter_by(premisegroup_uid=group_id).all()
        premise_array = []
        for premise in db_premises:
            text = premise.get_text()
            premise_array.append({'title': text, 'id': premise.statement_uid})
            if db_user and db_user.nickname != nick_of_anonymous_user:  # add seen by if the statement is visible
                add_seen_statement(premise.statement_uid, db_user)

        # get attack for each premise, so the urls will be unique
        db_argument = DBDiscussionSession.query(Argument).filter(Argument.premisegroup_uid == group_id,
                                                                 Argument.is_supportive == is_supportive)
        if conclusion_uid and not is_argument:
            db_argument = db_argument.filter_by(conclusion_uid=conclusion_uid).first()
        else:
            db_argument = db_argument.filter_by(argument_uid=argument_uid).first()

        if not db_argument:
            return None

        attacking_arg_uids = get_all_attacking_arg_uids_from_history(self.path)
        arg_id_sys, attack = attacks.get_attack_for_argument(db_argument.uid,
                                                             restrictive_arg_uids=attacking_arg_uids)
        url = _um.get_url_for_reaction_on_argument(db_argument.uid, attack, arg_id_sys)

        if is_argument:
            is_author = is_author_of_argument(db_user, argument_uid)
        else:
            is_author = is_author_of_statement(db_user, conclusion_uid)
        return self.__create_answer_dict(str(db_argument.uid), premise_array, 'choose', url,
                                         is_markable=True, is_editable=True, is_author=is_author)
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    def get_dict_for_argumentation(self, db_user_argument: Argument,
                                   arg_sys_id: Optional[int],
                                   attack: Optional[Relations], history: str,
                                   db_user: User) -> dict:
        """
        Prepares the discussion dict with all bubbles for the argumentation window.

        :param db_user_argument: Argument
        :param arg_sys_id: Argument.uid / not necessary if attack=end
        :param attack: String (undermine, support, undercut, rebut, ...)
        :param history: History
        :param db_user: User
        :return: dict()
        """
        LOG.debug("At_argumentation about %s", db_user_argument.uid)
        nickname = db_user.nickname
        if db_user.nickname == nick_of_anonymous_user:
            db_user = None
            nickname = None

        bubbles_array = history_handler.create_bubbles(self.history, nickname,
                                                       self.lang, self.slug)
        add_premise_text = ''
        save_statement_url = 'set_new_start_statement'
        bubble_mid = ''
        splitted_history = history_handler.split(self.history)
        user_changed_opinion = splitted_history[-1].endswith(
            str(db_user_argument.uid))
        statement_list = list()
        db_argument = DBDiscussionSession.query(Argument).get(
            db_user_argument.uid)
        gender_of_counter_arg = ''

        db_enemy = None
        if arg_sys_id is not None:
            db_tmp_arg = DBDiscussionSession.query(Argument).get(arg_sys_id)
            data = get_name_link_of_arguments_author(db_tmp_arg, nickname)
            db_enemy = data['user']

        if not attack:
            prep_dict = self.__get_dict_for_argumentation_end(
                db_user_argument.uid, user_changed_opinion, db_user)
            bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                  content=prep_dict['sys'],
                                                  omit_bubble_url=True,
                                                  lang=self.lang,
                                                  other_author=db_enemy)
            bubble_mid = create_speechbubble_dict(BubbleTypes.INFO,
                                                  content=prep_dict['mid'],
                                                  omit_bubble_url=True,
                                                  lang=self.lang)
        else:
            prep_dict = self.__get_dict_for_argumentation(
                db_argument, arg_sys_id, history, attack, nickname,
                db_user_argument.is_supportive)
            quid = 'question-bubble-' + str(arg_sys_id) if int(
                arg_sys_id) > 0 else ''
            is_author = is_author_of_argument(db_user,
                                              prep_dict['confrontation'].uid)
            bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                  is_markable=True,
                                                  is_author=is_author,
                                                  uid=quid,
                                                  content=prep_dict['sys'],
                                                  omit_bubble_url=True,
                                                  lang=self.lang,
                                                  other_author=db_enemy)
            statement_list = self.__get_all_statement_texts_by_argument(
                prep_dict['confrontation'])
            gender_of_counter_arg = prep_dict['gender']

        bubble_user = create_speechbubble_dict(
            BubbleTypes.USER,
            content=prep_dict['user'],
            omit_bubble_url=True,
            argument_uid=db_user_argument.uid,
            is_supportive=db_user_argument.is_supportive,
            db_user=db_user,
            lang=self.lang,
            other_author=db_enemy)

        # dirty fixes
        if len(bubbles_array) > 0 and bubbles_array[-1][
                'message'] == bubble_user['message']:
            bubbles_array.remove(bubbles_array[-1])

        self.__append_now_bubble(bubbles_array)
        if not bubbles_already_last_in_list(bubbles_array, bubble_user):
            bubbles_array.append(bubble_user)
        if not bubbles_already_last_in_list(bubbles_array, bubble_sys):
            bubbles_array.append(bubble_sys)

        if not attack:
            bubbles_array.append(bubble_mid)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'extras': statement_list,
            'gender': gender_of_counter_arg,
            'broke_limit': self.broke_limit
        }
Ejemplo n.º 5
0
    def get_array_for_choosing(self, argument_or_statement_id, pgroup_ids,
                               is_argument, is_supportive, nickname):
        """
        Prepares the dict with all items for the choosing an premise, when the user inserted more than one new premise.

        :param argument_or_statement_id: Argument.uid or Statement.uid
        :param pgroup_ids: PremiseGroups.uid
        :param is_argument: Boolean
        :param is_supportive: Boolean
        :param nickname:
        :return: dict()
        """
        logger('ItemDictHelper', 'def')
        statements_array = []
        slug = self.db_issue.slug
        _um = UrlManager(slug, history=self.path)
        conclusion_uid = argument_or_statement_id if not is_argument else None
        argument_uid = argument_or_statement_id if is_argument else None
        db_user = DBDiscussionSession.query(User).filter_by(
            nickname=nickname).first()

        for group_id in pgroup_ids:
            db_premises = DBDiscussionSession.query(Premise).filter_by(
                premisegroup_uid=group_id).all()
            premise_array = []
            for premise in db_premises:
                text = premise.get_text()
                premise_array.append({
                    'title': text,
                    'id': premise.statement_uid
                })
                if db_user and db_user.nickname != nick_of_anonymous_user:  # add seen by if the statement is visible
                    add_seen_statement(premise.statement_uid, db_user)

            # get attack for each premise, so the urls will be unique
            db_argument = DBDiscussionSession.query(Argument).filter(
                Argument.premisegroup_uid == group_id,
                Argument.is_supportive == is_supportive)
            if conclusion_uid and not is_argument:
                db_argument = db_argument.filter_by(
                    conclusion_uid=conclusion_uid).first()
            else:
                db_argument = db_argument.filter_by(
                    argument_uid=argument_uid).first()

            if not db_argument:
                print(group_id)
                return {
                    'elements': statements_array,
                    'extras': {
                        'cropped_list': False
                    }
                }

            attacking_arg_uids = get_all_attacking_arg_uids_from_history(
                self.path)
            arg_id_sys, attack = attacks.get_attack_for_argument(
                db_argument.uid, restrictive_arg_uids=attacking_arg_uids)
            url = _um.get_url_for_reaction_on_argument(db_argument.uid, attack,
                                                       arg_id_sys)

            if is_argument:
                is_author = is_author_of_argument(db_user, argument_uid)
            else:
                is_author = is_author_of_statement(db_user, conclusion_uid)
            statements_array.append(
                self.__create_answer_dict(str(db_argument.uid),
                                          premise_array,
                                          'choose',
                                          url,
                                          is_markable=True,
                                          is_editable=True,
                                          is_author=is_author))

        return {
            'elements': statements_array,
            'extras': {
                'cropped_list': False
            }
        }
Ejemplo n.º 6
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)
            }
        }
Ejemplo n.º 7
0
    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)
            }
        }