Feat(SQL, UI): 1. Dog Command Links page completed with get + set functionality. \n 2. Commands page and Command Categories page completed with get + set functionality.
This commit is contained in:
62
forms/dog/command.py
Normal file
62
forms/dog/command.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Backend
|
||||
Feature: Command Form
|
||||
|
||||
Description:
|
||||
Defines Flask-WTF form for handling user input on Commands page.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from dog_training.business_objects.base import Base
|
||||
from dog_training.business_objects.dog.command_category import Command_Category
|
||||
# from dog_training.business_objects.dog.command import Command # Circular
|
||||
from dog_training.helpers.helper_app import Helper_App
|
||||
# from dog_training.models.model_view_store import Model_View_Store # circular
|
||||
# from dog_training.models.model_view_base import Model_View_Base
|
||||
from dog_training.forms.base import Form_Base
|
||||
import dog_training.lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, request, flash, redirect, url_for, current_app
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import SelectField, BooleanField, StringField, SubmitField
|
||||
from wtforms.validators import DataRequired, Email, ValidationError
|
||||
import markupsafe
|
||||
from flask_wtf.recaptcha import RecaptchaField
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import json
|
||||
|
||||
class Filters_Command(Form_Base):
|
||||
search = StringField(
|
||||
'Search'
|
||||
)
|
||||
id_command_category = SelectField(
|
||||
'Command Category'
|
||||
, choices = [Form_Base.get_select_option_all()]
|
||||
, default = Form_Base.get_select_option_default_value()
|
||||
)
|
||||
active_only = BooleanField(
|
||||
'Active'
|
||||
, default = True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
filters = cls()
|
||||
filters.search.data = json[Base.FLAG_SEARCH]
|
||||
filters.id_command_category.data = json[Command_Category.ATTR_ID_COMMAND_CATEGORY]
|
||||
filters.active_only.data = av.input_bool(json[Base.FLAG_ACTIVE_ONLY], Base.FLAG_ACTIVE_ONLY, f'{cls.__name__}.from_json')
|
||||
return filters
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
Base.FLAG_SEARCH: self.search.data
|
||||
, Command_Category.ATTR_ID_COMMAND_CATEGORY: self.id_command_category.data
|
||||
, Base.FLAG_ACTIVE_ONLY: self.active_only.data
|
||||
}
|
||||
Reference in New Issue
Block a user