Feat: Multiplayer sessions added using CRUD database.
This commit is contained in:
70
forms/base.py
Normal file
70
forms/base.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
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
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from flask_wtf import FlaskForm
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from wtforms import SelectField, BooleanField, SubmitField
|
||||
from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional
|
||||
|
||||
|
||||
class Form_Base_Meta(type(FlaskForm), ABCMeta):
|
||||
pass
|
||||
|
||||
|
||||
class Form_Base(FlaskForm, metaclass=Form_Base_Meta):
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def from_json(cls, json):
|
||||
Helper_App.console_log(f'Error: Parent classes of {cls.__qualname__} must define cls.from_json')
|
||||
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls()
|
||||
@classmethod
|
||||
def get_select_option_blank(cls, is_valid = True):
|
||||
value = cls.get_select_valid_option_default_value() if is_valid else cls.get_select_invalid_option_default_value()
|
||||
return (value, 'Select')
|
||||
@classmethod
|
||||
def get_select_option_all(cls):
|
||||
return (cls.get_select_valid_option_default_value(), 'All')
|
||||
|
||||
@staticmethod
|
||||
def get_select_valid_option_default_value():
|
||||
return '0'
|
||||
@staticmethod
|
||||
def get_select_invalid_option_default_value():
|
||||
return ''
|
||||
|
||||
def __repr__(self):
|
||||
fields = ', '.join(
|
||||
f"{name}={field.data}" for name, field in self._fields.items()
|
||||
)
|
||||
return f"{self.__class__.__name__}({fields})"
|
||||
|
||||
'''
|
||||
class Filters_Stored_Procedure_Base(Form_Base):
|
||||
"""
|
||||
@abstractmethod
|
||||
def __repr__(self):
|
||||
pass
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def from_json(cls, json):
|
||||
pass
|
||||
"""
|
||||
@abstractmethod
|
||||
def to_json(self):
|
||||
pass
|
||||
'''
|
||||
Reference in New Issue
Block a user