Beispiel #1
0
def get_reputation_of(db_user: User, only_today=False):
    """
    Return the total sum of reputation_borders points for the given nickname

    :param db_user: Should be of type "User"
    :param only_today: Boolean
    :return: Integer and Boolean, if the user is author
    """
    if not db_user:
        return 0, False

    db_reputation = DBDiscussionSession.query(ReputationHistory)

    if only_today:
        today = arrow.utcnow().to('Europe/Berlin')
        db_reputation = db_reputation.filter(
            ReputationHistory.timestamp >= today)

    db_reputation = db_reputation.filter_by(reputator_uid=db_user.uid) \
        .join(ReputationReason, ReputationReason.uid == ReputationHistory.reputation_uid) \
        .all()

    count = sum([rep.reputations.points for rep in db_reputation])

    return count, db_user.is_author() or db_user.is_admin()
Beispiel #2
0
def get_reputation_of(db_user: User, only_today=False):
    """
    Return the total sum of reputation_borders points for the given nickname

    :param db_user: Should be of type "User", but also accepts nickname for legacy support
    :param only_today: Boolean
    :return: Integer and Boolean, if the user is author
    """
    if not isinstance(db_user, User):
        db_user = DBDiscussionSession.query(User).filter_by(nickname=db_user).first()
    count = 0

    if not db_user or db_user.nickname == nick_of_anonymous_user:
        return count, False

    db_reputation = DBDiscussionSession.query(ReputationHistory)

    if only_today:
        today = arrow.utcnow().to('Europe/Berlin')
        db_reputation = db_reputation.filter(ReputationHistory.timestamp >= today)

    db_reputation = db_reputation.filter_by(reputator_uid=db_user.uid) \
        .join(ReputationReason, ReputationReason.uid == ReputationHistory.reputation_uid) \
        .all()

    count = sum([r.reputations.points for r in db_reputation])

    return count, db_user.is_author() or db_user.is_admin()
Beispiel #3
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