Example #1
0
def edit_users(request):
    """Edit a user."""
    pagination = Pagination(request, User.query, request.args.get('page', type=int))
    form = EditUserRedirectForm()

    if request.method == 'POST' and form.validate():
        return redirect(url_for('admin.edit_user', user=form.user.username))

    return render_template('admin/edit_users.html', pagination=pagination,
                           users=pagination.get_objects(), form=form.as_widget())
Example #2
0
def bans(request):
    """Manages banned users"""
    form = BanUserForm()
    query = User.query.filter_by(is_banned=True)
    pagination = Pagination(request, query, request.args.get('page', type=int))

    if request.method == 'POST' and form.validate():
        admin_utils.ban_user(form.user)
        request.flash(_(u'The user ā€œ%sā€ was successfully banned and notified.') %
                      form.user.username)
        return form.redirect('admin.bans')

    return render_template('admin/bans.html', pagination=pagination,
                           banned_users=pagination.get_objects(),
                           form=form.as_widget())
Example #3
0
File: kb.py Project: Plurk/Solace
def _topic_list(template_name, request, query, order_by, **context):
    """Helper for views rendering a topic list."""
    # non moderators cannot see deleted posts, so we filter them out first
    # for moderators the template marks the posts up as deleted so that
    # they can be kept apart from non-deleted ones.
    if not request.user or not request.user.is_moderator:
        query = query.filter_by(is_deleted=False)
    query = query.order_by(_topic_order[order_by])

    # optimize the query for the template.  The template needs the author
    # of the topic as well (but not the editor) which is not eagerly
    # loaded by default.
    query = query.options(eagerload('author'))

    pagination = Pagination(request, query, request.args.get('page', type=int))
    return render_template(template_name, pagination=pagination,
                           order_by=order_by, topics=pagination.get_objects(),
                           **context)
Example #4
0
def userlist(request, locale=None):
    """Displays list of users.  Optionally a locale identifier can be passed
    in that replaces the default "all users" query.  This is used by the
    userlist form the knowledge base that forwards the call here.
    """
    query = User.query
    if locale is not None:
        # if we just have one language, we ignore that there is such a thing
        # as being active in a section of the webpage and redirect to the
        # general user list.
        if len(settings.LANGUAGE_SECTIONS) == 1:
            return redirect(url_for('users.userlist'))
        locale = Locale.parse(locale)
        query = query.active_in(locale)
    query = query.order_by(User.reputation.desc())
    pagination = Pagination(request, query, request.args.get('page', type=int))
    return render_template('users/userlist.html', pagination=pagination,
                           users=pagination.get_objects(), locale=locale,
                           sections=list_sections())
Example #5
0
def _topic_list(template_name, request, query, order_by, **context):
    """Helper for views rendering a topic list."""
    # non moderators cannot see deleted posts, so we filter them out first
    # for moderators the template marks the posts up as deleted so that
    # they can be kept apart from non-deleted ones.
    if not request.user or not request.user.is_moderator:
        query = query.filter_by(is_deleted=False)
    query = query.order_by(_topic_order[order_by])

    # optimize the query for the template.  The template needs the author
    # of the topic as well (but not the editor) which is not eagerly
    # loaded by default.
    query = query.options(eagerload('author'))

    pagination = Pagination(request, query, request.args.get('page', type=int))
    return render_template(template_name,
                           pagination=pagination,
                           order_by=order_by,
                           topics=pagination.get_objects(),
                           **context)
Example #6
0
def userlist(request, locale=None):
    """Displays list of users.  Optionally a locale identifier can be passed
    in that replaces the default "all users" query.  This is used by the
    userlist form the knowledge base that forwards the call here.
    """
    query = User.query
    if locale is not None:
        # if we just have one language, we ignore that there is such a thing
        # as being active in a section of the webpage and redirect to the
        # general user list.
        if len(settings.LANGUAGE_SECTIONS) == 1:
            return redirect(url_for('users.userlist'))
        locale = Locale.parse(locale)
        query = query.active_in(locale)
    query = query.order_by(User.reputation.desc())
    pagination = Pagination(request, query, request.args.get('page', type=int))
    return render_template('users/userlist.html',
                           pagination=pagination,
                           users=pagination.get_objects(),
                           locale=locale,
                           sections=list_sections())