コード例 #1
0
    def prepare_extras_dict(self,
                            current_slug: str,
                            is_reportable: bool,
                            show_bar_icon: bool,
                            show_graph_icon: bool,
                            registry: Registry,
                            application_url: str,
                            path: str,
                            db_user: User,
                            broke_limit=False,
                            add_premise_container_style='display: none',
                            add_statement_container_style='display: none',
                            ongoing_discussion=True):
        """
        Creates the extras.dict() with many options!

        :param current_slug:
        :param is_reportable: Same as discussion.bubbles.last.is_markable, but TAL has no last indicator
        :param show_bar_icon: True, if the discussion space should show the graph icon
        :param show_graph_icon: True, if the discussion space should show the barometer icon
        :param registry: Pyramids registry
        :param application_url: current app url
        :param path: current path
        :param db_user: User
        :param broke_limit: Boolean
        :param add_premise_container_style: style string, default 'display:none;'
        :param add_statement_container_style: style string, default 'display:none;'
        :param ongoing_discussion: Boolean
        :return: dict()
        """
        LOG.debug("Entering prepare_extras_dict")

        is_user_from_ldap = False
        is_logged_in = False
        nickname = None
        public_nickname = None
        is_user_male = False
        is_user_female = False
        is_admin = False
        is_special = False

        if db_user:
            is_user_from_ldap = db_user.validate_password(PW_FOR_LDAP_USER)
            is_logged_in = True
            nickname = db_user.nickname
            public_nickname = db_user.public_nickname
            is_user_male = db_user.gender == 'm'
            is_user_female = db_user.gender == 'f'
            is_admin = db_user.is_admin()
            is_special = db_user.is_special()
            if db_user.nickname == nick_of_anonymous_user:
                db_user = None
                is_logged_in = False

        return_dict = dict()
        return_dict['url'] = get_global_url()
        return_dict['year'] = datetime.datetime.now().year
        return_dict['restart_url'] = current_slug
        return_dict['is_in_discussion'] = 'discuss' in path
        return_dict['logged_in'] = is_logged_in
        return_dict['nickname'] = nickname
        return_dict['public_nickname'] = public_nickname
        return_dict[
            'add_premise_container_style'] = add_premise_container_style
        return_dict[
            'add_statement_container_style'] = add_statement_container_style
        return_dict['users_avatar'] = get_profile_picture(db_user, 25)
        return_dict['ongoing_discussion'] = ongoing_discussion
        return_dict['slug'] = current_slug
        return_dict['is_user_male'] = is_user_male
        return_dict['is_user_female'] = is_user_female
        return_dict['is_user_neutral'] = not return_dict[
            'is_user_male'] and not return_dict['is_user_female']
        return_dict['broke_limit'] = 'true' if broke_limit else 'false'
        return_dict['use_with_ldap'] = is_user_from_ldap
        return_dict['development_mode'] = is_development_mode(registry)
        return_dict['is_development'] = registry.settings.get(
            'mode', '') == 'development'
        return_dict['is_production'] = registry.settings.get(
            'mode', '') == 'production'
        return_dict['review_count'] = get_complete_review_count(db_user)
        return_dict['modern_bubbles'] = usage_of_modern_bubbles(registry)
        return_dict['usage_of_matomo'] = usage_of_matomo(registry)

        self.add_language_options_for_extra_dict(return_dict)
        is_author, points = get_reputation_of(db_user)
        is_author_bool = is_author or points > limit_to_open_issues

        return_dict['is_reportable'] = is_reportable
        return_dict['is_admin'] = is_admin
        return_dict['is_special'] = is_special
        return_dict['is_author'] = is_author_bool
        return_dict['is_user'] = not (is_admin or is_author_bool or is_special)
        return_dict['show_bar_icon'] = show_bar_icon
        return_dict['show_graph_icon'] = show_graph_icon
        return_dict['close_premise_container'] = True
        return_dict['close_statement_container'] = True
        return_dict['date'] = arrow.utcnow().format('DD-MM-YYYY')
        return_dict['count_of'] = {
            'arguments': DBDiscussionSession.query(Argument).count(),
            'users': DBDiscussionSession.query(User).count(),
            'discussions': DBDiscussionSession.query(Issue).count(),
            'reviews': get_count_of_all(),
        }
        self.__add_title_text(return_dict, is_logged_in)
        self.__add_button_text(return_dict)
        self.__add_tag_text(return_dict)
        self.__add_login_button_properties(return_dict)

        message_dict = dict()
        message_dict['new_count'] = count_of_new_notifications(
            db_user) if db_user else 0
        message_dict['has_unread'] = message_dict['new_count'] > 0
        inbox = get_box_for(db_user, self.system_lang, application_url,
                            True) if db_user else []
        outbox = get_box_for(db_user, self.system_lang, application_url,
                             False) if db_user else []
        message_dict['inbox'] = inbox
        message_dict['outbox'] = outbox
        message_dict['total_in'] = len(inbox)
        message_dict['total_out'] = len(outbox)
        return_dict['notifications'] = message_dict

        return return_dict
コード例 #2
0
def create_speechbubble_dict(bubble_type: BubbleTypes,
                             is_markable: bool = False,
                             is_author: bool = False,
                             uid: str = '',
                             bubble_url: str = '',
                             content: str = '',
                             omit_bubble_url: bool = False,
                             omit_vote_info: bool = False,
                             argument_uid: int = None,
                             statement_uid: int = None,
                             is_supportive: bool = False,
                             db_user: User = None,
                             lang: str = 'en',
                             is_users_opinion: bool = False,
                             other_author: User = None):
    """
    Creates an dictionary which includes every information needed for a bubble.

    :param bubble_type: BubbleTypes
    :param is_markable: True if the content itself could be flagged
    :param is_author: True if the current user is author of the content
    :param uid: Identifier for the bubble
    :param bubble_url: URL for the click event of the bubble
    :param content: Text of the bubble
    :param omit_bubble_url: True if the bubble should have a link
    :param omit_vote_info: True if the bubble have the little, grey information text
    :param argument_uid: Argument.uid
    :param statement_uid: Statement.uid
    :param is_supportive: Boolean
    :param db_user: current
    :param omit_bubble_url: Boolean
    :param lang: is_users_opinion
    :param is_users_opinion: Boolean
    :param other_author:
    :return: dict()
    """
    gravatar_link = get_global_url() + '/static/images/icon.png'
    profile = None

    is_enemy_user = {'admin': False, 'author': False, 'special': False}

    if uid != 'now':
        content = pretty_print_options(content)

    if bubble_type is BubbleTypes.SYSTEM and other_author is not None:
        gravatar_link = get_profile_picture(other_author, 25)
        profile = '/user/{}'.format(other_author.uid),
        is_enemy_user['admin'] = other_author.is_admin()
        is_enemy_user['author'] = other_author.is_author()
        is_enemy_user['special'] = other_author.is_special()

    # check for users opinion
    if bubble_type is BubbleTypes.USER and db_user and db_user.nickname != nick_of_anonymous_user:
        db_marked = None
        gravatar_link = get_profile_picture(db_user, 25)
        if argument_uid is not None and db_user is not None:
            db_marked = DBDiscussionSession.query(MarkedArgument).filter(
                MarkedArgument.argument_uid == argument_uid,
                MarkedArgument.author_uid == db_user.uid).first()

        if statement_uid is not None and db_user is not None:
            db_marked = DBDiscussionSession.query(MarkedStatement).filter(
                MarkedStatement.statement_uid == statement_uid,
                MarkedStatement.author_uid == db_user.uid).first()

        is_users_opinion = db_marked is not None

    speech = {
        'is_user':
        bubble_type is BubbleTypes.USER,
        'is_system':
        bubble_type is BubbleTypes.SYSTEM,
        'is_status':
        bubble_type is BubbleTypes.STATUS,
        'is_info':
        bubble_type is BubbleTypes.INFO,
        'is_markable':
        is_markable,
        'is_author':
        is_author,
        'is_enemy_user':
        is_enemy_user,
        'id':
        uid if len(str(uid)) > 0 else uuid4().hex,
        'bubble_url':
        bubble_url,
        'message':
        content,
        'omit_bubble_url':
        omit_bubble_url,
        'omit_vote_info':
        omit_vote_info,
        'data_type':
        'argument'
        if argument_uid else 'statement' if statement_uid else 'None',
        'data_argument_uid':
        argument_uid,
        'data_statement_uid':
        statement_uid,
        'data_is_supportive':
        is_supportive,
        'is_users_opinion':
        is_users_opinion,
        'enemy': {
            'avatar': gravatar_link,
            'profile': profile,
            'available': profile is not None
        }
    }

    votecount_keys = __get_text_for_click_and_mark_count(
        db_user, bubble_type is BubbleTypes.USER, argument_uid, statement_uid,
        speech, lang)

    speech['votecounts_message'] = votecount_keys[speech['votecounts']]

    return speech