1. Refactoring form objects and database objects to use inheritance and abstract base class for consistency and reduced redundancy.\n2. Contact us page button links updated to resolve error of missing link causing page refresh instead of expected functionality.
This commit is contained in:
BIN
forms/__pycache__/base.cpython-312.pyc
Normal file
BIN
forms/__pycache__/base.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
46
forms/base.py
Normal file
46
forms/base.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Backend
|
||||
Feature: Form Base and Meta Classes - data input
|
||||
|
||||
Description:
|
||||
Defines Flask-WTF base forms for handling user input.
|
||||
"""
|
||||
|
||||
# internal
|
||||
# external
|
||||
from flask_wtf import FlaskForm
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
|
||||
class Form_Base_Meta(type(FlaskForm), ABCMeta):
|
||||
pass
|
||||
|
||||
|
||||
class Form_Base(FlaskForm, metaclass=Form_Base_Meta):
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def from_filters(cls, filters):
|
||||
pass
|
||||
@abstractmethod
|
||||
def __repr__(self):
|
||||
pass
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def from_json(cls, json):
|
||||
pass
|
||||
"""
|
||||
@abstractmethod
|
||||
def test_69(self):
|
||||
pass
|
||||
|
||||
def get_Filters_Product_Category(data_request):
|
||||
data_form = data_request[Model_View_Store_Product_Category.KEY_FORM]
|
||||
form_filters = Filters_Product_Category(**data_form)
|
||||
form_filters.is_not_empty.data = av.input_bool(data_form['is_not_empty'], 'is_not_empty', 'filter_category')
|
||||
form_filters.active.data = av.input_bool(data_form['active'], 'active', 'filter_category')
|
||||
return form_filters
|
||||
"""
|
||||
@@ -14,11 +14,14 @@ Defines Flask-WTF forms for handling user input.
|
||||
# internal
|
||||
# from business_objects.store.product_category import Filters_Product_Category # circular
|
||||
# from models.model_view_store import Model_View_Store # circular
|
||||
from forms.base import Form_Base
|
||||
# external
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, TextAreaField, SubmitField, BooleanField, IntegerField, SelectField, FloatField
|
||||
from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional
|
||||
from flask_wtf.recaptcha import RecaptchaField
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
|
||||
|
||||
class Form_Contact(FlaskForm):
|
||||
@@ -141,5 +144,5 @@ class Form_Filters_Stock_Item(FlaskForm):
|
||||
|
||||
|
||||
class Form_Filters_User(FlaskForm):
|
||||
active_only = BooleanField('Active only?')
|
||||
active = BooleanField('Active only?')
|
||||
id_user = SelectField('User ID', validators=[Optional()], choices=[])
|
||||
BIN
forms/store/__pycache__/product.cpython-312.pyc
Normal file
BIN
forms/store/__pycache__/product.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
36
forms/store/product.py
Normal file
36
forms/store/product.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Backend
|
||||
Feature: Forms - Product Filter data input
|
||||
|
||||
Description:
|
||||
Defines Flask-WTF forms for handling user input.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
# from business_objects.store.product_category import Filters_Product_Category
|
||||
# from models.model_view_store import Model_View_Store # circular
|
||||
# external
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, TextAreaField, SubmitField, BooleanField, IntegerField, SelectField, FloatField
|
||||
from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional
|
||||
from flask_wtf.recaptcha import RecaptchaField
|
||||
|
||||
|
||||
class Form_Filters_Product(FlaskForm):
|
||||
id_category = SelectField('Category', validators=[Optional()], choices=[])
|
||||
is_not_empty = BooleanField('Not empty only?')
|
||||
active = BooleanField("Active only?")
|
||||
@classmethod
|
||||
def from_filters_product(cls, filters_product):
|
||||
form = Form_Filters_Product()
|
||||
form.id_category = filters_product.id_category
|
||||
form.is_not_empty.data = filters_product.is_not_empty
|
||||
form.active.data = filters_product.active
|
||||
return form
|
||||
def __repr__(self):
|
||||
return f'Form_Filters_Product(id_category={self.id_category}, is_not_empty={self.is_not_empty.data}, active={self.active.data})'
|
||||
@@ -4,31 +4,41 @@ Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Backend
|
||||
Feature: Forms - User data input
|
||||
Feature: Forms - Product Category Filters data input
|
||||
|
||||
Description:
|
||||
Defines Flask-WTF forms for handling user input.
|
||||
Defines Flask-WTF forms for handling product category filter input.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from business_objects.store.store_base import Store_Base
|
||||
# from business_objects.store.product_category import Filters_Product_Category
|
||||
# from models.model_view_store import Model_View_Store # circular
|
||||
# from helpers.DEPRECATED.helper_abc import Interface_ABC
|
||||
from forms.base import Form_Base
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, TextAreaField, SubmitField, BooleanField, IntegerField, SelectField, FloatField
|
||||
from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional
|
||||
from flask_wtf.recaptcha import RecaptchaField
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
|
||||
class Form_Filters_Product_Category(FlaskForm):
|
||||
class Filters_Product_Category(Form_Base):
|
||||
is_not_empty = BooleanField('Not empty only?')
|
||||
active = BooleanField("Active only?")
|
||||
@classmethod
|
||||
def from_filters_product_category(cls, filters_product_category):
|
||||
form = Form_Filters_Product_Category()
|
||||
form.is_not_empty.data = filters_product_category.is_not_empty_only
|
||||
form.active.data = filters_product_category.active_only
|
||||
def from_filters(cls, filters):
|
||||
form = Filters_Product_Category()
|
||||
form.is_not_empty.data = filters.is_not_empty
|
||||
form.active.data = filters.active
|
||||
return form
|
||||
def __repr__(self):
|
||||
return f'Form_Filters_Product_Category(is_not_empty={self.is_not_empty.data}, active={self.active.data})'
|
||||
return f'Filters_Product_Category(is_not_empty={self.is_not_empty.data}, active={self.active.data})'
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
form = Filters_Product_Category() # is_not_empty=json['is_not_empty'], active=json['active'])
|
||||
form.is_not_empty.data = av.input_bool(json[Store_Base.FLAG_IS_NOT_EMPTY], 'is_not_empty', 'Filters_Product_Category')
|
||||
form.active.data = av.input_bool(json[Store_Base.FLAG_ACTIVE], 'active', 'Filters_Product_Category')
|
||||
return form
|
||||
Reference in New Issue
Block a user