Browse Source

added admin section

php2python
Holger Frey 7 years ago
parent
commit
cbd6329142
  1. 4
      ordr2/resources/__init__.py
  2. 9
      ordr2/resources/admin.py
  3. 1
      ordr2/static/css/style.css
  4. 36
      ordr2/templates/admin/admin_section.jinja2
  5. 31
      ordr2/views/admin.py

4
ordr2/resources/__init__.py

@ -1,6 +1,7 @@
from pyramid.security import Allow, Everyone from pyramid.security import Allow, Everyone
from .account import Account from .account import Account
from .admin import Admin
from .base import BaseResource from .base import BaseResource
@ -11,7 +12,8 @@ class Root(BaseResource):
__parent__ = None __parent__ = None
_nodes = { _nodes = {
'account': Account 'account': Account,
'admin': Admin
} }
def __init__(self, request): def __init__(self, request):

9
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') ]

1
ordr2/static/css/style.css

@ -731,3 +731,4 @@ input[value="new_password:mapping"] + div { margin-bottom:10px; }
padding-bottom: 20px; padding-bottom: 20px;
margin-bottom: 20px; margin-bottom: 20px;
border-bottom: 1px solid #aaa;} border-bottom: 1px solid #aaa;}
div.alert a { color:inherit; text-decoration:underline; }

36
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 %}
<div class="content controls">
<div class="container-fluid">
<div class="row-fluid">
<div class="page-controls">
<h1>Register</h1>
</div>
</div>
<div class="row-fluid">{{ macros.flash_messages() }}</div>
<div class="row admin-options">
<a href="<?php echo base_url(); ?>admin/users/view/">
<div class="span4 rounded-box">
<div class="option user"></div>
<h2>Mangage Users</h2>
</div>
</a>
<a href="<?php echo base_url(); ?>admin/consumables/view/">
<div class="span4 rounded-box">
<div class="option shop"></div>
<h2>Manage Consumables</h2>
</div>
</a>
</div>
</div>
</div>
{% endblock content %}

31
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 <a href="{}">take a look at them</a> 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 {}