diff --git a/yadc/__init__.py b/yadc/__init__.py index 998ed50..dfeaf58 100644 --- a/yadc/__init__.py +++ b/yadc/__init__.py @@ -29,6 +29,7 @@ def create_app(): POST_UPLOADS=os.path.join(app.instance_path, 'post'), INSTANCE_NAME='YaDc', POSTS_PER_PAGE=8, + MANAGE_USERS_PER_PAGE=2, SQLALCHEMY_ECHO=True, ) diff --git a/yadc/bp/auth.py b/yadc/bp/auth.py index bc0ce35..849ce76 100644 --- a/yadc/bp/auth.py +++ b/yadc/bp/auth.py @@ -1,22 +1,16 @@ import flask_login as fl from flask import Blueprint, flash, redirect, render_template, request, url_for -from werkzeug.urls import url_parse from wtforms import BooleanField, PasswordField, StringField, SubmitField from wtforms.validators import DataRequired from yadc import db from yadc.forms import LoginForm, RegisterForm, ResetPasswordForm from yadc.models import User +from yadc.utils import nextpage bp = Blueprint('auth', __name__) -def nextpage(): - nextpg = request.args.get('next') - if not nextpg or url_parse(nextpg).netloc != '': - nextpg = url_for('main.index') - return nextpg - -@bp.route('/login/', methods=['GET', 'POST']) +@bp.route('/login', methods=['GET', 'POST']) def login(): if fl.current_user.is_authenticated: return redirect(url_for('main.index')) @@ -37,13 +31,14 @@ def login(): return render_template('auth/login.html', form=form) -@bp.route('/logout/') +@bp.route('/logout') def logout(): - fl.current_user.logout() + if fl.current_user.is_authenticated: + fl.current_user.logout() return redirect(nextpage()) -@bp.route('/reset_password/', methods=['GET', 'POST']) +@bp.route('/reset_password', methods=['GET', 'POST']) def reset_password(): if fl.current_user.is_authenticated: return redirect(url_for('main.index')) @@ -63,7 +58,7 @@ def reset_password(): return render_template('auth/reset_password.html', form=form) -@bp.route('/register/', methods=['GET', 'POST']) +@bp.route('/register', methods=['GET', 'POST']) def register(): if fl.current_user.is_authenticated: return redirect(url_for('main.index')) diff --git a/yadc/bp/user.py b/yadc/bp/user.py index 35495d5..7f9dc08 100644 --- a/yadc/bp/user.py +++ b/yadc/bp/user.py @@ -3,6 +3,8 @@ from flask import (Blueprint, abort, current_app, flash, redirect, from flask_login import current_user, login_required from yadc.forms import ChangePassForm +from yadc.models import User + bp = Blueprint('user', __name__) @bp.route('/') @@ -26,4 +28,12 @@ def settings(): flash('Password changed successfully.') return redirect(url_for('.settings')) - return render_template('manage/user.html', form=form) \ No newline at end of file + return render_template('manage/profile.html', form=form) + +@bp.route('/manage_users', defaults={'page': 1}) +@bp.route('/manage_users/') +@login_required +def manage_users(page): + users = User.query.order_by(User.created).paginate(page, current_app.config.get('MANAGE_USERS_PER_PAGE')) + + return render_template('manage/users.html', users=users.items, pagination=users) diff --git a/yadc/static/default.scss b/yadc/static/default.scss index f46e514..3b22363 100644 --- a/yadc/static/default.scss +++ b/yadc/static/default.scss @@ -383,28 +383,6 @@ header { } } } - - .pagin { - margin: 10px 0; - - @include media($bp-desktop) { - margin-right: calc(#{$side-panel-width}*3/4); - } - - display: flex; - flex-flow: row nowrap; - - justify-content: center; - - > a { - display: block; - - background-color: #0005; - padding: 8px 12px; - - margin: 0 2px; - } - } } section.post_single { @@ -486,6 +464,28 @@ header { } } + + .pagin { + margin: 10px 0; + + // @include media($bp-desktop) { + // margin-right: calc(#{$side-panel-width}*3/4); + // } + + display: flex; + flex-flow: row nowrap; + + justify-content: center; + + > a { + display: block; + + background-color: #0005; + padding: 8px 12px; + + margin: 0 2px; + } + } } footer { // DUE TO OVERFLOW OF THE SIDE PANEL, TRY TO KEEP IT ON THE RIGHT diff --git a/yadc/templates/layout/base.html b/yadc/templates/layout/base.html index 2d870aa..356a5a1 100644 --- a/yadc/templates/layout/base.html +++ b/yadc/templates/layout/base.html @@ -34,7 +34,7 @@ Register {% else %} Profile - Settings + Settings Log out {% endif%} diff --git a/yadc/templates/layout/settings.html b/yadc/templates/layout/settings.html index 958662f..0567f56 100644 --- a/yadc/templates/layout/settings.html +++ b/yadc/templates/layout/settings.html @@ -2,12 +2,12 @@ {% from '_includes.html' import render_sidenav with context %} {% block content %} -
-
- {{ render_sidenav({"speedtest": ("Speedtest", "http://speedtest.cesnet.cz")}) }} -
-
- {% block setting_content %}{% endblock %} -
-
+
+
+ {{ render_sidenav({"speedtest": ("Speedtest", "http://speedtest.cesnet.cz")}) }} +
+
+ {% block setting_content %}{% endblock %} +
+
{% endblock content %} \ No newline at end of file diff --git a/yadc/templates/manage/user.html b/yadc/templates/manage/profile.html similarity index 100% rename from yadc/templates/manage/user.html rename to yadc/templates/manage/profile.html diff --git a/yadc/templates/manage/users.html b/yadc/templates/manage/users.html new file mode 100644 index 0000000..81e7888 --- /dev/null +++ b/yadc/templates/manage/users.html @@ -0,0 +1,20 @@ +{% extends 'layout/settings.html' %} +{% from '_includes.html' import render_pagination with context %} +{% from "_formhelpers.html" import errors %} + +{% block setting_content %} + + + + {% for user in users %} + + + + + + + {% endfor %} + +
{{ user.username }}{{ user.user_status.name }}{{ user.op_level.name }}{{ user.last_login.strftime('%I:%M %p %d %b, %y') }}
+{{ render_pagination('user.manage_users') }} +{% endblock %} \ No newline at end of file diff --git a/yadc/utils.py b/yadc/utils.py index 1f6474d..4bd61f9 100644 --- a/yadc/utils.py +++ b/yadc/utils.py @@ -12,4 +12,13 @@ from werkzeug.urls import Href def query_replace(dic, base=''): args = request.args.to_dict() - return Href(base)(args.update(dic) or args) \ No newline at end of file + return Href(base)(args.update(dic) or args) + +from flask import request, url_for +from werkzeug.urls import url_parse + +def nextpage(): + nextpg = request.args.get('next') + if not nextpg or url_parse(nextpg).netloc != '': + nextpg = url_for('main.index') + return nextpg \ No newline at end of file