Added more docstrings for libraries
This commit is contained in:
parent
58ff6a1d74
commit
799cfe2125
4 changed files with 140 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ 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
|
"""Class for insert, update and list items of a model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, model, url, t):
|
def __init__(self, model, url, t):
|
||||||
|
|
@ -21,11 +21,20 @@ class GenerateAdminClass:
|
||||||
t (PTemplate): Template used for the class. Normally template subclassed from admin_t PTemplate
|
t (PTemplate): Template used for the class. Normally template subclassed from admin_t PTemplate
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
|
model (WebModel) The webmodel used for generatre the admin model form
|
||||||
|
t (PTemplate): Template used for the class. Normally template subclassed from admin_t PTemplate
|
||||||
|
list (SimpleList): A SimpleList class used for generate the listing
|
||||||
|
arr_fields_edit (list): A list with the fields that the user can edit
|
||||||
|
url (str): Base url used by GenerateAdminClass for generate edit, insert and other urls.
|
||||||
|
template_insert (str): The template used for the insert form
|
||||||
|
template_admin (str): The template used for the base admin site
|
||||||
|
template_delete (str): The template used for verify delete of an item
|
||||||
|
url_redirect (str): The url where user is redirect when an operation is done
|
||||||
|
post_update (function): A Function with item id used how argument for make a post-progressing after update.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.model_name=''
|
#self.model_name=''
|
||||||
|
|
||||||
self.model=model
|
self.model=model
|
||||||
|
|
||||||
|
|
@ -39,21 +48,21 @@ class GenerateAdminClass:
|
||||||
|
|
||||||
self.url=url
|
self.url=url
|
||||||
|
|
||||||
self.safe=0;
|
#self.safe=0;
|
||||||
|
|
||||||
self.arr_links={}
|
#self.arr_links={}
|
||||||
|
|
||||||
self.hierarchy=None
|
#self.hierarchy=None
|
||||||
|
|
||||||
self.text_add_item=''
|
#self.text_add_item=''
|
||||||
|
|
||||||
self.no_insert=False
|
#self.no_insert=False
|
||||||
|
|
||||||
self.no_delete=False
|
#self.no_delete=False
|
||||||
|
|
||||||
self.title=''
|
self.title=''
|
||||||
|
|
||||||
self.id=0
|
#self.id=0
|
||||||
|
|
||||||
self.template_insert='utils/insertform.phtml'
|
self.template_insert='utils/insertform.phtml'
|
||||||
|
|
||||||
|
|
@ -68,6 +77,12 @@ class GenerateAdminClass:
|
||||||
self.text_home=I18n.lang('common', 'home', 'Home')
|
self.text_home=I18n.lang('common', 'home', 'Home')
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
""" Method for show the admin model
|
||||||
|
|
||||||
|
Depending of op_admin arg, you have the different sections of a simple administrator
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
op_admin=request.args.get('op_admin', '0')
|
op_admin=request.args.get('op_admin', '0')
|
||||||
|
|
||||||
|
|
@ -198,10 +213,31 @@ class GenerateAdminClass:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class GenerateConfigClass:
|
class GenerateConfigClass:
|
||||||
|
"""Class for generate a simple form for simple data for a configuration
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, model, url, t):
|
def __init__(self, model, url, t):
|
||||||
|
"""Class for generate a simple form for simple data for a configuration database model
|
||||||
|
|
||||||
self.model_name=''
|
You can use this class if you need a simple table for configurations. You create the model and you can generate the configuration instancing this class in your admin
|
||||||
|
|
||||||
|
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:
|
||||||
|
model (WebModel) The webmodel used for generatre the admin model form
|
||||||
|
t (PTemplate): Template used for the class. Normally template subclassed from admin_t PTemplate
|
||||||
|
url (str): Base url used by GenerateConfigClass for different sections of update configuration model
|
||||||
|
url_redirect (str): The url where user is redirect when an operation is done
|
||||||
|
arr_fields_edit (list): A list with the fields that the user can edit
|
||||||
|
template_insert (str): The template used for the insert form
|
||||||
|
post_update (function): A Function with item id used how argument for make a post-progressing after update.
|
||||||
|
text_home (str): A str contening the text of home configuration
|
||||||
|
"""
|
||||||
|
|
||||||
|
#self.model_name=''
|
||||||
|
|
||||||
self.model=model
|
self.model=model
|
||||||
|
|
||||||
|
|
@ -225,6 +261,12 @@ class GenerateConfigClass:
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
|
||||||
|
""" Method for show the config admin model
|
||||||
|
|
||||||
|
Depending of op_config arg, you have the different sections of a simple configuration administrator
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
op_config=request.args.get('op_config', '0')
|
op_config=request.args.get('op_config', '0')
|
||||||
|
|
||||||
if len(self.model.forms)==0:
|
if len(self.model.forms)==0:
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,27 @@ if wsgi_gateway=='flask':
|
||||||
from flask import request
|
from flask import request
|
||||||
|
|
||||||
def get_query_args(key, default_value=''):
|
def get_query_args(key, default_value=''):
|
||||||
|
"""Simple shortcuts for get query args from a http request
|
||||||
|
|
||||||
|
A function that is used for have a shortcut for get query string args from a tipycal http request
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key (str): The arg name or query key for extract from args array
|
||||||
|
default_value (str): The default value if key is not set in args array
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
return request.args.get(key, default_value)
|
return request.args.get(key, default_value)
|
||||||
|
|
||||||
def get_post_args(key, default_value=''):
|
def get_post_args(key, default_value=''):
|
||||||
|
"""Simple shortcuts for get POST values from a http request
|
||||||
|
|
||||||
|
A function that is used for have a shortcut for get POST values from a tipycal http POST request
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key (str): The arg name or form key for extract from POST array
|
||||||
|
default_value (str): The default value if key is not set in args array
|
||||||
|
"""
|
||||||
|
|
||||||
return request.form.get(key, default_value)
|
return request.form.get(key, default_value)
|
||||||
|
|
||||||
|
|
@ -22,6 +39,15 @@ elif wsgi_gateway=='bottle':
|
||||||
from bottle import request
|
from bottle import request
|
||||||
|
|
||||||
def get_query_args(key, default_value=''):
|
def get_query_args(key, default_value=''):
|
||||||
|
"""Simple shortcuts for get query args from a http request
|
||||||
|
|
||||||
|
A function that is used for have a shortcut for get query string args from a tipycal http request
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key (str): The arg name or query key for extract from args array
|
||||||
|
default_value (str): The default value if key is not set in args array
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
return request.query.get(key, default_value)
|
return request.query.get(key, default_value)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ yes_session=False
|
||||||
i18n_module={}
|
i18n_module={}
|
||||||
|
|
||||||
def load_lang(*args):
|
def load_lang(*args):
|
||||||
|
"""A function for load the lang module dinamically
|
||||||
|
"""
|
||||||
|
|
||||||
for module in args:
|
for module in args:
|
||||||
|
|
||||||
|
|
@ -28,6 +30,15 @@ def load_lang(*args):
|
||||||
|
|
||||||
|
|
||||||
class I18n:
|
class I18n:
|
||||||
|
"""Class for i18n tasks
|
||||||
|
|
||||||
|
Class for i18n tasks, how, strings for every language supported, for now are en-US and es-ES. You can add more languages adding
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
default_lang (str): The default string lang used when get someone
|
||||||
|
dict_i18n (list): The list with default languages. You can add more calling it static variable in settings/config.py
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
default_lang='en-US'
|
default_lang='en-US'
|
||||||
|
|
||||||
|
|
@ -42,6 +53,7 @@ class I18n:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_default_lang():
|
def get_default_lang():
|
||||||
|
"""Static method for get the default lang"""
|
||||||
|
|
||||||
lang=I18n.default_lang
|
lang=I18n.default_lang
|
||||||
|
|
||||||
|
|
@ -52,11 +64,19 @@ class I18n:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def lang(module, symbol, text_default):
|
def lang(module, symbol, text_default):
|
||||||
|
"""Static method for get a string from selected language
|
||||||
|
|
||||||
|
Static method used to get the string of the selected language. If there is no string in the selected language, it returns text_default.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
module (str): The module to which the translation string belongs
|
||||||
|
symbol (str): Simple symbol that is useful for identify the string
|
||||||
|
text_default (str): The text used by default when there are not translation in the selected language
|
||||||
"""
|
"""
|
||||||
if not lang:
|
|
||||||
lang=I18n.get_default_lang()
|
#if not lang:
|
||||||
"""
|
# lang=I18n.get_default_lang()
|
||||||
|
|
||||||
lang=I18n.get_default_lang()
|
lang=I18n.get_default_lang()
|
||||||
|
|
||||||
I18n.l[lang]=I18n.l.get(lang, {})
|
I18n.l[lang]=I18n.l.get(lang, {})
|
||||||
|
|
@ -69,6 +89,11 @@ class I18n:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extract_value(value):
|
def extract_value(value):
|
||||||
|
"""Static method for get values from json lang array
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (json): Lang dict in json format
|
||||||
|
"""
|
||||||
|
|
||||||
value=json.loads(value)
|
value=json.loads(value)
|
||||||
|
|
||||||
|
|
@ -88,6 +113,15 @@ class I18n:
|
||||||
"""
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def lang_json(module, symbol, text_default):
|
def lang_json(module, symbol, text_default):
|
||||||
|
"""Static method for return a language dict in JSON
|
||||||
|
|
||||||
|
Static method used to get the string of the selected language in JSON format. If there are not string in the selected language, it returns text_default.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
module (str): The module to which the translation string belongs
|
||||||
|
symbol (str): Simple symbol that is useful for identify the string
|
||||||
|
text_default (str): The text used by default when there are not translation in the selected language
|
||||||
|
"""
|
||||||
|
|
||||||
arr_final={}
|
arr_final={}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,38 @@ from os import urandom
|
||||||
# Functions for create random strings usando urandom
|
# Functions for create random strings usando urandom
|
||||||
|
|
||||||
def create_key_encrypt(n=10):
|
def create_key_encrypt(n=10):
|
||||||
|
""" Simple function for create a random string
|
||||||
|
|
||||||
|
Simple function for create a random string based in sha512
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (int): size of string random bytes (view urandom function in Python3 Help)
|
||||||
|
"""
|
||||||
|
|
||||||
return sha512(urandom(n)).hexdigest()
|
return sha512(urandom(n)).hexdigest()
|
||||||
|
|
||||||
def create_key_encrypt_256(n=10):
|
def create_key_encrypt_256(n=10):
|
||||||
|
|
||||||
|
""" Simple function for create a random string
|
||||||
|
|
||||||
|
Simple function for create a random string based in sha256
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (int): size of string random bytes (view urandom function in Python3 Help)
|
||||||
|
"""
|
||||||
|
|
||||||
return sha256(urandom(n)).hexdigest()
|
return sha256(urandom(n)).hexdigest()
|
||||||
|
|
||||||
def create_key(n=10):
|
def create_key(n=10):
|
||||||
|
|
||||||
|
""" Simple function for create a random string
|
||||||
|
|
||||||
|
Simple function for create a random string based in urandom function and base64 encoding
|
||||||
|
|
||||||
|
Args:
|
||||||
|
n (int): size of string random bytes (view urandom function in Python3 Help)
|
||||||
|
"""
|
||||||
|
|
||||||
rand_bytes=urandom(n)
|
rand_bytes=urandom(n)
|
||||||
|
|
||||||
return b64encode(rand_bytes).decode('utf-8')[0:-2]
|
return b64encode(rand_bytes).decode('utf-8')[0:-2]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue