1
1
Fork 0

Trying something

dev
Jan Kužílek 5 years ago
parent 1c228fa781
commit b2ffd74286

@ -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,
)

@ -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():
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'))

@ -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('/<username>')
@ -26,4 +28,12 @@ def settings():
flash('Password changed successfully.')
return redirect(url_for('.settings'))
return render_template('manage/user.html', form=form)
return render_template('manage/profile.html', form=form)
@bp.route('/manage_users', defaults={'page': 1})
@bp.route('/manage_users/<int:page>')
@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)

@ -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

@ -34,7 +34,7 @@
<a href="{{ url_for('auth.register') }}">Register</a>
{% else %}
<a href="#">Profile</a>
<a href="#">Settings</a>
<a href="{{ url_for('user.settings') }}">Settings</a>
<a href="{{ url_for('auth.logout') }}">Log out</a>
{% endif%}
</div>

@ -0,0 +1,20 @@
{% extends 'layout/settings.html' %}
{% from '_includes.html' import render_pagination with context %}
{% from "_formhelpers.html" import errors %}
{% block setting_content %}
<table>
<!-- <thead></thead> -->
<tbody>
{% for user in users %}
<tr>
<td>{{ user.username }}</td>
<td>{{ user.user_status.name }}</td>
<td>{{ user.op_level.name }}</td>
<td>{{ user.last_login.strftime('%I:%M %p %d %b, %y') }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ render_pagination('user.manage_users') }}
{% endblock %}

@ -13,3 +13,12 @@ from werkzeug.urls import Href
def query_replace(dic, base=''):
args = request.args.to_dict()
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
Loading…
Cancel
Save