256 lines
11 KiB
Python
256 lines
11 KiB
Python
"""
|
|
Project: PARTS Website
|
|
Author: Edward Middleton-Smith
|
|
Precision And Research Technology Systems Limited
|
|
|
|
Technology: Business Objects
|
|
Feature: Calendar_Entry Business Object
|
|
"""
|
|
|
|
# internal
|
|
from business_objects.base import Base
|
|
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
|
from business_objects.dog.calendar_entry_type import Calendar_Entry_Type
|
|
import lib.argument_validation as av
|
|
from extensions import db
|
|
from forms.dog.calendar_entry import Filters_Calendar_Entry
|
|
from helpers.helper_app import Helper_App
|
|
# external
|
|
from dataclasses import dataclass
|
|
from typing import ClassVar
|
|
|
|
|
|
class Calendar_Entry(SQLAlchemy_ABC, Base):
|
|
ATTR_ID_CALENDAR_ENTRY: ClassVar[str] = 'id_calendar_entry'
|
|
FLAG_CALENDAR_ENTRY: ClassVar[str] = 'calendar_entry'
|
|
FLAG_IS_CALENDAR_ENTRY_TYPE_BILL: ClassVar[str] = 'is-calendar-entry-type-bill'
|
|
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_CALENDAR_ENTRY
|
|
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
|
|
|
__tablename__ = 'DOG_Calendar_Entry'
|
|
__table_args__ = { 'extend_existing': True }
|
|
|
|
id_calendar_entry = db.Column(db.Integer, primary_key=True)
|
|
id_calendar_entry_type = db.Column(db.Integer)
|
|
name = db.Column(db.String(250))
|
|
start_on = db.Column(db.DateTime)
|
|
end_on = db.Column(db.DateTime)
|
|
price = db.Column(db.Float)
|
|
active = db.Column(db.Boolean)
|
|
created_on = db.Column(db.DateTime)
|
|
|
|
def __init__(self):
|
|
self.id_calendar_entry = 0
|
|
self.calendar_entry_type = None
|
|
self.is_new = False
|
|
self.is_calendar_entry_type_bill = None
|
|
super().__init__()
|
|
|
|
@classmethod
|
|
def from_db_calendar_entry(cls, query_row):
|
|
_m = f'{cls.__qualname__}.from_db_calendar_entry'
|
|
calendar_entry = cls()
|
|
calendar_entry.id_calendar_entry = query_row[0]
|
|
calendar_entry.id_calendar_entry_type = query_row[1]
|
|
calendar_entry.name = query_row[2]
|
|
calendar_entry.start_on = query_row[3]
|
|
calendar_entry.end_on = query_row[4]
|
|
calendar_entry.price = query_row[5]
|
|
calendar_entry.active = av.input_bool(query_row[6], 'active', _m)
|
|
calendar_entry.is_calendar_entry_type_bill = query_row[7]
|
|
calendar_entry.calendar_entry_type = Calendar_Entry_Type.from_db_calendar_entry(query_row)
|
|
return calendar_entry
|
|
|
|
@classmethod
|
|
def from_json(cls, json):
|
|
_m = f'{cls.__qualname__}.from_json'
|
|
calendar_entry = cls()
|
|
if json is None: return calendar_entry
|
|
calendar_entry.id_calendar_entry = json.get(Calendar_Entry.ATTR_ID_CALENDAR_ENTRY, -1)
|
|
calendar_entry.id_calendar_entry_type = json[Calendar_Entry_Type.ATTR_ID_CALENDAR_ENTRY_TYPE]
|
|
calendar_entry.name = json[cls.FLAG_NAME]
|
|
calendar_entry.start_on = json[cls.FLAG_DATE_FROM]
|
|
calendar_entry.end_on = json[cls.FLAG_DATE_TO]
|
|
calendar_entry.price = json[cls.FLAG_PRICE]
|
|
calendar_entry.is_calendar_entry_type_bill = json.get(cls.FLAG_IS_CALENDAR_ENTRY_TYPE_BILL, None)
|
|
calendar_entry.active = av.input_bool(json[cls.FLAG_ACTIVE], cls.FLAG_ACTIVE, _m)
|
|
calendar_entry.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
|
return calendar_entry
|
|
|
|
def to_json(self):
|
|
as_json = {
|
|
**self.get_shared_json_attributes(self)
|
|
, self.ATTR_ID_CALENDAR_ENTRY: self.id_calendar_entry
|
|
, Calendar_Entry_Type.ATTR_ID_CALENDAR_ENTRY_TYPE: self.id_calendar_entry_type
|
|
, self.FLAG_NAME: self.name
|
|
, self.FLAG_DATE_FROM: self.start_on
|
|
, self.FLAG_DATE_TO: self.end_on
|
|
, self.FLAG_PRICE: self.price
|
|
, self.FLAG_IS_CALENDAR_ENTRY_TYPE_BILL: self.is_calendar_entry_type_bill
|
|
, self.FLAG_ACTIVE: self.active
|
|
, self.FLAG_CREATED_ON: self.created_on
|
|
}
|
|
return as_json
|
|
|
|
def __repr__(self):
|
|
return f'''
|
|
{self.__class__.__name__}(
|
|
{self.FLAG_CALENDAR_ENTRY}: {self.id_calendar_entry}
|
|
{Calendar_Entry_Type.ATTR_ID_CALENDAR_ENTRY_TYPE}: {self.id_calendar_entry_type}
|
|
{self.FLAG_NAME}: {self.name}
|
|
{self.FLAG_DATE_FROM}: {self.start_on}
|
|
{self.FLAG_DATE_TO}: {self.end_on}
|
|
{self.FLAG_PRICE}: {self.price}
|
|
{self.FLAG_IS_CALENDAR_ENTRY_TYPE_BILL}: {self.is_calendar_entry_type_bill}
|
|
{self.FLAG_ACTIVE}: {self.active}
|
|
{self.FLAG_CREATED_ON}: {self.created_on}
|
|
)
|
|
'''
|
|
"""
|
|
class Calendar_Entry_Temp(db.Model, Base):
|
|
__tablename__ = 'DOG_Calendar_Entry_Temp'
|
|
__table_args__ = { 'extend_existing': True }
|
|
id_temp = db.Column(db.Integer, primary_key=True)
|
|
id_calendar_entry = db.Column(db.Integer)
|
|
id_calendar_entry_type = db.Column(db.Integer)
|
|
code = db.Column(db.String(250))
|
|
name = db.Column(db.String(250))
|
|
notes = db.Column(db.Text)
|
|
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_calendar_entry(cls, calendar_entry):
|
|
_m = 'Calendar_Entry_Temp.from_calendar_entry'
|
|
temp = cls()
|
|
temp.id_calendar_entry = calendar_entry.id_calendar_entry
|
|
temp.id_calendar_entry_type = calendar_entry.id_calendar_entry_type
|
|
temp.code = calendar_entry.code
|
|
temp.name = calendar_entry.name
|
|
temp.notes = calendar_entry.notes
|
|
temp.active = calendar_entry.active
|
|
# temp.created_on = calendar_entry.created_on
|
|
return temp
|
|
|
|
def __repr__(self):
|
|
return f'''
|
|
{self.__class__.__name__}(
|
|
{Calendar_Entry.FLAG_CALENDAR_ENTRY}: {self.id_calendar_entry}
|
|
{Calendar_Entry_Type.FLAG_CALENDAR_ENTRY_TYPE}: {self.id_calendar_entry_type}
|
|
{self.FLAG_CODE}: {self.code}
|
|
{self.FLAG_NAME}: {self.name}
|
|
{self.FLAG_NOTES}: {self.notes}
|
|
{self.FLAG_ACTIVE}: {self.active}
|
|
)
|
|
'''
|
|
|
|
class Parameters_Calendar_Entry(Get_Many_Parameters_Base):
|
|
get_all_file_type: bool
|
|
get_inactive_file_type: bool
|
|
ids_file_type: str
|
|
names_file_type: str
|
|
get_all_calendar_entry_type: bool
|
|
get_inactive_calendar_entry_type: bool
|
|
ids_calendar_entry_type: str
|
|
names_calendar_entry_type: str
|
|
get_all_calendar_entry: bool
|
|
get_inactive_calendar_entry: bool
|
|
ids_calendar_entry: str
|
|
names_calendar_entry: str
|
|
notes_calendar_entry: str
|
|
require_all_id_search_filters_met: bool
|
|
require_any_id_search_filters_met: bool
|
|
require_all_non_id_search_filters_met: bool
|
|
require_any_non_id_search_filters_met: bool
|
|
|
|
@classmethod
|
|
def get_default(cls):
|
|
return cls(
|
|
get_all_file_type = True
|
|
, get_inactive_file_type = False
|
|
, ids_file_type = ''
|
|
, names_file_type = ''
|
|
, get_all_calendar_entry_type = True
|
|
, get_inactive_calendar_entry_type = False
|
|
, ids_calendar_entry_type = ''
|
|
, names_calendar_entry_type = ''
|
|
, get_all_calendar_entry = True
|
|
, get_inactive_calendar_entry = False
|
|
, ids_calendar_entry = ''
|
|
, names_calendar_entry = ''
|
|
, notes_calendar_entry = ''
|
|
, require_all_id_search_filters_met = True
|
|
, require_any_id_search_filters_met = True
|
|
, require_all_non_id_search_filters_met = False
|
|
, require_any_non_id_search_filters_met = True
|
|
)
|
|
|
|
@classmethod
|
|
def from_json(cls, json):
|
|
return cls(
|
|
get_all_file_type = json.get('a_get_all_file_type', False)
|
|
, get_inactive_file_type = json.get('a_get_inactive_file_type', False)
|
|
, ids_file_type = json.get('a_ids_file_type', '')
|
|
, names_file_type = json.get('a_names_file_type', '')
|
|
, get_all_calendar_entry_type = json.get('a_get_all_calendar_entry_type', False)
|
|
, get_inactive_calendar_entry_type = json.get('a_get_inactive_calendar_entry_type', False)
|
|
, ids_calendar_entry_type = json.get('a_ids_calendar_entry_type', '')
|
|
, names_calendar_entry_type = json.get('a_names_calendar_entry_type', '')
|
|
, get_all_calendar_entry = json.get('a_get_all_calendar_entry', False)
|
|
, get_inactive_calendar_entry = json.get('a_get_inactive_calendar_entry', False)
|
|
, ids_calendar_entry = json.get('a_ids_calendar_entry', '')
|
|
, names_calendar_entry = json.get('a_names_calendar_entry', '')
|
|
, notes_calendar_entry = json.get('a_notes_calendar_entry', '')
|
|
, require_all_id_search_filters_met = json.get('a_require_all_id_search_filters_met', True)
|
|
, require_any_id_search_filters_met = json.get('a_require_any_id_search_filters_met', True)
|
|
, require_all_non_id_search_filters_met = json.get('a_require_all_non_id_search_filters_met', False)
|
|
, require_any_non_id_search_filters_met = json.get('a_require_any_non_id_search_filters_met', True)
|
|
)
|
|
|
|
@classmethod
|
|
def from_form_filters_calendar_entry(cls, form):
|
|
av.val_instance(form, 'form', 'Parameters_Calendar_Entry.from_form_filters_calendar_entry', Filters_Calendar_Entry)
|
|
has_filter_search_text = not (form.search.data == '' or form.search.data is None)
|
|
active_only = av.input_bool(form.active_only.data, "active", "Parameters_Calendar_Entry.from_form_filters_calendar_entry")
|
|
filters = cls.get_default()
|
|
filters.get_all_file_type = True
|
|
filters.get_inactive_file_type = not active_only
|
|
filters.ids_file_type = ''
|
|
filters.names_file_type = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_calendar_entry_type = True
|
|
filters.get_inactive_calendar_entry_type = not active_only
|
|
filters.ids_calendar_entry_type = ''
|
|
filters.names_calendar_entry_type = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_calendar_entry = True
|
|
filters.get_inactive_calendar_entry = not active_only
|
|
filters.ids_calendar_entry = ''
|
|
filters.names_calendar_entry = form.search.data if has_filter_search_text else ''
|
|
filters.notes_calendar_entry = form.search.data if has_filter_search_text else ''
|
|
return filters
|
|
|
|
def to_json(self):
|
|
return {
|
|
'a_get_all_file_type': self.get_all_file_type
|
|
, 'a_get_inactive_file_type': self.get_inactive_file_type
|
|
, 'a_ids_file_type': self.ids_file_type
|
|
, 'a_names_file_type': self.names_file_type
|
|
, 'a_get_all_calendar_entry_type': self.get_all_calendar_entry_type
|
|
, 'a_get_inactive_calendar_entry_type': self.get_inactive_calendar_entry_type
|
|
, 'a_ids_calendar_entry_type': self.ids_calendar_entry_type
|
|
, 'a_names_calendar_entry_type': self.names_calendar_entry_type
|
|
, 'a_get_all_calendar_entry': self.get_all_calendar_entry
|
|
, 'a_get_inactive_calendar_entry': self.get_inactive_calendar_entry
|
|
, 'a_ids_calendar_entry': self.ids_calendar_entry
|
|
, 'a_names_calendar_entry': self.names_calendar_entry
|
|
, 'a_notes_calendar_entry': self.notes_calendar_entry
|
|
, 'a_require_all_id_search_filters_met': self.require_all_id_search_filters_met
|
|
, 'a_require_any_id_search_filters_met': self.require_any_id_search_filters_met
|
|
, 'a_require_all_non_id_search_filters_met': self.require_all_non_id_search_filters_met
|
|
, 'a_require_any_non_id_search_filters_met': self.require_any_non_id_search_filters_met
|
|
}
|
|
"""
|