Added admin2, more simple, more fast
This commit is contained in:
parent
6cffc09371
commit
352f3ec36b
30 changed files with 2846 additions and 6 deletions
10
paramecio/modules/admin2/libraries/config.py
Normal file
10
paramecio/modules/admin2/libraries/config.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# Every element
|
||||
|
||||
# ['Name of module admin', 'name_function_for_url_for', 'xml-icon']
|
||||
|
||||
modules_admin=[]
|
||||
|
||||
modules_admin_icons=[]
|
||||
|
||||
19
paramecio/modules/admin2/libraries/i18n.py
Normal file
19
paramecio/modules/admin2/libraries/i18n.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from parameciofast.libraries.i18n import I18n
|
||||
|
||||
"""
|
||||
I18n.l['en-US']=I18n.l.get('en-US', {})
|
||||
|
||||
I18n.l['en-US']['fastadmin']=I18n.l['en-US'].get('fastadmin', {})
|
||||
|
||||
I18n.l['en-US']['fastadmin']['fastadmin_ausers']='Admin users'
|
||||
|
||||
I18n.l['es-ES']=I18n.l.get('es-ES', {})
|
||||
|
||||
I18n.l['es-ES']['fastadmin']=I18n.l['en-US'].get('fastadmin', {})
|
||||
|
||||
I18n.l['es-ES']['fastadmin']['fastadmin_ausers']='Usuarios admin'
|
||||
"""
|
||||
|
||||
I18n.add_lang('en-US', 'admin2', 'admin_app.admin_users', 'Admin users')
|
||||
I18n.add_lang('es-ES', 'admin2', 'admin_app.admin_users', 'Usuarios admin')
|
||||
|
||||
66
paramecio/modules/admin2/libraries/loginplugin.py
Normal file
66
paramecio/modules/admin2/libraries/loginplugin.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
from bottle import request, response, redirect
|
||||
from settings import config
|
||||
import inspect
|
||||
from paramecio.wsgiapp import app
|
||||
|
||||
def check_login(callback):
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
if 'session' in request.environ:
|
||||
|
||||
if request.environ['session'].get('login_admin', 0):
|
||||
|
||||
result = callback(*args, **kwargs)
|
||||
|
||||
return result
|
||||
|
||||
redirect(app.get_url('admin_app.login_admin'))
|
||||
|
||||
return wrapper
|
||||
"""
|
||||
class CheckLoginPlugin(object):
|
||||
|
||||
name = 'checklogin'
|
||||
api = 2
|
||||
|
||||
def __init__(self, keyword='session'):
|
||||
|
||||
self.keyword=keyword
|
||||
|
||||
|
||||
def setup(self, app):
|
||||
''' Make sure that other installed plugins don't affect the same keyword argument.'''
|
||||
for other in app.plugins:
|
||||
if not isinstance(other, SessionPlugin): continue
|
||||
if other.keyword == self.keyword:
|
||||
raise PluginError("Found another login plugin with "\
|
||||
"conflicting settings (non-unique keyword).")
|
||||
|
||||
def apply(self, callback, context):
|
||||
|
||||
# Test if the original callback accepts a 'session' keyword.
|
||||
# Ignore it if it does not need a login handle.
|
||||
|
||||
conf = context.config.get('checklogin') or {}
|
||||
|
||||
keyword = conf.get('keyword', self.keyword)
|
||||
|
||||
args = inspect.getfullargspec(context.callback)[0]
|
||||
|
||||
if keyword not in args:
|
||||
return callback
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
if 'session' in request.environ:
|
||||
|
||||
if request.environ['session'].get('login_admin', 1):
|
||||
|
||||
rv=callback(*args, **kwargs)
|
||||
|
||||
return rv
|
||||
|
||||
redirect(app.get_url('admin_app.home_admin'))
|
||||
|
||||
return wrapper
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue