From cbd632914226d69ad7737b18112568c3b0ceac48 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 28 Sep 2017 15:13:34 +0200 Subject: [PATCH] added admin section --- ordr2/resources/__init__.py | 4 ++- ordr2/resources/admin.py | 9 ++++++ ordr2/static/css/style.css | 1 + ordr2/templates/admin/admin_section.jinja2 | 36 ++++++++++++++++++++++ ordr2/views/admin.py | 31 +++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 ordr2/resources/admin.py create mode 100644 ordr2/templates/admin/admin_section.jinja2 create mode 100644 ordr2/views/admin.py diff --git a/ordr2/resources/__init__.py b/ordr2/resources/__init__.py index b577c27..8d0834b 100644 --- a/ordr2/resources/__init__.py +++ b/ordr2/resources/__init__.py @@ -1,6 +1,7 @@ from pyramid.security import Allow, Everyone from .account import Account +from .admin import Admin from .base import BaseResource @@ -11,7 +12,8 @@ class Root(BaseResource): __parent__ = None _nodes = { - 'account': Account + 'account': Account, + 'admin': Admin } def __init__(self, request): diff --git a/ordr2/resources/admin.py b/ordr2/resources/admin.py new file mode 100644 index 0000000..01c04fb --- /dev/null +++ b/ordr2/resources/admin.py @@ -0,0 +1,9 @@ +from pyramid.security import Allow, Authenticated, Deny, Everyone + +from .base import BaseResource + + +class Admin(BaseResource): + + def __acl__(self): + return [ (Allow, 'role:admin', 'view') ] diff --git a/ordr2/static/css/style.css b/ordr2/static/css/style.css index ea79ca6..909455c 100755 --- a/ordr2/static/css/style.css +++ b/ordr2/static/css/style.css @@ -731,3 +731,4 @@ input[value="new_password:mapping"] + div { margin-bottom:10px; } padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid #aaa;} +div.alert a { color:inherit; text-decoration:underline; } diff --git a/ordr2/templates/admin/admin_section.jinja2 b/ordr2/templates/admin/admin_section.jinja2 new file mode 100644 index 0000000..9ac9d70 --- /dev/null +++ b/ordr2/templates/admin/admin_section.jinja2 @@ -0,0 +1,36 @@ +{% extends "ordr2:templates/layout.jinja2" %} +{% import 'ordr2:templates/macros.jinja2' as macros with context %} + +{% block subtitle %} Admin {% endblock subtitle %} + +{% block content %} +
+ +
+ +
+
+

Register

+
+
+ +
{{ macros.flash_messages() }}
+ + +
+ +
+{% endblock content %} diff --git a/ordr2/views/admin.py b/ordr2/views/admin.py new file mode 100644 index 0000000..8f7749f --- /dev/null +++ b/ordr2/views/admin.py @@ -0,0 +1,31 @@ +import deform + +from pyramid.httpexceptions import HTTPFound +from pyramid.renderers import render +from pyramid.security import remember, forget +from pyramid.view import view_config + +from ordr2.models import User, Role +from ordr2.schemas.account import UserSchema + +# user log in and log out + +@view_config( + context='ordr2:resources.Admin', + permission='view', + renderer='ordr2:templates/admin/admin_section.jinja2' + ) +def admin_section(context, request): + ''' display the admin section ''' + new_users = request.dbsession.query(User).filter_by(role=Role.NEW).count() + if new_users: + plural = 's' if new_users > 1 else '' + request.flash( + 'info', + '{} new user{} have registered.'.format(new_users, plural), + '''Please take a look at them and confirm or + reject the registration by setting the role accordingly. This + message will disappear when all new registrations have been + processed.'''.format(request.resource_url(context, 'users')) + ) + return {}