Ejemplo n.º 1
0
def __prepare_justify_statement_step(bubble_array: List[dict], index: int,
                                     step: str, db_user: User, lang: str,
                                     url: str) -> None:
    """
    Preparation for creating the justification bubbles

    :param bubble_array: [dict()]
    :param index: int
    :param step: String
    :param db_user: User
    :param lang: Language.ui_locales
    :param url: String
    :return: None
    """
    LOG.debug("%s: justify case -> %s", index, step)
    steps = step.split('/')
    if len(steps) < 3:
        return
    mode = steps[2]
    relation = steps[3] if len(steps) > 3 else ''

    if [
            c for c in (Attitudes.AGREE.value, Attitudes.DISAGREE.value)
            if c in mode
    ] and relation == '':
        bubble = __get_bubble_from_justify_statement_step(
            step, db_user, lang, url)
        if bubble and not bubbles_already_last_in_list(bubble_array, bubble):
            bubble_array += bubble

    elif Attitudes.DONT_KNOW.value in mode and relation == '':
        bubbles = __get_bubble_from_dont_know_step(step, db_user, lang)
        if bubbles and not bubbles_already_last_in_list(bubble_array, bubbles):
            bubble_array += bubbles
Ejemplo n.º 2
0
    def get_dict_for_dont_know_reaction(self, uid, nickname) -> dict:
        """
        Prepares the discussion dict with all bubbles for the third step,
        where an supportive argument will be presented.

        :param uid: Argument.uid
        :param nickname:
        :return: dict()
        """
        LOG.debug("Entering get_dict_for_dont_know_reaction")
        _tn = Translator(self.lang)
        bubbles_array = history_handler.create_bubbles(self.history,
                                                       self.nickname,
                                                       self.lang, self.slug)
        add_premise_text = ''
        save_statement_url = 'set_new_start_statement'
        gender = ''
        b = '<' + tag_type + '>'
        e = '</' + tag_type + '>'
        statement_list = list()

        if int(uid) != 0:
            text = get_text_for_argument_uid(uid,
                                             rearrange_intro=True,
                                             attack_type='dont_know',
                                             with_html_tag=True,
                                             start_with_intro=True)
            db_argument = DBDiscussionSession.query(Argument).get(uid)
            if not db_argument:
                text = ''
            data = get_name_link_of_arguments_author(db_argument, nickname)
            gender = data['gender']
            if data['is_valid']:
                intro = data['link'] + ' ' + b + _tn.get(_.thinksThat) + e
            else:
                intro = b + _tn.get(_.otherParticipantsThinkThat) + e
            sys_text = intro + ' ' + start_with_small(text) + '. '
            sys_text += '<br><br> ' + b + _tn.get(
                _.whatDoYouThinkAboutThat) + '?' + e
            bubble_sys = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                  is_markable=True,
                                                  uid=uid,
                                                  content=sys_text,
                                                  other_author=data['user'])
            if not bubbles_already_last_in_list(bubbles_array, bubble_sys):
                bubbles_array.append(bubble_sys)

            # add statements of discussion to report them
            statement_list = self.__get_all_statement_texts_by_argument(
                db_argument)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'extras': statement_list,
            'gender': gender,
            'broke_limit': self.broke_limit
        }
Ejemplo n.º 3
0
    def get_dict_for_choosing(self, uid, is_uid_argument,
                              is_supportive) -> dict:
        """
        Prepares the discussion dict with all bubbles for the choosing an premise,
        when the user inserted more than one new premise.

        :param uid: Argument.uid
        :param is_uid_argument: Boolean
        :param is_supportive: Boolean
        :return:
        """
        _tn = Translator(self.lang)
        bubbles_array = history_handler.create_bubbles(self.history,
                                                       self.nickname,
                                                       self.lang, self.slug)
        add_premise_text = ''
        save_statement_url = 'set_new_start_statement'

        LOG.debug("Choosing dictionary for bubbles.")
        a = _tn.get(_.soYouEnteredMultipleReasons)
        if is_uid_argument:
            c = get_text_for_argument_uid(uid)
        else:
            statement = DBDiscussionSession.query(Statement).get(uid)
            c = statement.get_text()

        if is_supportive:
            if is_uid_argument:
                b = _tn.get(_.whatIsYourMostImportantReasonForArgument)
            else:
                b = _tn.get(_.whatIsYourMostImportantReasonForStatement)
        else:
            if is_uid_argument:
                b = _tn.get(_.whatIsYourMostImportantReasonAgainstArgument)
            else:
                b = _tn.get(_.whatIsYourMostImportantReasonAgainstStatement)
        b = b.replace('{}', '')

        text = '{}. {}: {}?<br>{}...'.format(a, b, c, _tn.get(_.because))

        self.__append_now_bubble(bubbles_array)

        question_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                   uid='question-bubble',
                                                   content=text,
                                                   omit_bubble_url=True,
                                                   lang=self.lang)
        if not bubbles_already_last_in_list(bubbles_array, question_bubble):
            bubbles_array.append(question_bubble)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'broke_limit': self.broke_limit
        }
Ejemplo n.º 4
0
def __prepare_reaction_step(bubble_array: List[dict], index: int, step: str, db_user: User, lang: str,
                            splitted_history: list, url: str) -> None:
    """
    Preparation for creating the reaction bubbles

    :param bubble_array: [dict()]
    :param index: int
    :param step: String
    :param db_user: User
    :param lang: Language.ui_locales
    :param splitted_history:
    :param url: String
    :return: None
    """
    LOG.debug("%s: reaction case -> %s", index, step)
    bubbles = get_bubble_from_reaction_step(step, db_user, lang, splitted_history, url)
    if bubbles and not bubbles_already_last_in_list(bubble_array, bubbles):
        bubble_array += bubbles
Ejemplo n.º 5
0
def __prepare_reaction_step(bubble_array, index, step, db_user, lang, splitted_history, url):
    """
    Preparation for creating the reaction bubbles

    :param bubble_array: [dict()]
    :param index: int
    :param application_url: String
    :param step: String
    :param db_user: User
    :param lang: Language.ui_locales
    :param splitted_history:
    :param url: String
    :return: None
    """
    logger('history_handler', str(index) + ': reaction case -> ' + step)
    bubbles = get_bubble_from_reaction_step(step, db_user, lang, splitted_history, url)
    if bubbles and not bubbles_already_last_in_list(bubble_array, bubbles):
        bubble_array += bubbles
Ejemplo n.º 6
0
def __prepare_support_step(bubble_array: List[dict], index: int, step: str, db_user: User, lang: str) -> None:
    """
    Preparation for creating the support bubbles

    :param bubble_array: [dict()]
    :param index: int
    :param step: String
    :param db_user: User
    :param lang: Language.ui_locales
    :return: None
    """
    LOG.debug("%s: support case -> %s", index, step)
    steps = step.split('/')
    if len(steps) < 3:
        return
    user_uid = int(steps[1])
    system_uid = int(steps[2])

    bubble = __get_bubble_from_support_step(user_uid, system_uid, db_user, lang)
    if bubble and not bubbles_already_last_in_list(bubble_array, bubble):
        bubble_array += bubble
Ejemplo n.º 7
0
def __prepare_support_step(bubble_array, index, step, nickname, lang):
    """
    Preparation for creating the support bubbles

    :param bubble_array: [dict()]
    :param index: int
    :param step: String
    :param nickname: User.nickname
    :param lang: Language.ui_locales
    :param application_url: String
    :return: None
    """
    logger('history_handler', str(index) + ': support case -> ' + step)
    steps = step.split('/')
    if len(steps) < 3:
        return
    user_uid = steps[1]
    system_uid = steps[2]

    bubble = __get_bubble_from_support_step(user_uid, system_uid, nickname, lang)
    if bubble and not bubbles_already_last_in_list(bubble_array, bubble):
        bubble_array += bubble
Ejemplo n.º 8
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.º 9
0
    def get_dict_for_justify_argument(self, uid, is_supportive, attack):
        """
        Prepares the discussion dict with all bubbles for a step in discussion,
        where the user justifies his attack she has done.

        :param uid: Argument.uid
        :param is_supportive: Boolean
        :param attack: String (undermine, support, undercut, rebut, ...)
        :return: dict()
        """
        LOG.debug("Entering get_dict_for_justify_argument")
        _tn = Translator(self.lang)
        bubbles_array = history_handler.create_bubbles(self.history,
                                                       self.nickname,
                                                       self.lang, self.slug)
        add_premise_text = ''
        save_statement_url = 'set_new_premises_for_argument'

        db_argument = DBDiscussionSession.query(Argument).get(uid)
        if not db_argument:
            return {
                'bubbles': bubbles_array,
                'add_premise_text': add_premise_text,
                'save_statement_url': save_statement_url,
                'mode': '',
                'broke_limit': self.broke_limit
            }

        confrontation = get_text_for_argument_uid(uid)
        premise = db_argument.get_premisegroup_text()
        conclusion = get_text_for_conclusion(db_argument,
                                             is_users_opinion=False)

        if db_argument.conclusion_uid is None:
            conclusion = start_with_small(conclusion)

        while premise.endswith(('.', '?', '!')):
            premise = premise[:-1]
        while conclusion.endswith(('.', '?', '!')):
            conclusion = premise[:-1]

        redirect_from_jump = 'jump/' in self.history.split('-')[-1]
        user_msg, sys_msg = get_header_for_users_confrontation_response(
            db_argument,
            self.lang,
            premise,
            attack,
            conclusion,
            False,
            is_supportive,
            self.nickname,
            redirect_from_jump=redirect_from_jump)

        add_premise_text = self.__get_add_premise_text_for_justify_argument(
            confrontation, premise, attack, conclusion, db_argument,
            is_supportive, user_msg)
        start = '<{} data-argumentation-type="position">'.format(tag_type)
        end = '</{}>'.format(tag_type)
        user_msg = user_msg.format(start, end)

        pro_tag = '<{} class="text-success">'.format(tag_type)
        con_tag = '<{} class="text-danger">'.format(tag_type)
        end_tag = '</{}>'.format(tag_type)

        if attack == Relations.UNDERCUT:
            sys_msg = _tn.get(
                _.whatIsYourMostImportantReasonForArgument).rstrip().format(
                    pro_tag, end_tag) + ': '
            dot = '.'
        else:
            dot = '?'
            if attack == Relations.UNDERMINE:
                sys_msg = _tn.get(
                    _.whatIsYourMostImportantReasonAgainstStatement).rstrip(
                    ).format(con_tag, end_tag)
                sys_msg += ', ' if self.lang == 'de' else ' '
            else:
                sys_msg = _tn.get(_.whatIsYourMostImportantReasonForStatement
                                  ).rstrip().format(pro_tag, end_tag) + ': '

        sys_msg += user_msg + dot + '<br>' + _tn.get(_.because) + '...'

        self.__append_now_bubble(bubbles_array)
        sys_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                              content=sys_msg,
                                              omit_bubble_url=True,
                                              lang=self.lang)
        if not bubbles_already_last_in_list(bubbles_array, sys_bubble):
            bubbles_array.append(sys_bubble)

        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'attack_type': attack,
            'arg_uid': uid,
            'broke_limit': self.broke_limit
        }
Ejemplo n.º 10
0
    def get_dict_for_justify_statement(self, db_statement: Statement, slug,
                                       is_supportive, count_of_items,
                                       db_user: User):
        """
        Prepares the discussion dict with all bubbles for the third step in discussion,
        where the user justifies his position.

        :param db_statement: Statement
        :param db_user: User
        :param slug: Issue.slug
        :param is_supportive: Boolean
        :param count_of_items: Integer
        :return: dict()
        """
        LOG.debug("Entering get_dict_for_justify_statement")
        _tn = Translator(self.lang)

        bubbles_array = history_handler.create_bubbles(self.history,
                                                       self.nickname,
                                                       self.lang, self.slug)

        save_statement_url = 'set_new_start_statement'
        text = db_statement.get_text()
        if not text:
            return None

        tag_start = '<{} data-argumentation-type="position">'.format(tag_type)
        tag_end = '</{}>'.format(tag_type)

        # system bubble
        system_question = get_system_bubble_text_for_justify_statement(
            is_supportive, _tn, tag_start, text, tag_end)

        # user bubble
        nickname = db_user.nickname if db_user and db_user.nickname != nick_of_anonymous_user else None
        user_text, add_premise_text = get_user_bubble_text_for_justify_statement(
            db_statement.uid, db_user, is_supportive, _tn)

        question_bubble = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                                   content=system_question,
                                                   omit_bubble_url=True,
                                                   lang=self.lang)
        url = UrlManager(slug).get_url_for_statement_attitude(db_statement.uid)
        select_bubble = create_speechbubble_dict(
            BubbleTypes.USER,
            bubble_url=url,
            content=user_text,
            omit_bubble_url=False,
            statement_uid=db_statement.uid,
            is_supportive=is_supportive,
            db_user=db_user,
            lang=self.lang)

        if not bubbles_already_last_in_list(bubbles_array, select_bubble):
            bubbles_array.append(select_bubble)

        self.__append_now_bubble(bubbles_array)

        if not bubbles_already_last_in_list(bubbles_array, question_bubble):
            bubbles_array.append(question_bubble)

        if not self.nickname and count_of_items == 1:
            _t = Translator(self.lang)
            db_user = DBDiscussionSession.query(User).filter_by(
                nickname=nickname).first()
            msg_dict = {
                'm': _.voteCountTextFirstM,
                'f': _.voteCountTextFirstF,
                'n': _.voteCountTextFirst,
            }

            if db_user:
                msg = msg_dict[db_user.gender]
            else:
                msg = _.voteCountTextFirst

            msg = _t.get(msg) + '.'

            bubbles_array.append(
                create_speechbubble_dict(BubbleTypes.INFO,
                                         uid='now_first',
                                         content=msg +
                                         _tn.get(_.onlyOneItemWithLink),
                                         omit_bubble_url=True,
                                         lang=self.lang))
        return {
            'bubbles': bubbles_array,
            'add_premise_text': add_premise_text,
            'save_statement_url': save_statement_url,
            'mode': '',
            'is_supportive': is_supportive,
            'broke_limit': self.broke_limit
        }