Added plugins
This commit is contained in:
parent
e5af25adf6
commit
6fd05f526e
2 changed files with 61 additions and 0 deletions
|
|
@ -7,8 +7,23 @@ from paramecio2.libraries.i18n import I18n
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
class GenerateAdminClass:
|
class GenerateAdminClass:
|
||||||
|
"""Class for generate items for a model
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, model, url, t):
|
def __init__(self, model, url, t):
|
||||||
|
"""A class for generate forms, insert and update items from a database model
|
||||||
|
|
||||||
|
For an easy and fast access to database data, you can use this class for get a simple database model of paramecio and get list of items, add forms, edit forms and more.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
model (WebModel): A WebModel model (equivalent to database mysql table)
|
||||||
|
url (str): A string with the base url for the forms.
|
||||||
|
t (PTemplate): Template used for the class. Normally template subclassed from admin_t PTemplate
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
self.model_name=''
|
self.model_name=''
|
||||||
|
|
||||||
|
|
|
||||||
46
paramecio2/libraries/plugins.py
Normal file
46
paramecio2/libraries/plugins.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
from flask import g
|
||||||
|
from functools import wraps
|
||||||
|
from paramecio2.libraries.db.webmodel import WebModel
|
||||||
|
|
||||||
|
login_name='login'
|
||||||
|
login_url='.login'
|
||||||
|
|
||||||
|
def db(f):
|
||||||
|
|
||||||
|
@wraps(f)
|
||||||
|
|
||||||
|
def wrapper(*args, **kwds):
|
||||||
|
|
||||||
|
g.connection=WebModel.connection()
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
code=f(*args, **kwds)
|
||||||
|
|
||||||
|
g.connection.close()
|
||||||
|
|
||||||
|
except:
|
||||||
|
|
||||||
|
g.connection.close()
|
||||||
|
|
||||||
|
raise
|
||||||
|
|
||||||
|
return code
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
def login_site(f):
|
||||||
|
|
||||||
|
@wraps(f)
|
||||||
|
|
||||||
|
def wrapper(*args, **kwds):
|
||||||
|
|
||||||
|
if not login_name in session:
|
||||||
|
|
||||||
|
return redirect(url_for(login_url))
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
return f(*args, **kwds)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
Loading…
Add table
Add a link
Reference in a new issue