1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

No need for a factory

This commit is contained in:
Mo 2022-04-04 18:56:16 +02:00
parent 34ee938636
commit cc3f230a3a
2 changed files with 8 additions and 13 deletions

View file

@ -16,17 +16,18 @@ from wtforms import Form
from wtforms.fields import ( from wtforms.fields import (
BooleanField, BooleanField,
DateField, DateField,
DecimalField,
IntegerField, IntegerField,
RadioField, RadioField,
SelectField, SelectField,
StringField, StringField,
) )
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional 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 import adminSpace, app, assistantSpace, db, user_datastore
from advlabdb.configUtils import getConfig from advlabdb.configUtils import getConfig
from advlabdb.customClasses import ( from advlabdb.customClasses import (
CustomDecimalFieldFactory,
CustomIdEndpointLinkRowAction, CustomIdEndpointLinkRowAction,
SecureAdminBaseView, SecureAdminBaseView,
SecureAdminModelView, SecureAdminModelView,
@ -696,26 +697,29 @@ class SemesterExperimentView(SecureAdminModelView):
blank_text="-", blank_text="-",
) )
oral_weighting = CustomDecimalFieldFactory(0.01)( oral_weighting = DecimalField(
"Oral weighting", "Oral weighting",
validators=[DataRequired(), NumberRange(min=0, max=1)], validators=[DataRequired(), NumberRange(min=0, max=1)],
default=0.5, default=0.5,
description="Between 0 and 1", description="Between 0 and 1",
places=2, places=2,
widget=NumberInput(step=0.01),
) )
protocol_weighting = CustomDecimalFieldFactory(0.01)( protocol_weighting = DecimalField(
"Protocol weighting", "Protocol weighting",
validators=[DataRequired(), NumberRange(min=0, max=1)], validators=[DataRequired(), NumberRange(min=0, max=1)],
default=0.5, default=0.5,
description="Between 0 and 1. Oral and protocol weightings have to add to 1! Both are rounded to 2 decimal digits.", description="Between 0 and 1. Oral and protocol weightings have to add to 1! Both are rounded to 2 decimal digits.",
places=2, places=2,
widget=NumberInput(step=0.01),
) )
final_weighting = CustomDecimalFieldFactory(0.01)( final_weighting = DecimalField(
"Final weighting", "Final weighting",
validators=[DataRequired(), NumberRange(min=0, max=1)], validators=[DataRequired(), NumberRange(min=0, max=1)],
default=1.0, default=1.0,
description="Between 0 and 1", description="Between 0 and 1",
places=2, places=2,
widget=NumberInput(step=0.01),
) )
assistants = QuerySelectMultipleField("Assistants", query_factory=assistantQueryFactory) assistants = QuerySelectMultipleField("Assistants", query_factory=assistantQueryFactory)

View file

@ -5,8 +5,6 @@ from flask_admin.model.helpers import get_mdict_item_or_list
from flask_admin.model.template import EndpointLinkRowAction from flask_admin.model.template import EndpointLinkRowAction
from flask_security import current_user from flask_security import current_user
from sqlalchemy import and_ from sqlalchemy import and_
from wtforms.fields import DecimalField
from wtforms.widgets import NumberInput
from advlabdb.exceptions import DataBaseException, ModelViewException from advlabdb.exceptions import DataBaseException, ModelViewException
from advlabdb.models import ( from advlabdb.models import (
@ -271,10 +269,3 @@ class CustomIdEndpointLinkRowAction(EndpointLinkRowAction):
def render(self, context, row_id, row): def render(self, context, row_id, row):
return super().render(context, self.customId(row), row) return super().render(context, self.customId(row), row)
def CustomDecimalFieldFactory(step):
class CustomDecimalField(DecimalField):
widget = NumberInput(step=step)
return CustomDecimalField