示例#1
0
def get_user_with_same_opinion_for_argument(argument_uid, db_user, lang, main_page):
    """
    Returns nested dictionary with all kinds of information about the votes of the argument.

    :param argument_uid: Argument.uid
    :param db_user: User
    :param lang: language
    :param main_page: url
    :return: {'users':[{nickname1.avatar_url, nickname1.vote_timestamp}*]}
    """
    try:
        text = get_text_for_argument_uid(argument_uid, 'de')
        LOG.debug("Argument %s: %s", argument_uid, text)
        if not text:
            return {'uid': None, 'text': None, 'message': None, 'users': None, 'seen_by': None}
    except TypeError:
        return {'uid': None, 'text': None, 'message': None, 'users': None, 'seen_by': None}

    opinions = dict()
    all_users = []
    _t = Translator(lang)
    text = get_text_for_argument_uid(argument_uid, lang)
    title = _t.get(_.reactionFor) + ': ' + start_with_capital(text)

    db_argument = DBDiscussionSession.query(Argument).get(argument_uid)
    if not db_argument:
        opinions = {'uid': None, 'text': None, 'message': None, 'users': None, 'seen_by': None}

    opinions['uid'] = str(argument_uid)
    text = get_text_for_argument_uid(argument_uid, lang)
    opinions['text'] = start_with_capital(text)

    db_clicks = DBDiscussionSession.query(ClickedArgument).filter(ClickedArgument.argument_uid == argument_uid,
                                                                  ClickedArgument.is_up_vote == True,
                                                                  ClickedArgument.is_valid == True,
                                                                  ClickedArgument.author_uid != db_user.uid).all()

    for vote in db_clicks:
        voted_user = DBDiscussionSession.query(User).get(vote.author_uid)
        users_dict = create_users_dict(voted_user, vote.timestamp, main_page, lang)
        all_users.append(users_dict)
    opinions['users'] = all_users
    opinions['message'] = __get_text_for_clickcount(len(db_clicks), db_user.uid, _t)

    db_seen_by = DBDiscussionSession.query(SeenArgument).filter_by(argument_uid=int(argument_uid)).all()
    opinions['seen_by'] = len(db_seen_by) if db_seen_by else 0

    return {'opinions': opinions, 'title': start_with_capital(title)}
示例#2
0
def __get_reviews_from_history_queue(main_page, db_user, translator, is_executed=False):
    """

    :param main_page: Host URL
    :param db_user: User
    :param translator: Translator
    :param is_executed: Boolean
    :return: dict()
    """
    past_decision = []
    for key in review_queues:
        review_table = get_review_model_by_key(key)
        executed_list = __get_executed_reviews_of(key, main_page, review_table, translator, is_executed)
        past_decision.append({
            'title': start_with_capital(key) + ' Queue',
            'icon': reputation_icons[key],
            'queue': key,
            'content': executed_list,
            'has_reason': key in [key_delete],
            'has_oem_text': key in [key_edit, key_merge, key_split],
            'has_duplicate_text': key in [key_duplicate]
        })

    return {
        'has_access': is_executed and __has_access_to_history(db_user),
        'is_history': is_executed,
        'past_decision': past_decision
    }
示例#3
0
def get_user_with_same_opinion_for_premisegroups_of_args(
        argument_uids, db_user, lang, main_page):
    """
    Returns nested dictionary with all kinds of information about the votes of the premisegroups.

    :param argument_uids: [Argument.uid]
    :param db_user: User
    :param lang: language
    :param main_page: url
    :return: {'users':[{nickname1.avatar_url, nickname1.vote_timestamp}*]}
    """
    LOG.debug("Arguments %s", argument_uids)

    opinions = []
    _t = Translator(lang)
    title = _t.get(_.relativePopularityOfStatements)
    for arg_uid in argument_uids:
        db_argument = DBDiscussionSession.query(Argument).get(arg_uid)
        db_premises = DBDiscussionSession.query(Premise).filter_by(
            premisegroup_uid=db_argument.premisegroup_uid).all()
        if db_premises:
            opinions.append(
                get_user_with_same_opinion_for_premisegroups_of_arg(
                    db_argument, db_premises, db_user, lang, main_page))

    return {'opinions': opinions, 'title': start_with_capital(title)}
示例#4
0
    def test_get_text_for_add_premise_container(self):
        _t = Translator('en')

        for is_supportive in [True, False]:
            confrontation = start_with_capital(self.confrontation)
            undermine = _t.get(_.itIsFalseThat) + ' ' + self.premise
            support = _t.get(_.itIsTrueThat) if is_supportive else _t.get(
                _.itIsFalseThat)
            support += ' ' + self.conclusion + ' '
            support += _t.get(_.hold) if is_supportive else _t.get(
                _.doesNotHold)
            undercut = confrontation + ', ' + _t.get(
                _.butIDoNotBelieveCounterFor).format(self.conclusion)
            rebut = confrontation + ' '
            rebut += _t.get(_.iAcceptCounterThat) if is_supportive else _t.get(
                _.iAcceptArgumentThat)
            rebut += ' ' + self.conclusion

            results = {
                Relations.UNDERMINE: undermine + ' ...',
                Relations.SUPPORT: support + ' ...',
                Relations.UNDERCUT: undercut + ' ...',
                Relations.REBUT: rebut + ' ...',
                '': '',
            }

            for r in results:
                self.assertEqual(
                    results[r],
                    tg.get_text_for_add_premise_container(
                        'en', self.confrontation, self.premise, r,
                        self.conclusion, is_supportive))
示例#5
0
    def __get_dict_for_argumentation_end(self, argument_uid: int,
                                         user_changed_opinion: bool,
                                         db_user: User) -> dict:
        """
        Returns a special dict() when the discussion ends during an argumentation

        :param argument_uid: Argument.uid
        :param user_changed_opinion:  Boolean
        :param db_user: User
        :return: String, String, String
        """
        nickname = db_user.nickname if db_user and db_user.nickname != nick_of_anonymous_user else None
        _tn = Translator(self.lang)
        text = get_text_for_argument_uid(
            argument_uid,
            user_changed_opinion=user_changed_opinion,
            minimize_on_undercut=True,
            nickname=nickname)
        user_text = start_with_capital(text)
        sys_text = _tn.get(_.otherParticipantsDontHaveCounterForThat) + '.'
        trophy = '<i class="fa fa-trophy" aria-hidden="true"></i>'
        mid_text = '{} {} {} <br>{}'.format(
            trophy, _tn.get(_.congratulation), trophy,
            _tn.get(_.discussionCongratulationEnd))

        if nickname is not None:
            mid_text += _tn.get(_.discussionEndLinkTextWithQueueLoggedIn)
        else:
            mid_text += _tn.get(_.discussionEndLinkTextWithQueueNotLoggedIn)

        return {'user': user_text, 'mid': mid_text, 'sys': sys_text}
示例#6
0
def get_system_bubble_text_for_justify_statement(is_supportive, _tn, tag_start,
                                                 text, tag_end):
    """
    Returns system text for a bubble when the user has to justify a statement and text for the add-position-container

    :param is_supportive: Boolean
    :param _tn: Translator
    :param tag_start: String
    :param text: String
    :param tag_end: String
    :return: String
    """
    if _tn.get_lang() == 'de':
        if is_supportive:
            question = _tn.get(_.whatIsYourMostImportantReasonWhyForInColor)
        else:
            question = _tn.get(
                _.whatIsYourMostImportantReasonWhyAgainstInColor)
    else:
        question = _tn.get(_.whatIsYourMostImportantReasonWhyFor)

    question += ' ' + tag_start + text + tag_end

    if _tn.get_lang() != 'de':
        question += ' ' + _tn.get(
            _.holdsInColor if is_supportive else _.isNotAGoodIdeaInColor)
    because = start_with_capital(_tn.get(_.because)) + '...'
    question += '? <br>' + because

    return question
示例#7
0
def pretty_print_options(message):
    """
    Some modifications for pretty printing.
    Use uppercase for first letter in text and a single dot for the end if there isn't one already.

    :param message: String
    :return:  String
    """

    # check for html
    if message[0:1] == '<':
        pos = message.index('>')
        message = message[0:pos + 1] + message[pos + 1:pos +
                                               2].upper() + message[pos + 2:]
    else:
        message = start_with_capital(message)

    # check for html
    if message[-1] == '>':
        pos = message.rfind('<')
        if message[pos - 1] not in ['.', '?', '!']:
            message = message[0:pos] + '.' + message[pos:]
    elif not message.endswith(tuple(['.', '?', '!'])) and id != 'now':
        message += '.'

    return message
示例#8
0
def get_title_by_key(key: str):
    """
    Get the title of a queue page

    :param key:
    :return:
    """
    return _.get_key_by_string(_.queue.value + start_with_capital(key))
示例#9
0
def get_user_bubble_text_for_justify_statement(stmt_uid, db_user,
                                               is_supportive, _tn):
    """
    Returns user text for a bubble when the user has to justify a statement and text for the add-position-container

    :param stmt_uid: Statement.uid
    :param db_user: User
    :param is_supportive: Boolean
    :param _tn: Translator
    :return: String, String
    """
    LOG.debug("%s is supportive? %s", stmt_uid, is_supportive)
    statement = DBDiscussionSession.query(Statement).get(stmt_uid)
    text = statement.get_text()

    if _tn.get_lang() == 'de':
        intro = _tn.get(_.itIsTrueThat if is_supportive else _.itIsFalseThat)
        add_premise_text = start_with_capital(intro) + ' ' + text
    else:
        add_premise_text = start_with_capital(text) + ' ' + _tn.get(
            _.holds if is_supportive else _.isNotAGoodIdea).strip()
    add_premise_text += ', ...'

    is_users_opinion = False
    if db_user:
        db_marked_statement = DBDiscussionSession.query(
            MarkedStatement).filter(
                MarkedStatement.statement_uid == stmt_uid,
                MarkedStatement.author_uid == db_user.uid).first()
        is_users_opinion = db_marked_statement is not None

    if is_users_opinion:
        intro = _tn.get(_.youHaveTheOpinionThat)
        outro = '' if is_supportive else ', ' + _tn.get(_.isNotAGoodIdea)
        text = intro.format(text) + outro

        return text, add_premise_text

    if is_supportive:
        intro = _tn.get(_.youAgreeWith) if _tn.get_lang() == 'de' else '{}'
    else:
        intro = _tn.get(_.youDisagreeWith)
    text = intro.format(text)

    return text, add_premise_text
示例#10
0
def __get_text_for_add_something(nickname, lang, url, keyword, for_html=True):
    nl = '<br>' if for_html else '\n'
    _t = Translator(lang)
    intro = _t.get(keyword).format(nickname)
    clickForMore = start_with_capital(_t.get(_.clickForMore))
    if for_html:
        url = f'{get_global_url()}/discuss{url}'
        url = f'<a href="{url}">{clickForMore}</a>'
    else:
        url = get_global_url() + '/discuss' + url
    return f'{intro}{nl}{clickForMore}: {url}'
示例#11
0
def get_user_and_opinions_for_argument(argument_uid, db_user, lang, main_page,
                                       path):
    """
    Returns nested dictionary with all kinds of attacks for the argument as well as the users who are supporting
    these attacks.

    :param argument_uid: Argument.uid
    :param db_user: User
    :param lang: current language
    :param main_page: main_page
    :param path: path
    :return: { 'attack_type': { 'message': 'string', 'users': [{'nickname': 'string', 'avatar_url': 'url'
               'vote_timestamp': 'string' ], ... }],...}
    """

    LOG.debug("Argument %s, nickname %s", argument_uid, db_user.nickname)

    # preparation
    _t = Translator(lang)
    title = _t.get(_.attitudesOfOpinions)

    # getting uids of all reactions
    arg_uids_for_reactions = [
        get_undermines_for_argument_uid(argument_uid),
        get_supports_for_argument_uid(argument_uid),
        get_undercuts_for_argument_uid(argument_uid),
        get_rebuts_for_argument_uid(argument_uid)
    ]

    # get gender of counter use
    db_supporter = get_author_or_first_supporter_of_element(
        argument_uid, db_user.uid, True)
    gender = 'n'
    if db_supporter:
        gender = db_supporter.gender

    if re.search(r'/%s/?$' % Attitudes.DONT_KNOW, path.split('?')[0]):
        relation_text = get_relation_text_dict_with_substitution(
            lang, False, is_dont_know=True, gender=gender)
    else:
        relation_text = get_relation_text_dict_with_substitution(lang,
                                                                 True,
                                                                 gender=gender)

    # getting votes for every reaction
    ret_list = __get_clicks_for_reactions(arg_uids_for_reactions,
                                          relation_text, db_supporter, _t,
                                          main_page)

    return {'opinions': ret_list, 'title': start_with_capital(title)}
示例#12
0
    def __get_queue_information(self, queue_name: str):
        """
        Returns some information of the current queue

        :param queue_name: name of the queue
        :return:
        """
        last_reviewer = get_last_reviewer_by_key(queue_name)
        table = get_review_model_by_key(queue_name)
        task_count = get_review_count_for(table, last_reviewer, self.db_user)
        count, all_rights = get_reputation_of(self.db_user)
        visit_key_str = _.get_key_by_string('visit{}Queue'.format(
            start_with_capital(queue_name)))
        visit_limit_key_str = _.get_key_by_string(
            'visit{}QueueLimitation'.format(start_with_capital(queue_name)))
        return {
            'task_name':
            self.translator.get(get_title_by_key(queue_name)),
            'id':
            queue_name,
            'url':
            f'{self.application_url}/review/{queue_name}',
            'icon':
            reputation_icons[queue_name],
            'task_count':
            task_count,
            'is_allowed':
            count >= reputation_borders[queue_name] or all_rights,
            'is_allowed_text':
            self.translator.get(visit_key_str),
            'is_not_allowed_text':
            self.translator.get(visit_limit_key_str).format(
                str(reputation_borders[queue_name])),
            'last_reviews':
            self.__get_last_reviewer_of(last_reviewer, self.application_url)
        }
示例#13
0
def get_text_for_add_premise_container(lang, confrontation, premise,
                                       attack_type, conclusion, is_supportive):
    """
    Based on the users reaction, text will be build. This text can be used for the container where users can
    add their statements

    :param lang: ui_locales
    :param confrontation: chosen confrontation
    :param premise: current premise
    :param attack_type: type of the attack
    :param conclusion: current conclusion
    :param is_supportive: boolean
    :return: string
    """
    _t = Translator(lang)

    while premise[-1] in ['.', ' ']:
        premise = premise[:-1]

    while conclusion[-1] in ['.', ' ']:
        conclusion = premise[:-1]

    confrontation = start_with_capital(confrontation)

    # different cases
    if attack_type == Relations.UNDERMINE:
        return '{} {} ...'.format(_t.get(_.itIsFalseThat), premise)

    elif attack_type == Relations.SUPPORT:
        intro = _t.get(_.itIsFalseThat)
        outro = _t.get(_.doesNotHold)
        if is_supportive:
            intro = _t.get(_.itIsTrueThat)
            outro = _t.get(_.hold)
        return '{} {} {} ...'.format(intro, conclusion, outro)

    elif attack_type == Relations.UNDERCUT:
        return '{}, {} ...'.format(
            confrontation,
            _t.get(_.butIDoNotBelieveCounterFor).format(conclusion))

    elif attack_type == Relations.REBUT:
        mid = _t.get(_.iAcceptCounterThat) if is_supportive else _t.get(
            _.iAcceptArgumentThat)
        return '{} {} {} ...'.format(confrontation, mid, conclusion)

    else:
        return ''
示例#14
0
def get_all_infos_about_argument(db_argument: Argument, main_page, db_user,
                                 lang) -> dict:
    """
    Returns bunch of information about the given argument

    :param db_argument: The argument
    :param main_page: url of the application
    :param db_user: User
    :param lang: Language
    :rtype: dict
    :return: dictionary with many information or an error
    """
    _t = Translator(lang.ui_locales)

    return_dict = dict()
    db_votes = DBDiscussionSession.query(ClickedArgument).filter(
        ClickedArgument.argument_uid == db_argument.uid,
        ClickedArgument.is_valid == True,
        ClickedStatement.is_up_vote == True).all()

    db_author = DBDiscussionSession.query(User).get(db_argument.author_uid)
    return_dict['vote_count'] = str(len(db_votes))
    return_dict['author'] = db_author.global_nickname
    return_dict['author_url'] = main_page + '/user/' + str(db_author.uid)
    return_dict['gravatar'] = get_profile_picture(db_author)
    return_dict['timestamp'] = sql_timestamp_pretty_print(
        db_argument.timestamp, db_argument.lang)
    text = get_text_for_argument_uid(db_argument.uid)
    return_dict['text'] = start_with_capital(text)

    supporters = []
    gravatars = dict()
    public_page = dict()
    for vote in db_votes:
        db_author = DBDiscussionSession.query(User).get(vote.author_uid)
        name = db_author.global_nickname
        if db_user.nickname == db_author.nickname:
            name += ' (' + _t.get(_.itsYou) + ')'
        supporters.append(name)
        gravatars[name] = get_profile_picture(db_author)
        public_page[name] = main_page + '/user/' + str(db_author.uid)

    return_dict['supporter'] = supporters
    return_dict['gravatars'] = gravatars
    return_dict['public_page'] = public_page

    return return_dict
示例#15
0
def get_user_with_opinions_for_attitude(statement_uid, db_user, lang,
                                        main_page):
    """
    Returns dictionary with agree- and disagree-votes

    :param statement_uid: Statement.uid
    :param db_user: User
    :param lang: language
    :param main_page: url
    :return:
    """

    LOG.debug("Statement %s", statement_uid)
    db_statement = DBDiscussionSession.query(Statement).get(
        statement_uid) if statement_uid else None
    _t = Translator(lang)
    title = _t.get(_.agreeVsDisagree)

    if not db_statement:
        empty_dict = {'users': [], 'text': None, 'message': ''}
        return {
            'text': None,
            'agree': empty_dict,
            'disagree': empty_dict,
            'title': title
        }

    text = db_statement.get_text()
    title += ' ' + text

    ret_dict = dict()
    ret_dict['text'] = start_with_capital(text)
    ret_dict['agree'] = None
    ret_dict['disagree'] = None
    ret_dict['title'] = title

    agree_dict = __collect_pro_clicks(statement_uid, db_user.uid, main_page,
                                      _t)
    disagree_dict = __collect_con_clicks(statement_uid, db_user.uid, main_page,
                                         _t)
    ret_dict['agree'] = agree_dict
    ret_dict['disagree'] = disagree_dict

    db_seen_by = DBDiscussionSession.query(SeenStatement).filter_by(
        statement_uid=int(statement_uid)).all()
    ret_dict['seen_by'] = len(db_seen_by) if db_seen_by else 0
    return ret_dict
示例#16
0
def get_information_of(db_user: User, lang):
    """
    Returns public information of the given user

    :param db_user: User
    :param lang: ui_locales
    :return: dict()
    """
    if db_user.nickname == nick_of_anonymous_user:
        return __get_special_infos(lang)
    db_group = DBDiscussionSession.query(Group).get(db_user.group_uid)
    ret_dict = dict()
    ret_dict['public_nick'] = db_user.global_nickname
    ret_dict['last_action'] = sql_timestamp_pretty_print(
        db_user.last_action, lang)
    ret_dict['last_login'] = sql_timestamp_pretty_print(
        db_user.last_login, lang)
    ret_dict['registered'] = sql_timestamp_pretty_print(
        db_user.registered, lang)
    ret_dict['group'] = start_with_capital(db_group.name)

    ret_dict['is_male'] = db_user.gender == 'm'
    ret_dict['is_female'] = db_user.gender == 'f'
    ret_dict['is_neutral'] = db_user.gender != 'm' and db_user.gender != 'f'

    arg_votes, stat_votes = get_mark_count_of(db_user, False)
    db_reviews_duplicate = DBDiscussionSession.query(
        ReviewDuplicate).filter_by(detector_uid=db_user.uid).all()
    db_reviews_edit = DBDiscussionSession.query(ReviewEdit).filter_by(
        detector_uid=db_user.uid).all()
    db_reviews_delete = DBDiscussionSession.query(ReviewDelete).filter_by(
        detector_uid=db_user.uid).all()
    db_reviews_optimization = DBDiscussionSession.query(
        ReviewOptimization).filter_by(detector_uid=db_user.uid).all()
    db_reviews = db_reviews_duplicate + db_reviews_edit + db_reviews_delete + db_reviews_optimization

    get_tv_dict = get_textversions(db_user, lang)
    ret_dict['statements_posted'] = len(get_tv_dict.get('statements', []))
    ret_dict['edits_done'] = len(get_tv_dict.get('edits', []))
    ret_dict['reviews_proposed'] = len(db_reviews)
    ret_dict['discussion_arg_votes'] = arg_votes
    ret_dict['discussion_stat_votes'] = stat_votes
    ret_dict['avatar_url'] = get_profile_picture(db_user, 120)
    ret_dict['discussion_stat_rep'], trash = get_reputation_of(db_user)

    return ret_dict
示例#17
0
def __build_val_for_jump(db_argument, tag_premise, tag_conclusion, tag_end, _t):
    premises = db_argument.get_premisegroup_text()
    if premises[-1] != '.':
        premises += '.'
    conclusion = db_argument.get_conclusion_text()

    because = _t.get(_.because).lower()
    conclusion = tag_conclusion + conclusion + tag_end
    premises = tag_premise + premises + tag_end

    intro = (start_con + _t.get(_.isNotRight).lower() + end_tag) if not db_argument.is_supportive else ''
    ret_value = '{} {} {} {}'.format(conclusion, intro, because, premises)
    if _t.get_lang() == 'de':
        intro = _t.get(_.itIsTrueThatAnonymous) if db_argument.is_supportive else _t.get(_.itIsFalseThatAnonymous)
        intro = start_with_capital(intro)
        intro = (start_pro if db_argument.is_supportive else start_con) + intro + end_tag
        ret_value = '{} {}, {} {}'.format(intro, conclusion, because, premises)

    return ret_value
示例#18
0
def get_information_of(user: User, lang: str) -> Dict[str, Any]:
    """
    Returns public information of the given user.

    :param user: User whose information is queried.
    :param lang: Language-string representing language of the answer.
    :return: A dictionary containing the public information.
    """
    if user.nickname == nick_of_anonymous_user:
        return _get_special_infos(lang)
    ret_dict = dict()
    ret_dict['public_nick'] = user.global_nickname
    ret_dict['last_action'] = sql_timestamp_pretty_print(
        user.last_action, lang)
    ret_dict['last_login'] = sql_timestamp_pretty_print(user.last_login, lang)
    ret_dict['registered'] = sql_timestamp_pretty_print(user.registered, lang)
    ret_dict['group'] = start_with_capital(user.group.name)

    ret_dict['is_male'] = user.gender == 'm'
    ret_dict['is_female'] = user.gender == 'f'
    ret_dict['is_neutral'] = user.gender != 'm' and user.gender != 'f'

    arg_votes, stat_votes = get_mark_count_of(user, False)
    db_reviews_duplicate = DBDiscussionSession.query(
        ReviewDuplicate).filter_by(detector_uid=user.uid).all()
    db_reviews_edit = DBDiscussionSession.query(ReviewEdit).filter_by(
        detector_uid=user.uid).all()
    db_reviews_delete = DBDiscussionSession.query(ReviewDelete).filter_by(
        detector_uid=user.uid).all()
    db_reviews_optimization = DBDiscussionSession.query(
        ReviewOptimization).filter_by(detector_uid=user.uid).all()
    db_reviews = db_reviews_duplicate + db_reviews_edit + db_reviews_delete + db_reviews_optimization

    get_tv_dict = get_textversions(user, lang)
    ret_dict['statements_posted'] = len(get_tv_dict.get('statements', []))
    ret_dict['edits_done'] = len(get_tv_dict.get('edits', []))
    ret_dict['reviews_proposed'] = len(db_reviews)
    ret_dict['discussion_arg_votes'] = arg_votes
    ret_dict['discussion_stat_votes'] = stat_votes
    ret_dict['avatar_url'] = get_profile_picture(user, 120)
    ret_dict['discussion_stat_rep'], _ = get_reputation_of(user)

    return ret_dict
示例#19
0
    def __get_add_premise_text_for_justify_argument(self, confrontation,
                                                    premise, attack,
                                                    conclusion, db_argument,
                                                    is_supportive,
                                                    user_msg) -> str:
        """
        Returns the text fot the add premise container during the justification for an argument

        :param confrontation: String
        :param premise: String
        :param attack: String
        :param conclusion: String
        :param db_argument: Argument
        :param is_supportive: Boolean
        :param user_msg: String
        :return: String
        """
        if attack == Relations.UNDERMINE:
            add_premise_text = get_text_for_add_premise_container(
                self.lang, confrontation, premise, attack, conclusion,
                db_argument.is_supportive)
            add_premise_text = start_with_capital(add_premise_text)

        elif attack == Relations.SUPPORT:
            is_supportive = not is_supportive
            # when the user rebuts a system confrontation, he attacks his own negated premise, therefore he supports
            # is own premise. so his premise is the conclusion and we need new premises ;-)
            add_premise_text = get_text_for_add_premise_container(
                self.lang, confrontation, premise, attack, conclusion,
                is_supportive)

        elif attack == Relations.UNDERCUT:
            add_premise_text = user_msg.format('', '') + ', ' + '...'

        else:
            add_premise_text = get_text_for_add_premise_container(
                self.lang, confrontation, premise, attack, conclusion,
                db_argument.is_supportive)

        return add_premise_text
示例#20
0
def get_text_for_message(nickname, lang, path, message_content, for_html=True) -> str:
    """
    This method creates a message used for example in mails or messages.

    :param nickname: The nickname of the addressed user
    :param lang: The language to be used in the email
    :param path: The url for the user where he can find the changes
    :param message_content: The key variable which will be translated into a message
    :param for_html: A boolean to determine if the Message should contain a clickable link
    :return: A Message addressed to a user which can contain a clickable or non-clickable link
    """
    _t = Translator(lang)
    intro = _t.get(message_content).format(nickname)
    clickForMore = start_with_capital(_t.get(_.clickForMore))
    dbas_url = get_global_url()
    message_appendix_auto_generated = _t.get(_.emailBodyText).format(dbas_url)
    abs_path = f'{dbas_url}/discuss{path}'

    link = f'<a href="{abs_path}">{clickForMore}</a>' if for_html else abs_path
    msg = f'{intro}\n\n{link}\n\n---\n\n{message_appendix_auto_generated}'

    return msg.replace("\n", "<br>") if for_html else msg
示例#21
0
def get_user_with_same_opinion_for_statements(statement_uids, is_supportive, db_user, lang, main_page):
    """
    Returns nested dictionary with all kinds of information about the votes of the statements.

    :param statement_uids: Statement.uids
    :param is_supportive: Boolean
    :param db_user: User
    :param lang: language
    :param main_page: url
    :return: {'users':[{nickname1.avatar_url, nickname1.vote_timestamp}*]}
    """
    LOG.debug("Statement %s (%s)", statement_uids, is_supportive)

    opinions = []
    _t = Translator(lang)
    title = _t.get(_.relativePopularityOfStatements)

    for statement_uid in statement_uids:
        statement_dict = __get_opinions_for_uid(statement_uid, is_supportive, db_user, lang, _t, main_page)
        opinions.append(statement_dict)

    return {'opinions': opinions, 'title': start_with_capital(title)}
示例#22
0
def __get_rebuts_for_arguments_conclusion_uid(db_argument):
    """
    Returns a list with dict(). They contain id and text of the rebuttal's pgroups

    :return argument_uid: UID of the argument
    :param db_argument: Argument
    :return: [dict()]
    """
    return_array = []
    given_rebuts = set()
    db_arguments = get_enabled_arguments_as_query()
    db_rebuts = db_arguments.filter(Argument.is_supportive == (not db_argument.is_supportive),
                                    Argument.conclusion_uid == db_argument.conclusion_uid).all()
    for rebut in db_rebuts:

        if rebut.premisegroup_uid not in given_rebuts:
            given_rebuts.add(rebut.premisegroup_uid)
            tmp_dict = dict()
            tmp_dict['id'] = rebut.uid
            text = rebut.get_premisegroup_text()
            tmp_dict['text'] = start_with_capital(text)
            return_array.append(tmp_dict)
    return return_array
示例#23
0
 def test_start_with_capital(self):
     self.assertEqual(start_with_capital(''), '')
     self.assertEqual(start_with_capital('asd'), 'Asd')
     self.assertEqual(start_with_capital('Asd'), 'Asd')
     self.assertEqual(start_with_capital('ASD'), 'ASD')
示例#24
0
    def __get_dict_for_argumentation(self, user_arg: Argument,
                                     confrontation_arg_uid: int, history: str,
                                     attack: Relations, nickname: str,
                                     is_supportive: bool) -> dict:
        """
        Returns dict() for the reaction step

        :param user_arg: Argument
        :param confrontation_arg_uid:  Argument.uid
        :param history: String
        :param attack: String
        :param nickname: User.nickname
        :param is_supportive: Boolean
        :return: dict()
        """
        premise = user_arg.get_premisegroup_text()
        conclusion = get_text_for_conclusion(user_arg)
        db_confrontation = DBDiscussionSession.query(Argument).get(
            confrontation_arg_uid)
        confr = db_confrontation.get_premisegroup_text()
        sys_conclusion = (db_confrontation.get_conclusion_text())
        if attack == Relations.UNDERMINE:
            if db_confrontation.conclusion_uid != 0:
                premise = db_confrontation.get_conclusion_text()
            else:
                premise = get_text_for_argument_uid(
                    db_confrontation.argument_uid,
                    True,
                    colored_position=True,
                    attack_type=attack)

        # did the user changed his opinion?
        history = history_handler.split(history)
        user_changed_opinion = len(history) > 1 and '/undercut/' in history[-2]

        # argumentation is a reply for an argument, if the arguments conclusion of the user is no position
        conclusion_uid = user_arg.conclusion_uid
        tmp_arg = user_arg
        while not conclusion_uid:
            tmp_arg = DBDiscussionSession.query(Argument).get(
                tmp_arg.argument_uid)
            conclusion_uid = tmp_arg.conclusion_uid

        db_statement = DBDiscussionSession.query(Statement).get(conclusion_uid)
        reply_for_argument = not (db_statement and db_statement.is_position)
        support_counter_argument = 'reaction' in self.history.split('-')[-1]

        current_argument = get_text_for_argument_uid(
            user_arg.uid,
            nickname=nickname,
            with_html_tag=True,
            colored_position=True,
            user_changed_opinion=user_changed_opinion,
            attack_type=attack,
            minimize_on_undercut=True,
            support_counter_argument=support_counter_argument)

        current_argument = start_with_capital(current_argument)
        if self.lang != 'de':
            premise = start_with_small(premise)

        # check for support and build text
        _tn = Translator(self.lang)
        user_text = (_tn.get(_.otherParticipantsConvincedYouThat) +
                     ': ') if user_changed_opinion else ''
        user_text += current_argument if current_argument != '' else premise

        sys_text, gender = get_text_for_confrontation(
            self.lang, nickname, premise, conclusion, sys_conclusion,
            is_supportive, attack, confr, reply_for_argument,
            not user_arg.is_supportive, user_arg, db_confrontation)
        gender_of_counter_arg = gender

        return {
            'user': user_text,
            'sys': sys_text,
            'gender': gender_of_counter_arg,
            'confrontation': db_confrontation
        }
示例#25
0
def __build_nested_argument(arg_array: List[Argument], first_arg_by_user,
                            user_changed_opinion, with_html_tag,
                            start_with_intro, minimize_on_undercut,
                            anonymous_style, premisegroup_by_user, _t):
    """

    :param arg_array:
    :param first_arg_by_user:
    :param user_changed_opinion:
    :param with_html_tag:
    :param start_with_intro:
    :param minimize_on_undercut:
    :param anonymous_style:
    :param premisegroup_by_user:
    :param _t:
    :return:
    """
    # get all pgroups and at last, the conclusion
    pgroups = []
    supportive = []
    arg_array = arg_array[::-1]
    local_lang = arg_array[0].lang

    # grepping all arguments in the chain
    for db_argument in arg_array:
        text = db_argument.get_premisegroup_text()

        pgroups.append(text)
        supportive.append(db_argument.is_supportive)

    conclusion = arg_array[0].get_conclusion_text()

    # html tags for framing
    sb = start_position if with_html_tag else ''
    se = end_tag if with_html_tag else ''

    because = (', ' if local_lang == 'de' else ' ') + _t.get(
        _.because).lower() + ' '

    if len(
            arg_array
    ) % 2 == 0 and not first_arg_by_user and not anonymous_style:  # system starts
        ret_value = _t.get(_.earlierYouArguedThat if user_changed_opinion else
                           _.otherUsersSaidThat) + ' '
        tmp_users_opinion = True  # user after system

    elif not anonymous_style:  # user starts
        ret_value = (_t.get(_.soYourOpinionIsThat) +
                     ': ') if start_with_intro else ''
        tmp_users_opinion = False  # system after user
        conclusion = se + start_with_capital(conclusion)  # pretty print

    else:
        ret_value = _t.get(_.someoneArgued) + ' '
        tmp_users_opinion = False

    tmp = _t.get(_.itFalseIsThat) + ' ' if not supportive[0] else ''
    ret_value += tmp + conclusion + because + pgroups[0] + '.'
    del pgroups[0]

    # just display the last premise group on undercuts, because the story is always saved in all bubbles
    if minimize_on_undercut and not user_changed_opinion and len(pgroups) > 2:
        return _t.get(
            _.butYouCounteredWith).strip() + ' ' + sb + pgroups[len(pgroups) -
                                                                1] + se + '.'

    for i, pgroup in enumerate(pgroups):
        ret_value += ' '
        if tmp_users_opinion and not anonymous_style:
            tmp = _.butYouCounteredWithArgument if premisegroup_by_user else _.butYouCounteredWithInterest
            ret_value += _t.get(_.otherParticipantsConvincedYouThat
                                if user_changed_opinion else tmp)
        elif not anonymous_style:
            ret_value += _t.get(_.youAgreeWithThatNow)
        else:
            ret_value += _t.get(_.otherUsersSaidThat) if i == 0 else _t.get(
                _.thenOtherUsersSaidThat)

        ret_value += sb + ' ' + pgroups[i] + '.'
        tmp_users_opinion = not tmp_users_opinion

    return ret_value.replace('  ', ' ')
示例#26
0
def __create_reaction_history_bubbles(step: str, db_user: User, lang: str,
                                      split_history: list, url: str,
                                      color_steps: bool, uid: int,
                                      additional_uid: int, attack) -> list:
    is_supportive = DBDiscussionSession.query(Argument).get(uid).is_supportive
    last_relation = get_last_relation(split_history)

    user_changed_opinion = len(
        split_history) > 1 and '/undercut/' in split_history[-2]
    support_counter_argument = False

    if step in split_history:
        index = split_history.index(step)
        try:
            support_counter_argument = 'reaction' in split_history[index - 1]
        except IndexError:
            support_counter_argument = False

    color_steps = color_steps and attack != Relations.SUPPORT  # special case for the support round
    current_arg = get_text_for_argument_uid(
        uid,
        user_changed_opinion=user_changed_opinion,
        support_counter_argument=support_counter_argument,
        colored_position=color_steps,
        nickname=db_user.nickname,
        with_html_tag=color_steps)

    db_argument = DBDiscussionSession.query(Argument).get(uid)
    db_confrontation = DBDiscussionSession.query(Argument).get(additional_uid)
    reply_for_argument = True
    if db_argument.conclusion_uid is not None:
        db_statement = DBDiscussionSession.query(Statement).get(
            db_argument.conclusion_uid)
        reply_for_argument = not (db_statement and db_statement.is_position)

    premise = db_argument.get_premisegroup_text()
    conclusion = get_text_for_conclusion(db_argument)
    sys_conclusion = get_text_for_conclusion(db_confrontation)
    confr = db_confrontation.get_premisegroup_text()
    user_is_attacking = not db_argument.is_supportive

    if lang != 'de':
        current_arg = start_with_capital(current_arg)
        if current_arg.startswith('<'):
            pos = current_arg.index('>')
            current_arg = current_arg[0:pos] + current_arg[pos:pos + 1].upper(
            ) + current_arg[pos + 1:]

    premise = start_with_small(premise)

    _tn = Translator(lang)
    user_text = ''
    if last_relation == Relations.SUPPORT:
        user_text = _tn.get(_.otherParticipantsConvincedYouThat) + ': '

    user_text += '<{}>{}</{}>'.format(
        tag_type, current_arg if current_arg != '' else premise, tag_type)

    sys_text, tmp = get_text_for_confrontation(lang,
                                               db_user.nickname,
                                               premise,
                                               conclusion,
                                               sys_conclusion,
                                               is_supportive,
                                               attack,
                                               confr,
                                               reply_for_argument,
                                               user_is_attacking,
                                               db_argument,
                                               db_confrontation,
                                               color_html=False)

    bubble_user = create_speechbubble_dict(BubbleTypes.USER,
                                           bubble_url=url,
                                           content=user_text,
                                           omit_bubble_url=False,
                                           argument_uid=uid,
                                           is_supportive=is_supportive,
                                           db_user=db_user,
                                           lang=lang)
    db_tmp = DBDiscussionSession.query(User).get(db_confrontation.author_uid)
    if not attack:
        bubble_syst = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                               content=sys_text,
                                               omit_bubble_url=True,
                                               db_user=db_user,
                                               lang=lang,
                                               other_author=db_tmp)
    else:
        bubble_syst = create_speechbubble_dict(BubbleTypes.SYSTEM,
                                               uid='question-bubble-' +
                                               str(additional_uid),
                                               content=sys_text,
                                               omit_bubble_url=True,
                                               db_user=db_user,
                                               lang=lang,
                                               other_author=db_tmp)
    return [bubble_user, bubble_syst]