89 lines
5.0 KiB
Python
89 lines
5.0 KiB
Python
"""
|
|
Project: PARTS Website
|
|
Author: Edward Middleton-Smith
|
|
Precision And Research Technology Systems Limited
|
|
|
|
Technology: View Models
|
|
Feature: Dog Dog Command Link View Model
|
|
|
|
Description:
|
|
Data model for dog dog command links view
|
|
"""
|
|
|
|
# internal
|
|
from business_objects.dog.button_icon import Button_Icon, Parameters_Button_Icon
|
|
from business_objects.dog.button_shape import Button_Shape, Parameters_Button_Shape
|
|
from business_objects.dog.colour import Colour, Parameters_Colour
|
|
from business_objects.dog.command import Command, Parameters_Command
|
|
from business_objects.dog.dog import Dog, Parameters_Dog
|
|
from business_objects.dog.command_button_link import Command_Button_Link, Parameters_Command_Button_Link
|
|
from business_objects.dog.location import Location, Parameters_Location
|
|
from business_objects.dog.obedience_level import Obedience_Level
|
|
from datastores.datastore_dog import DataStore_Dog
|
|
from models.model_view_dog_base import Model_View_Dog_Base
|
|
from forms.dog.command_button_link import Filters_Command_Button_Link
|
|
# from routes import bp_home
|
|
from helpers.helper_app import Helper_App
|
|
import lib.argument_validation as av
|
|
|
|
# external
|
|
from pydantic import BaseModel
|
|
from typing import ClassVar
|
|
from operator import attrgetter
|
|
|
|
class Model_View_Dog_Command_Button_Link(Model_View_Dog_Base):
|
|
filter_command_categories: list = None
|
|
filter_commands: list = None
|
|
filter_button_shapes: list = None
|
|
filter_colours: list = None
|
|
filter_button_icons: list = None
|
|
filter_locations: list = None
|
|
command_button_links: list = None
|
|
form_filters: Filters_Command_Button_Link = None
|
|
form_filters_old: Filters_Command_Button_Link
|
|
|
|
def __init__(self, form_filters_old, hash_page_current=Model_View_Dog_Base.HASH_PAGE_DOG_COMMAND_BUTTON_LINKS):
|
|
_m = 'Model_View_Dog_Command_Button_Link.__init__'
|
|
Helper_App.console_log(f'{_m}\nstarting...')
|
|
super().__init__(hash_page_current=hash_page_current, form_filters_old=form_filters_old)
|
|
self._title = 'Command Button Link'
|
|
self.form_filters = form_filters_old
|
|
datastore = DataStore_Dog()
|
|
|
|
user_session = datastore.get_user_session()
|
|
|
|
parameters_filter_command = Parameters_Command.get_default(user_session.id_user)
|
|
self.filter_command_categories, self.filter_commands, errors = datastore.get_many_command(parameters_filter_command)
|
|
if len(self.filter_command_categories) > 0:
|
|
self.form_filters.id_command_category.choices += [(str(command_category.id_command_category), command_category.name) for command_category in self.filter_command_categories]
|
|
if len(self.filter_commands) > 0:
|
|
Helper_App.console_log(f'filter commands: {self.filter_commands}')
|
|
sorted_filter_commands = self.filter_commands
|
|
sorted_filter_commands.sort(key = attrgetter('name'))
|
|
Helper_App.console_log(f'sorted filter commands: {sorted_filter_commands}')
|
|
self.form_filters.id_command.choices += [(str(command.id_command), command.name) for command in sorted_filter_commands] # .sort(key = lambda command: command[1])
|
|
|
|
parameters_filter_button_shape = Parameters_Button_Shape.get_default(user_session.id_user)
|
|
self.filter_button_shapes, errors = datastore.get_many_button_shape(parameters_filter_button_shape)
|
|
if len(self.filter_button_shapes) > 0:
|
|
self.form_filters.id_button_shape.choices += [(str(button_shape.id_button_shape), button_shape.name) for button_shape in self.filter_button_shapes]
|
|
|
|
parameters_filter_colour = Parameters_Colour.get_default()
|
|
self.filter_colours, errors = datastore.get_many_colour(parameters_filter_colour)
|
|
if len(self.filter_colours) > 0:
|
|
self.form_filters.id_colour.choices += [(str(colour.id_colour), colour.name) for colour in self.filter_colours]
|
|
|
|
parameters_filter_button_icon = Parameters_Button_Icon.get_default(user_session.id_user)
|
|
self.filter_button_icons, errors = datastore.get_many_button_icon(parameters_filter_button_icon)
|
|
if len(self.filter_button_icons) > 0:
|
|
self.form_filters.id_button_icon.choices += [(str(button_icon.id_button_icon), button_icon.name) for button_icon in self.filter_button_icons]
|
|
|
|
parameters_filter_location = Parameters_Location.get_default(user_session.id_user)
|
|
self.filter_locations, errors = datastore.get_many_location(parameters_filter_location)
|
|
if len(self.filter_locations) > 0:
|
|
self.form_filters.id_location.choices += [(str(location.id_location), location.name) for location in self.filter_locations]
|
|
|
|
Helper_App.console_log(f'Form filters: {self.form_filters}')
|
|
parameters_command_button_link = Parameters_Command_Button_Link.from_form_filters_command_button_link(self.form_filters, user_session.id_user)
|
|
Helper_App.console_log(f'Query args: {parameters_command_button_link}')
|
|
self.command_button_links, errors = datastore.get_many_command_button_link(parameters_command_button_link) |