Initial commit.
This commit is contained in:
126
business_objects/dog/dog.py
Normal file
126
business_objects/dog/dog.py
Normal file
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Dog Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Dog(SQLAlchemy_ABC, Base):
|
||||
FLAG_DOG: ClassVar[str] = 'dog'
|
||||
FLAG_APPEARANCE: ClassVar[str] = 'appearance'
|
||||
FLAG_MASS_KG: ClassVar[str] = 'mass-kg'
|
||||
FLAG_NOTES: ClassVar[str] = 'notes'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = FLAG_DOG
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_EMAIL
|
||||
|
||||
__tablename__ = 'PH_Dog'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_dog = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(250))
|
||||
appearance = db.Column(db.String(1000))
|
||||
mass_kg = db.Column(db.Numeric(precision=7, scale=3))
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self):
|
||||
self.id_dog = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
def from_DB_Dog(query_row):
|
||||
_m = 'Dog.from_DB_Dog'
|
||||
dog = Dog()
|
||||
dog.id_dog = query_row[0]
|
||||
dog.name = query_row[1]
|
||||
dog.appearance = query_row[2]
|
||||
dog.mass_kg = query_row[3]
|
||||
dog.notes = query_row[4]
|
||||
dog.active = av.input_bool(query_row[5], 'active', _m)
|
||||
return dog
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = 'Dog.from_json'
|
||||
dog = cls()
|
||||
if json is None: return Dog
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
dog.id_dog = -1
|
||||
dog.name = json[cls.FLAG_NAME]
|
||||
dog.appearance = json[cls.FLAG_APPEARANCE]
|
||||
dog.mass_kg = json[cls.FLAG_MASS_KG]
|
||||
dog.notes = json[cls.FLAG_NOTES]
|
||||
dog.active = json[cls.FLAG_ACTIVE]
|
||||
Helper_App.console_log(f'Dog: {dog}')
|
||||
return dog
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
self.FLAG_DOG: self.id_dog
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_APPEARANCE: self.appearance
|
||||
, self.FLAG_MASS_KG: self.mass_kg
|
||||
, self.FLAG_NOTES: self.notes
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
}
|
||||
Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_DOG}: {self.id_dog}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_APPEARANCE}: {self.appearance}
|
||||
{self.FLAG_MASS_KG}: {self.mass_kg}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
"""
|
||||
class Dog_Temp(db.Model, Base):
|
||||
__tablename__ = 'PH_Dog_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_dog = db.Column(db.Integer)
|
||||
email = db.Column(db.String(250))
|
||||
name_contact = db.Column(db.String(250))
|
||||
name_company = db.Column(db.String(250))
|
||||
message = db.Column(db.Text)
|
||||
receive_marketing_communications = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_dog(cls, dog):
|
||||
_m = 'Dog_Temp.from_Dog'
|
||||
temp = cls()
|
||||
temp.id_dog = dog.id_dog
|
||||
temp.email = dog.email
|
||||
temp.name_contact = dog.name_contact
|
||||
temp.name_company = dog.name_company
|
||||
temp.message = dog.message
|
||||
temp.receive_marketing_communications = dog.receive_marketing_communications
|
||||
temp.active = dog.active
|
||||
temp.created_on = dog.created_on
|
||||
return temp
|
||||
"""
|
||||
Reference in New Issue
Block a user