Пример #1
0
def get_box_for(db_user, lang, main_page, is_inbox):
    """
    Returns all notifications for the user

    :param db_user: User
    :param lang: ui_locales
    :param main_page: URL
    :param is_inbox: Boolean
    :return: [Notification]
    """
    if is_inbox:
        db_messages = DBDiscussionSession.query(Message).filter(
            Message.to_author_uid == db_user.uid,
            Message.is_inbox == is_inbox).order_by(Message.uid.desc()).all()
    else:
        db_messages = DBDiscussionSession.query(Message).filter(
            Message.from_author_uid == db_user.uid,
            Message.is_inbox == is_inbox).order_by(Message.uid.desc()).all()

    message_array = []
    for message in db_messages:
        tmp_dict = dict()
        if is_inbox:
            db_from_user = DBDiscussionSession.query(User).get(
                message.from_author_uid)
            tmp_dict[
                'show_from_author'] = db_from_user.global_nickname != 'admin'
            tmp_dict['from_author'] = db_from_user.global_nickname
            tmp_dict['from_author_avatar'] = get_profile_picture(db_from_user,
                                                                 size=30)
            tmp_dict['from_author_url'] = main_page + '/user/' + str(
                db_from_user.uid)
        else:
            db_to_user = DBDiscussionSession.query(User).get(
                message.to_author_uid)
            tmp_dict['to_author'] = db_to_user.global_nickname
            tmp_dict['to_author_avatar'] = get_profile_picture(db_to_user,
                                                               size=30)
            tmp_dict['to_author_url'] = main_page + '/user/' + str(
                db_to_user.uid)

        tmp_dict['id'] = str(message.uid)
        tmp_dict['timestamp'] = sql_timestamp_pretty_print(
            message.timestamp, lang)
        tmp_dict['read'] = message.read
        tmp_dict['topic'] = message.topic
        tmp_dict['content'] = message.content
        tmp_dict['collapse_link'] = '#collapse' + str(message.uid)
        tmp_dict['collapse_id'] = 'collapse' + str(message.uid)
        message_array.append(tmp_dict)

    return message_array[::-1]
Пример #2
0
def get_strings_for_public_nickname(search_value: str, nickname: str) -> list:
    """
    Returns dictionaries with public nicknames of users, where the nickname containts the value

    :param search_value: String
    :param nickname: current users nickname
    :return: dict()
    """
    db_user = DBDiscussionSession.query(User).filter(
        func.lower(User.public_nickname).contains(func.lower(search_value)),
        ~User.public_nickname.in_([nickname, 'admin', nick_of_anonymous_user
                                   ])).all()
    return_array = []

    for index, user in enumerate(db_user):
        dist = get_distance(search_value, user.public_nickname)
        return_array.append({
            'index':
            index,
            'distance':
            dist,
            'text':
            user.public_nickname,
            'html':
            __highlight_fuzzy_string(user.public_nickname, search_value),
            'avatar':
            get_profile_picture(user)
        })

    return_array = __sort_array(return_array)
    return return_array[:RESULT_LENGTH]
Пример #3
0
def __get_values_of_reference(reference: StatementReferences, main_page):
    """
    Creates dictionary with all values of the column

    :param reference: Current database row
    :param main_page: current main page
    :return: Dictionary with all columns
    """
    db_user = DBDiscussionSession.query(User).get(int(reference.author_uid))

    img = get_profile_picture(db_user, 20, True)
    name = db_user.global_nickname
    link = main_page + '/user/' + str(db_user.uid)

    return {
        'uid': reference.uid,
        'reference': reference.reference,
        'host': reference.host,
        'path': reference.path,
        'author': {
            'img': img,
            'name': name,
            'link': link
        },
        'created': str(reference.created.humanize),
        'statement_text': reference.get_statement_text()
    }
Пример #4
0
def __resolve_email_attribute(attribute, main_page, db_languages, db_users,
                              tmp):
    db_user = DBDiscussionSession.query(User).filter_by(
        email=str(attribute)).first()
    img = '<img class="img-circle" src="{}">'.format(
        get_profile_picture(db_user, 25))
    tmp.append('{} {}'.format(img, attribute))
Пример #5
0
    def __get_last_reviewer_of(reviewer_type, main_page):
        """
        Returns a list with the last reviewers of the given type. Multiple reviewers are filtered

        :param reviewer_type:
        :param main_page:
        :return:
        """
        #  logger('ReviewQueues', '__get_last_reviewer_of', 'main')
        users_array = list()
        db_reviews = DBDiscussionSession.query(reviewer_type).order_by(
            reviewer_type.uid.desc()).all()
        limit = min(5, len(db_reviews))
        index = 0
        while index < limit:
            db_review = db_reviews[index]
            db_user = DBDiscussionSession.query(User).get(
                db_review.reviewer_uid)
            if db_user:
                tmp_dict = dict()
                tmp_dict['img_src'] = get_profile_picture(db_user, 40)
                tmp_dict['url'] = f'{main_page}/user/{db_user.uid}'
                tmp_dict['name'] = db_user.global_nickname
                # skip it, if it is already in
                if tmp_dict in users_array:
                    limit += 1 if len(db_reviews) > limit else 0
                else:
                    users_array.append(tmp_dict)
            else:
                limit += 1 if len(db_reviews) > limit else 0
            index += 1
        return users_array
Пример #6
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
Пример #7
0
def __get_editor_of_statement(uid):
    """

    :param uid:
    :return:
    """
    db_statement = DBDiscussionSession.query(TextVersion).filter_by(
        statement_uid=uid).order_by(TextVersion.uid.desc()).first()
    db_editor = DBDiscussionSession.query(User).get(db_statement.author_uid)
    gravatar = get_profile_picture(db_editor, 40)
    name = db_editor.global_nickname
    return {'name': name, 'gravatar': gravatar}
Пример #8
0
def __get_user_dict_for_review(user_id, main_page):
    """
    Fetches some data of the given user.

    :param main_page: main_page of D-BAS
    :return: dict with gravatar, users page and nickname
    """
    db_user = DBDiscussionSession.query(User).get(user_id)
    image_url = get_profile_picture(db_user, 20)
    return {
        'gravatar_url': image_url,
        'nickname': db_user.global_nickname,
        'userpage_url': main_page + '/user/' + str(db_user.uid)
    }
Пример #9
0
def create_users_dict(db_user, timestamp, main_page, lang):
    """
    Creates dictionary with nickname, url and timestamp

    :param db_user: User
    :param timestamp: SQL Timestamp
    :param main_page: url
    :param lang: language
    :return: dict()
    """
    tmp = db_user.global_nickname
    return {'nickname': tmp,
            'public_profile_url': main_page + '/user/' + str(db_user.uid),
            'avatar_url': get_profile_picture(db_user),
            'vote_timestamp': sql_timestamp_pretty_print(timestamp, lang)}
Пример #10
0
def get_user_dict_for_review(user_id, application_url):
    """
    Fetches some data of the given user.

    :param user_id:
    :param application_url: app url of D-BAS
    :return: dict with gravatar, users page and nickname
    """
    db_user = DBDiscussionSession.query(User).get(user_id)
    image_url = get_profile_picture(db_user, 20)
    return {
        'gravatar_url': image_url,
        'nickname': db_user.global_nickname,
        'userpage_url': f'{application_url}/user/{db_user.uid}'
    }
Пример #11
0
def __get_author_data(uid, query, main_page):
    """
    Returns a-tag with gravatar of current author and users page as href

    :param uid: of user
    :param query: of all users
    :params main_page: URL
    :return: string
    """
    db_user = query.get(uid)
    if not db_user:
        return 'Missing author with uid ' + str(uid), False

    img = '<img class="img-circle" src="{}">'.format(get_profile_picture(db_user, 20, True))
    return '<a href="{}/user/{}">{} {}</a> ({})'.format(main_page, db_user.uid, img, db_user.nickname,
                                                        db_user.uid), True
Пример #12
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
Пример #13
0
def send_request_for_recent_reviewer_socketio(nickname, main_page, queue):
    """
    Sends request to the socketio server for updating the last reviewer view

    :param nickname: Current users nickname
    :param main_page: URL of the app itself
    :param queue: Key of the last reviewers queue
    :return: Status code of the request
    """
    logger('Websocket.lib',
           'main - nickname {} for queue {}'.format(nickname, queue))
    db_user = DBDiscussionSession.query(User).filter_by(
        nickname=nickname).first()
    reviewer_name = db_user.global_nickname
    reviewer_image_url = get_profile_picture(db_user)
    use_https = 'dbas' in main_page
    return __send_request_for_recent_review_to_socketio(
        reviewer_name, reviewer_image_url, queue, use_https)
Пример #14
0
def __get_logfile_dict(textversion: TextVersion, main_page: str, lang: str) -> Dict:
    """
    Returns dictionary with information about the given textversion

    :param textversion: TextVersion
    :param main_page: String
    :param lang: Language.ui_locales
    :return: dict()
    """
    db_author = DBDiscussionSession.query(User).get(textversion.author_uid)
    corr_dict = dict()
    corr_dict['uid'] = str(textversion.uid)
    corr_dict['author'] = str(db_author.global_nickname)
    corr_dict['author_url'] = main_page + '/user/' + str(db_author.uid)
    corr_dict['author_gravatar'] = get_profile_picture(db_author, 20)
    corr_dict['date'] = sql_timestamp_pretty_print(textversion.timestamp, lang)
    corr_dict['text'] = str(textversion.content)
    return corr_dict
Пример #15
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
Пример #16
0
def get_reporter_stats_for_review(db_review, ui_locales, main_page):
    """
    Get statistics for the current review

    :param db_review: Review-Row
    :param ui_locales: Language.ui_locales
    :param main_page: Host URL
    :return: dict()
    """
    LOG.debug("Return statistics for review %s", db_review.uid)

    db_reporter = DBDiscussionSession.query(User).get(db_review.detector_uid)

    return {
        'reported': sql_timestamp_pretty_print(db_review.timestamp, ui_locales),
        'reporter': db_reporter.global_nickname,
        'reporter_gravatar': get_profile_picture(db_reporter, 20),
        'reporter_url': main_page + '/user/' + str(db_reporter.uid),
        'id': str(db_review.uid)
    }
Пример #17
0
def set_settings(url, db_user: User, service, settings_value, _tn):
    """
    Edits a user specific setting

    :param url: current url of request
    :param db_user: User
    :param service: service, which should be modified
    :param settings_value: Boolean
    :param _tn: Translator
    :return: public_nick, public_page_url, gravatar_url, error
    """
    error = ''
    public_nick = db_user.global_nickname
    db_setting = db_user.settings

    if service == 'mail':
        db_setting.set_send_mails(settings_value)
    elif service == 'notification':
        db_setting.set_send_notifications(settings_value)
    elif service == 'public_nick':
        db_setting.set_show_public_nickname(settings_value)
        if settings_value:
            db_user.set_public_nickname(db_user.nickname)
        elif db_user.nickname == db_user.public_nickname:
            user.refresh_public_nickname(db_user)
        public_nick = db_user.global_nickname
    else:
        error = _tn.get(_.keyword)

    transaction.commit()
    public_page_url = '{}/user/{}'.format(url, db_user.uid)
    gravatar_url = get_profile_picture(db_user, 80)

    return {
        'error': error,
        'public_nick': public_nick,
        'public_page_url': public_page_url,
        'gravatar_url': gravatar_url
    }
Пример #18
0
def __get_stats_for_review(review, ui_locales, main_page):
    """
    Get statistics for the current review

    :param review: Review-Row
    :param ui_locales: Language.ui_locales
    :param main_page: Host URL
    :return: dict()
    """
    logger('ReviewSubpagerHelper', 'main')

    db_reporter = DBDiscussionSession.query(User).get(review.detector_uid)

    stats = dict()
    stats['reported'] = sql_timestamp_pretty_print(review.timestamp,
                                                   ui_locales)
    stats['reporter'] = db_reporter.global_nickname
    stats['reporter_gravatar'] = get_profile_picture(db_reporter, 20)
    stats['reporter_url'] = main_page + '/user/' + str(db_reporter.uid)
    stats['id'] = str(review.uid)

    return stats
Пример #19
0
def send_users_notification(author, recipient, title, text,
                            ui_locales) -> dict:
    """
    Send a notification from user a to user b

    :param recipient: User
    :param title: Title of the notification
    :param text: Text of the notification
    :param author: User
    :param ui_locales: Current used language
    :rtype: dict
    :return: prepared collection with status information
    """
    db_notification = send_notification(author, recipient, title, text,
                                        author.nickname)
    prepared_dict = {
        'timestamp':
        sql_timestamp_pretty_print(db_notification.timestamp, ui_locales),
        'uid':
        db_notification.uid,
        'recipient_avatar':
        get_profile_picture(recipient, 20)
    }
    return prepared_dict
Пример #20
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
Пример #21
0
    def prepare_settings_dict(self, pw_change_success, old_pw, new_pw,
                              confirm_pw, pw_change_error, message, db_user,
                              main_page, use_with_ldap):
        """
        Prepares the dictionary for settings.ow

        :param pw_change_success: Boolean
        :param old_pw: String
        :param new_pw: String
        :param confirm_pw: String
        :param pw_change_error: Boolean
        :param message: String
        :param db_user: User
        :param main_page: String
        :param use_with_ldap: Boolean
        :return: dict()
        """
        _tn = Translator(self.system_lang)

        edits = user.get_edit_count_of(db_user, False)
        statements = user.get_statement_count_of(db_user, False)
        arg_vote, stat_vote = user.get_mark_count_of(db_user)
        arg_clicks, stat_clicks = user.get_click_count_of(db_user)
        public_nick = db_user.global_nickname
        db_group = DBDiscussionSession.query(Group).get(db_user.group_uid)
        db_settings = db_user.settings
        db_language = DBDiscussionSession.query(Language).get(
            db_settings.lang_uid)

        group = db_group.name if db_group else '-'
        gravatar_public_url = get_profile_picture(db_user, 80)
        reputation, tmp = get_reputation_of(db_user)

        return {
            'passwordold': '' if pw_change_success else old_pw,
            'password': '' if pw_change_success else new_pw,
            'passwordconfirm': '' if pw_change_success else confirm_pw,
            'pw_change_error': pw_change_error,
            'pw_change_success': pw_change_success,
            'message': message,
            'db_firstname': db_user.firstname,
            'db_surname': db_user.surname,
            'db_nickname': db_user.nickname,
            'db_public_nickname': public_nick,
            'db_mail': db_user.email,
            'has_mail': db_user.email != 'None',
            'can_change_password': not use_with_ldap
            and db_user.oauth_provider is None,
            'db_group': group,
            'avatar_public_url': gravatar_public_url,
            'edits_done': edits,
            'statements_posted': statements,
            'discussion_arg_votes': arg_vote,
            'discussion_stat_votes': stat_vote,
            'discussion_arg_clicks': arg_clicks,
            'discussion_stat_clicks': stat_clicks,
            'send_mails': db_settings.should_send_mails,
            'send_notifications': db_settings.should_send_notifications,
            'public_nick': db_settings.should_show_public_nickname,
            'title_mails': _tn.get(_.mailSettingsTitle),
            'title_notifications': _tn.get(_.notificationSettingsTitle),
            'title_public_nick': _tn.get(_.publicNickTitle),
            'title_preferred_lang': _tn.get(_.preferredLangTitle),
            'public_page_url': main_page + '/user/' + str(db_user.uid),
            'on': _tn.get(_.on),
            'off': _tn.get(_.off),
            'current_lang': db_language.name,
            'current_ui_locales': db_language.ui_locales,
            'reputation': reputation
        }
Пример #22
0
 def test_get_public_profile_picture(self):
     user = DBDiscussionSession.query(User).get(1)
     self.assertIn('gravatar.com', lib.get_profile_picture(user))
     self.assertIn('80', lib.get_profile_picture(user))
     self.assertIn('gravatar.com', lib.get_profile_picture(user, size=120))
     self.assertIn('120', lib.get_profile_picture(user, size=120))
Пример #23
0
 def resolve_profile_picture(self, info, **kwargs):
     return get_profile_picture(self, **kwargs)