Split Attribute classes using inheritance
This commit is contained in:
parent
c56b07718e
commit
6055bcad17
@ -1,3 +1,5 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
"""
|
"""
|
||||||
class Attribute:
|
class Attribute:
|
||||||
def __init__(self, display_name, html_input_type="text", required=False, unique=False, primary=False, regex=None, min=None, max=None, options=None, default_val="", auto_increment=False, index=False, comment="", compareto=None):
|
def __init__(self, display_name, html_input_type="text", required=False, unique=False, primary=False, regex=None, min=None, max=None, options=None, default_val="", auto_increment=False, index=False, comment="", compareto=None):
|
||||||
@ -18,28 +20,90 @@ class Attribute:
|
|||||||
##default_val: Optional[str, int, float] = None, # HTML form input "value" attribute. Sets default value.
|
##default_val: Optional[str, int, float] = None, # HTML form input "value" attribute. Sets default value.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Base Attribute class
|
||||||
class Attribute:
|
class Attribute:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
display_name: str, # Input label or table column header.
|
display_name: str, # Input label or table column header.
|
||||||
html_input_type: str = "text", # HTML form input type. Determines MySQL data type.
|
html_input_type: str = "text", # HTML form input type. Determines MySQL data type.
|
||||||
placeholder: str = "text", # HTML form input placeholder.
|
placeholder: str = "", # HTML form input placeholder.
|
||||||
required: bool = False, # HTML form input "required" attribute and MySQL "Not Null" constraint
|
required: bool = False, # HTML form input "required" attribute and MySQL "Not Null" constraint
|
||||||
unique: bool = False, # MySQL "unique" constraint
|
unique: bool = False, # MySQL "unique" constraint
|
||||||
primary: bool = False, # MySQL "primary key" constraint
|
primary: bool = False, # MySQL "primary key" constraint
|
||||||
index: bool = False, # bool: MySQL index
|
index: bool = False, # bool: MySQL index
|
||||||
compareto: Optional[List[str]] = None, # Compare to another attribute of the item for validation: ["comparison", "referenceattrib"]
|
compareto: Optional[List[str]] = None, # Compare to another attribute of the item for validation: ["comparison", "referenceattrib"]
|
||||||
title: str ="" # Description text, html "title" attribute
|
title: str ="" # Description text, html "title" attribute
|
||||||
):
|
):
|
||||||
self.display_name = display_name
|
self.display_name = display_name
|
||||||
if not display_name:
|
|
||||||
return f"Missing display name for attribute '{attrib_name}'."
|
|
||||||
self.html_input_type = html_input_type
|
self.html_input_type = html_input_type
|
||||||
if not html_input_type:
|
|
||||||
return f"Missing input type for attribute '{attrib_name}'."
|
|
||||||
self.required = required
|
self.required = required
|
||||||
self.unique = unique
|
self.unique = unique
|
||||||
self.primary = primary
|
self.primary = primary
|
||||||
self.default_val = default_val
|
self.default_val = default_val
|
||||||
self.index = index
|
self.index = index
|
||||||
self.compareto = compareto
|
self.compareto = compareto
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
|
class textAttribute:
|
||||||
|
def __init__(self,
|
||||||
|
regex: str = None, # Regex for value validation
|
||||||
|
default_val: str = "", # Default value
|
||||||
|
compareto: Optional[List[Tuple[str, str]]] = None,
|
||||||
|
):
|
||||||
|
self.html_input_type = "text"
|
||||||
|
self.regex = regex
|
||||||
|
self.default_val = default_val
|
||||||
|
|
||||||
|
class intAttribute:
|
||||||
|
def __init__(self,
|
||||||
|
min_val: int = None, # Min value
|
||||||
|
max_val: int = None, # Max value
|
||||||
|
step_val: int = None, # Increment step
|
||||||
|
default_val: int = None, # Default value
|
||||||
|
auto_increment: bool = False, # bool: MySQL autoincrement
|
||||||
|
compareto: Optional[List[Tuple[str, str]]] = None,
|
||||||
|
):
|
||||||
|
self.html_input_type = "number"
|
||||||
|
self.min_val = min_val
|
||||||
|
self.max_val = max_val
|
||||||
|
self.step_val = step_val
|
||||||
|
self.default_val = default_val
|
||||||
|
self.auto_increment = auto_increment
|
||||||
|
|
||||||
|
class floatAttribute:
|
||||||
|
def __init__(self,
|
||||||
|
min_val: float = None, # Min value
|
||||||
|
max_val: float = None, # Max value
|
||||||
|
step_val: float = None, # Increment step
|
||||||
|
default_val: float = None, # Default value
|
||||||
|
auto_increment: bool = False, # bool: MySQL autoincrement
|
||||||
|
compareto: Optional[List[Tuple[str, str]]] = None,
|
||||||
|
):
|
||||||
|
self.html_input_type = "number"
|
||||||
|
self.min_val = min_val
|
||||||
|
self.max_val = max_val
|
||||||
|
self.step_val = step_val
|
||||||
|
self.default_val = default_val
|
||||||
|
self.auto_increment = auto_increment
|
||||||
|
|
||||||
|
class dateAttribute:
|
||||||
|
def __init__(self,
|
||||||
|
min_val = None, # Min value
|
||||||
|
max_val = None, # Max value
|
||||||
|
default_val = None, # Default value
|
||||||
|
compareto: Optional[List[Tuple[str, str]]] = None,
|
||||||
|
):
|
||||||
|
self.html_input_type = "date"
|
||||||
|
self.min_val = datetime.strptime(min_val, "%Y-%m-%d")
|
||||||
|
self.max_val = datetime.strptime(max_val, "%Y-%m-%d")
|
||||||
|
self.default_val = datetime.strptime(default_val, "%Y-%m-%d")
|
||||||
|
|
||||||
|
class selectAttribute:
|
||||||
|
def __init__(self,
|
||||||
|
options: Optional[List[str]] = None, # List of options
|
||||||
|
default_val: str = None, # Default value
|
||||||
|
):
|
||||||
|
self.html_input_type = "select"
|
||||||
|
self.options = options
|
||||||
|
self.default_val = default_val if default_val else self.options[0]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user