From 9fe99c8c72273c369ae43bc5d92d28f658f584ab Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 18 Apr 2022 19:15:20 +0200 Subject: [PATCH] More docs in webmodel.py --- paramecio2/libraries/db/webmodel.py | 51 ++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/paramecio2/libraries/db/webmodel.py b/paramecio2/libraries/db/webmodel.py index f4510cf..a5a83a1 100644 --- a/paramecio2/libraries/db/webmodel.py +++ b/paramecio2/libraries/db/webmodel.py @@ -13,10 +13,42 @@ import traceback class PhangoField: """Base class for fields used in WebModel classes - PhangoField is a class with all elements and variables that you can imagine for a + PhangoField is a class with all elements and variables that you can imagine for a database mysql field in a table. You have many types similar to mysql field types. """ def __init__(self, name, size=255, required=False): + """ + Args: + name (str): The name of the field + size (int): The size of sql field. + required (bool): If the field is required or not. + + Attributes: + name (str): The name of the field + label (str): A label or generic name for use in text labels used for representate the field + required (bool): If the field is required or not. + size (int): The size of sql field. + protected (bool): If the field can be updated or not in WebModel update method. + quote_close (str): In old versions was used for get more protection for sql sentences + error (bool): If error in query, set to True. + txt_error (str): Variable where the basic text error is saved + model (str): The model where this component or field live + indexed (bool): Property used for set this field how indexed in the database table. + unique (bool): Property used for set this field how unique value in the database table. + foreignkey (bool): Simple property for make more easy identify foreignkeyfields. + default_value (str): Property that define the default value for this field + update (bool): Property that define if this field is in an update operation or insert operation + check_blank (bool): Property used for check if this value cannot change if is in blank and is filled + name_form(BaseForm): Define the form, when is created forms with create_forms you can change the properties of this class + escape (bool): Property that define if make escape in show_formatted. This property control the html transformation of <>" characters in html entities.If false, convert. + file_related (bool): File related: if the field have a file related, delete the file + extra_parameters (list): Extra parameters for the form related with this field + t (PTemplate): Template manager for the form if needed + error_default (str): Error text by default + show_formatted_value (bool): Show this value formatted + help (str): Value used for help strings in tooltips in forms + + """ # The name of the field in database table @@ -54,7 +86,7 @@ class PhangoField: self.txt_error="" - # Themodel where this component or field live + # The model where this component or field live self.model=None @@ -113,22 +145,19 @@ class PhangoField: # Value used for help strings in tooltips in forms self.help='' - - # This method is used for describe the new field in a sql language format. - def get_type_sql(self): + """This method is used for describe the new field in a sql language format.""" return 'VARCHAR('+str(self.size)+') NOT NULL DEFAULT "'+self.default_value+'"' def show_formatted(self, value): + """Method for format the value to show in html or others text outputs""" return value - - # This method for check the value - def check(self, value): + """Method for check if value is valid for this type field""" self.error=False self.txt_error='' @@ -156,6 +185,7 @@ class PhangoField: pass def create_form(self): + """Create a BaseForm object for use in forms functions and methods""" #self.name, self.default_value, final_parameters=copy.copy(self.extra_parameters) @@ -171,6 +201,7 @@ class PhangoField: return form def change_form(self, new_form, parameters): + """Change the base form of the field and its parameters""" self.name_form=new_form @@ -180,6 +211,10 @@ class PhangoField: pass class PrimaryKeyField(PhangoField): + """Primary key field based in PhangoField. + + This field is used for create a typical id field in a mariadb/mysql table + """ def __init__(self, name, size=11, required=False): super(PrimaryKeyField, self).__init__(name, size, required)