Fixes in documentation for db model
This commit is contained in:
parent
ae3bf3f6c3
commit
3433b3150a
6 changed files with 159 additions and 2 deletions
|
|
@ -6,8 +6,30 @@ from html import escape
|
|||
#Forms para python3
|
||||
|
||||
class BaseForm:
|
||||
"""The class used by all forms classes
|
||||
|
||||
BaseForm is the base class used for all form classes.
|
||||
|
||||
A form class is used for generate simple html forms, how input type, text type, hidden type, etc. PhangoField classes use this forms for generate automatically forms using GenerateAdminClass and others.
|
||||
"""
|
||||
|
||||
def __init__(self, name, value):
|
||||
"""
|
||||
Args:
|
||||
name (str): The html name for this form
|
||||
value (str): The default value of this html form.
|
||||
|
||||
Attributes:
|
||||
label (str): Label used in functions how show_form that generate a complete html form from a form class list
|
||||
name (str): Name of the html form.
|
||||
default_value (mixed): The default value of the form. Equal to value in typical html form.
|
||||
css (str): Used for add css classes to the html form
|
||||
type (str): Variable used for conventional html forms with html tag <input>
|
||||
field (PhangoField): Field related with this form. Used in PhangoField.
|
||||
required (boolean): If form is required or not, used in functions that generate forms.
|
||||
name_field_id (str): The html id for the html form. Used for html things.
|
||||
help (str): A string with help text, used in functions that generate forms.
|
||||
"""
|
||||
|
||||
self.label=name
|
||||
self.name=name
|
||||
|
|
@ -21,22 +43,39 @@ class BaseForm:
|
|||
self.help=''
|
||||
|
||||
def form(self):
|
||||
"""Method for returm the html code of the form
|
||||
"""
|
||||
|
||||
return '<input type="'+self.type+'" class="'+self.css+'" name="'+self.name+'" id="'+self.name_field_id+'" value="'+self.setform(self.default_value)+'" />'
|
||||
|
||||
def show_formatted(self, value):
|
||||
"""Method for show the value of form formatted
|
||||
|
||||
Args:
|
||||
value (mixed): The value of field form
|
||||
"""
|
||||
|
||||
return value
|
||||
|
||||
#Method for escape value for html input. DON'T CHANGE IF YOU DON'T KNOWN WHAT ARE YOU DOING
|
||||
|
||||
def setform(self, value):
|
||||
"""A method for set the value in the form for escape and other things
|
||||
|
||||
Args:
|
||||
value (mixed): The value of field form for set
|
||||
"""
|
||||
|
||||
value=str(value)
|
||||
|
||||
return value.replace('"', '"').replace("'", ''')
|
||||
|
||||
def change_name(self, new_name):
|
||||
"""A method for change the default form html name of the field form
|
||||
|
||||
Args:
|
||||
new_name (str): The new name of the form. Always is finished with _form suffix
|
||||
"""
|
||||
|
||||
self.name=new_name
|
||||
|
||||
|
|
@ -45,6 +84,8 @@ class BaseForm:
|
|||
return ""
|
||||
|
||||
class SimpleTextForm(BaseForm):
|
||||
"""Form for simple text
|
||||
"""
|
||||
|
||||
def __init__(self, name, value):
|
||||
super().__init__(name, value)
|
||||
|
|
@ -56,6 +97,8 @@ class SimpleTextForm(BaseForm):
|
|||
return super().form()+' '+self.after_text
|
||||
|
||||
class TextForm(BaseForm):
|
||||
"""Form for simple text form
|
||||
"""
|
||||
|
||||
def __init__(self, name, value):
|
||||
super(TextForm, self).__init__(name, value)
|
||||
|
|
@ -65,6 +108,8 @@ class TextForm(BaseForm):
|
|||
return '<textarea class="'+self.css+'" name="'+self.name+'" id="'+self.name+'_form">'+self.setform(self.default_value)+'</textarea>'
|
||||
|
||||
class PasswordForm(BaseForm):
|
||||
"""Form for password forms
|
||||
"""
|
||||
|
||||
def __init__(self, name, value, show_password=False):
|
||||
super(PasswordForm, self).__init__(name, value)
|
||||
|
|
@ -79,6 +124,8 @@ class PasswordForm(BaseForm):
|
|||
return value
|
||||
|
||||
class HiddenForm(BaseForm):
|
||||
"""Form for hidden forms
|
||||
"""
|
||||
|
||||
def __init__(self, name, value):
|
||||
super(HiddenForm, self).__init__(name, value)
|
||||
|
|
@ -86,8 +133,16 @@ class HiddenForm(BaseForm):
|
|||
|
||||
|
||||
class SelectForm(BaseForm):
|
||||
"""Form for select html form
|
||||
"""
|
||||
|
||||
def __init__(self, name, value, elements=OrderedDict()):
|
||||
"""
|
||||
Args:
|
||||
ame (str): The html name for this form
|
||||
value (str): The default value of this html form
|
||||
elements (OrderedDict): An ordered dict with the keys(the form value) and text label. Example, if you have a OrderedDict how {'0': 'Value selected'} in a html select form you have the next result: <select name="name"><option value="0">Value selected</option></selected>
|
||||
"""
|
||||
super(SelectForm, self).__init__(name, value)
|
||||
self.arr_select=elements
|
||||
|
||||
|
|
@ -107,8 +162,20 @@ class SelectForm(BaseForm):
|
|||
return the_form
|
||||
|
||||
class SelectModelForm(SelectForm):
|
||||
"""Form for select html using a webmodel how base for get the data
|
||||
"""
|
||||
|
||||
def __init__(self, name, value, model, field_name, field_value, field_parent=None):
|
||||
"""
|
||||
Args:
|
||||
name (str): The html name for this form
|
||||
value (str): The default value of this html form.
|
||||
arr_select (OrderedDict): Used for save the data from the webmodel
|
||||
model (WebModel): The webmodel used for get the data for arr_select
|
||||
field_name (str): The field used for get the name of every option in select
|
||||
field_value (str): The field used for get the value of every option in select
|
||||
field_parent (int): If the model have parents or children, the value of this argument
|
||||
"""
|
||||
super(SelectModelForm, self).__init__(name, value)
|
||||
|
||||
try:
|
||||
|
|
@ -129,6 +196,10 @@ class SelectModelForm(SelectForm):
|
|||
|
||||
|
||||
def normal_form(self):
|
||||
"""Method for prepare the form hierated from SelectForm class, without parents
|
||||
|
||||
Method for prepare the form hierated from SelectForm class getting data from database using model attribute.
|
||||
"""
|
||||
|
||||
self.arr_select['']=''
|
||||
|
||||
|
|
@ -147,6 +218,10 @@ class SelectModelForm(SelectForm):
|
|||
return super().form()
|
||||
|
||||
def parent_form(self):
|
||||
"""Method for prepare the form hierated from SelectForm class, with parents
|
||||
|
||||
Method for prepare the form hierated from SelectForm class getting data from database using model attribute.
|
||||
"""
|
||||
|
||||
self.arr_select['']=''
|
||||
|
||||
|
|
@ -186,6 +261,8 @@ class SelectModelForm(SelectForm):
|
|||
|
||||
|
||||
def create_son(self, parent_id, arr_son, separator=''):
|
||||
"""Recursive method for generate parents and children dictionary
|
||||
"""
|
||||
|
||||
if parent_id in arr_son:
|
||||
for son in arr_son[parent_id]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue