From cc3f230a3ac52bc84609f1229295855d91a73df6 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Mon, 4 Apr 2022 18:56:16 +0200 Subject: [PATCH] No need for a factory --- advlabdb/adminModelViews.py | 12 ++++++++---- advlabdb/customClasses.py | 9 --------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 289b070..9aff87c 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -16,17 +16,18 @@ from wtforms import Form from wtforms.fields import ( BooleanField, DateField, + DecimalField, IntegerField, RadioField, SelectField, StringField, ) from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional +from wtforms.widgets import NumberInput from advlabdb import adminSpace, app, assistantSpace, db, user_datastore from advlabdb.configUtils import getConfig from advlabdb.customClasses import ( - CustomDecimalFieldFactory, CustomIdEndpointLinkRowAction, SecureAdminBaseView, SecureAdminModelView, @@ -696,26 +697,29 @@ class SemesterExperimentView(SecureAdminModelView): blank_text="-", ) - oral_weighting = CustomDecimalFieldFactory(0.01)( + oral_weighting = DecimalField( "Oral weighting", validators=[DataRequired(), NumberRange(min=0, max=1)], default=0.5, description="Between 0 and 1", places=2, + widget=NumberInput(step=0.01), ) - protocol_weighting = CustomDecimalFieldFactory(0.01)( + protocol_weighting = DecimalField( "Protocol weighting", validators=[DataRequired(), NumberRange(min=0, max=1)], default=0.5, description="Between 0 and 1. Oral and protocol weightings have to add to 1! Both are rounded to 2 decimal digits.", places=2, + widget=NumberInput(step=0.01), ) - final_weighting = CustomDecimalFieldFactory(0.01)( + final_weighting = DecimalField( "Final weighting", validators=[DataRequired(), NumberRange(min=0, max=1)], default=1.0, description="Between 0 and 1", places=2, + widget=NumberInput(step=0.01), ) assistants = QuerySelectMultipleField("Assistants", query_factory=assistantQueryFactory) diff --git a/advlabdb/customClasses.py b/advlabdb/customClasses.py index 3c5c970..04d977b 100644 --- a/advlabdb/customClasses.py +++ b/advlabdb/customClasses.py @@ -5,8 +5,6 @@ from flask_admin.model.helpers import get_mdict_item_or_list from flask_admin.model.template import EndpointLinkRowAction from flask_security import current_user from sqlalchemy import and_ -from wtforms.fields import DecimalField -from wtforms.widgets import NumberInput from advlabdb.exceptions import DataBaseException, ModelViewException from advlabdb.models import ( @@ -271,10 +269,3 @@ class CustomIdEndpointLinkRowAction(EndpointLinkRowAction): def render(self, context, row_id, row): return super().render(context, self.customId(row), row) - - -def CustomDecimalFieldFactory(step): - class CustomDecimalField(DecimalField): - widget = NumberInput(step=step) - - return CustomDecimalField