Fixes in generate_admin_class for make independent of flask
This commit is contained in:
parent
d91b85dfa0
commit
312629238f
2 changed files with 56 additions and 16 deletions
|
|
@ -38,7 +38,7 @@ class GenerateAdminClass:
|
||||||
"""Class for insert, update and list items of a model
|
"""Class for insert, update and list items of a model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, model, url, t=None):
|
def __init__(self, model, url, t=None, query_args=None, request_post=None):
|
||||||
"""A class for generate forms, insert and update items from a database model
|
"""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.
|
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.
|
||||||
|
|
@ -117,6 +117,10 @@ class GenerateAdminClass:
|
||||||
|
|
||||||
self.text_home=_('Home')
|
self.text_home=_('Home')
|
||||||
|
|
||||||
|
self.query_args=None
|
||||||
|
|
||||||
|
self.request_post=None
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
""" Method for show the admin model
|
""" Method for show the admin model
|
||||||
|
|
||||||
|
|
@ -126,10 +130,14 @@ class GenerateAdminClass:
|
||||||
html (str): The html content of the admin page, can be, items list, forms for create items, etc...
|
html (str): The html content of the admin page, can be, items list, forms for create items, etc...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not self.query_args:
|
||||||
op_admin=request.args.get('op_admin', '0')
|
op_admin=request.args.get('op_admin', '0')
|
||||||
|
|
||||||
item_id=request.args.get('id', '0')
|
item_id=request.args.get('id', '0')
|
||||||
|
|
||||||
|
else:
|
||||||
|
op_admin=self.query_args.get('op_admin', '0')
|
||||||
|
item_id=self.query_args.get('id', '0')
|
||||||
|
|
||||||
if len(self.model.forms)==0:
|
if len(self.model.forms)==0:
|
||||||
|
|
||||||
self.model.create_forms()
|
self.model.create_forms()
|
||||||
|
|
@ -189,7 +197,11 @@ class GenerateAdminClass:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
if not self.query_args:
|
||||||
|
|
||||||
item_id=str(int(request.args.get('id', '0')))
|
item_id=str(int(request.args.get('id', '0')))
|
||||||
|
else:
|
||||||
|
item_id=str(int(self.query_args.get('id', '0')))
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|
||||||
|
|
@ -203,7 +215,11 @@ class GenerateAdminClass:
|
||||||
title_edit=_('Edit item')
|
title_edit=_('Edit item')
|
||||||
self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [item_id]]
|
self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [item_id]]
|
||||||
|
|
||||||
|
if not self.request_post:
|
||||||
|
|
||||||
post=dict(request.form)
|
post=dict(request.form)
|
||||||
|
else:
|
||||||
|
post=self.request_post
|
||||||
|
|
||||||
if pre_update_ret:
|
if pre_update_ret:
|
||||||
|
|
||||||
|
|
@ -221,7 +237,10 @@ class GenerateAdminClass:
|
||||||
|
|
||||||
url_action=add_get_parameters(self.url, op_admin=2, id=item_id)
|
url_action=add_get_parameters(self.url, op_admin=2, id=item_id)
|
||||||
|
|
||||||
|
if not self.request_post:
|
||||||
post=dict(request.form)
|
post=dict(request.form)
|
||||||
|
else:
|
||||||
|
post=self.request_post
|
||||||
|
|
||||||
form=show_form(post, edit_forms, self.t, True)
|
form=show_form(post, edit_forms, self.t, True)
|
||||||
|
|
||||||
|
|
@ -231,7 +250,7 @@ class GenerateAdminClass:
|
||||||
else:
|
else:
|
||||||
url_action=add_get_parameters(self.url, op_admin=2, id=item_id)
|
url_action=add_get_parameters(self.url, op_admin=2, id=item_id)
|
||||||
|
|
||||||
post=dict(request.form)
|
#post=dict(request.form)
|
||||||
|
|
||||||
form=show_form(post, edit_forms, self.t, True)
|
form=show_form(post, edit_forms, self.t, True)
|
||||||
|
|
||||||
|
|
@ -242,8 +261,14 @@ class GenerateAdminClass:
|
||||||
|
|
||||||
elif op_admin=='3':
|
elif op_admin=='3':
|
||||||
|
|
||||||
|
if not self.query_args:
|
||||||
|
|
||||||
verified=request.args.get('verified', '0')
|
verified=request.args.get('verified', '0')
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
verified=self.query_args.get('verified', '0')
|
||||||
|
|
||||||
if verified=='1':
|
if verified=='1':
|
||||||
|
|
||||||
if item_id!='0':
|
if item_id!='0':
|
||||||
|
|
@ -338,7 +363,11 @@ class GenerateConfigClass:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
#op_config=request.args.get('op_config', '0')
|
||||||
|
if not self.query_args:
|
||||||
op_config=request.args.get('op_config', '0')
|
op_config=request.args.get('op_config', '0')
|
||||||
|
else:
|
||||||
|
op_config=self.query_args.get('op_config', '0')
|
||||||
|
|
||||||
if len(self.model.forms)==0:
|
if len(self.model.forms)==0:
|
||||||
|
|
||||||
|
|
@ -366,7 +395,13 @@ class GenerateConfigClass:
|
||||||
if c:
|
if c:
|
||||||
insert_model=self.model.update
|
insert_model=self.model.update
|
||||||
|
|
||||||
|
#post=dict(request.form)
|
||||||
|
if not self.request_post:
|
||||||
|
|
||||||
post=dict(request.form)
|
post=dict(request.form)
|
||||||
|
else:
|
||||||
|
post=self.request_post
|
||||||
|
|
||||||
|
|
||||||
if insert_model(post):
|
if insert_model(post):
|
||||||
set_flash_message(_('Task successful'))
|
set_flash_message(_('Task successful'))
|
||||||
|
|
@ -380,7 +415,12 @@ class GenerateConfigClass:
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
#post=dict(request.form)
|
||||||
|
if not self.request_post:
|
||||||
post=dict(request.form)
|
post=dict(request.form)
|
||||||
|
else:
|
||||||
|
post=self.request_post
|
||||||
|
|
||||||
|
|
||||||
form=show_form(post, edit_forms, self.t, True)
|
form=show_form(post, edit_forms, self.t, True)
|
||||||
self.model.yes_reset_conditions=True
|
self.model.yes_reset_conditions=True
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,10 @@ build-backend = "flit_core.buildapi"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "paramecio2"
|
name = "paramecio2"
|
||||||
version = "2.0.36"
|
|
||||||
description = "Simple Web Framework based in flask and Mako."
|
|
||||||
readme = "README.md"
|
|
||||||
license = {file = "LICENSE.txt"}
|
|
||||||
authors = [{name = "Antonio de la Rosa", email = "antonio.delarosa@salirdelhoyo.com"}]
|
authors = [{name = "Antonio de la Rosa", email = "antonio.delarosa@salirdelhoyo.com"}]
|
||||||
|
readme = "README.md"
|
||||||
|
dynamic = ["version", "description"]
|
||||||
|
|
||||||
classifiers=['Development Status :: 4 - Beta',
|
classifiers=['Development Status :: 4 - Beta',
|
||||||
"Intended Audience :: Developers",
|
"Intended Audience :: Developers",
|
||||||
"License :: OSI Approved :: GNU Affero General Public License v3",
|
"License :: OSI Approved :: GNU Affero General Public License v3",
|
||||||
|
|
@ -37,9 +36,10 @@ install_requires=[
|
||||||
"bleach",
|
"bleach",
|
||||||
"argon2-cffi"
|
"argon2-cffi"
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
Home = "https://git.cuchulu.com/paramecio/paramecio2fm/"
|
||||||
Documentation = "https://docs.cuchulu.com/paramecio2/"
|
Documentation = "https://docs.cuchulu.com/paramecio2/"
|
||||||
Source = "https://git.cuchulu.com/paramecio/paramecio2fm/"
|
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
paramecio2 = "paramecio2.console:start"
|
paramecio2 = "paramecio2.console:start"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue