mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Add selection_mark_field
This commit is contained in:
parent
35560622dc
commit
80e7ff731f
1 changed files with 36 additions and 4 deletions
|
@ -1,11 +1,13 @@
|
|||
# Functions dependent on advlabdb.models
|
||||
|
||||
from functools import cache
|
||||
|
||||
from flask import flash, url_for
|
||||
from flask_admin.menu import MenuLink
|
||||
from flask_security import current_user
|
||||
from sqlalchemy import select
|
||||
from wtforms.fields import BooleanField, IntegerField, StringField
|
||||
from wtforms.validators import NumberRange, Optional
|
||||
from wtforms.fields import BooleanField, IntegerField, SelectField, StringField
|
||||
from wtforms.validators import DataRequired, NumberRange, Optional
|
||||
|
||||
from . import app, db
|
||||
from .models import MAX_MARK, MIN_MARK, Semester
|
||||
|
@ -44,15 +46,45 @@ def active_semester_str():
|
|||
return active_semester_str
|
||||
|
||||
|
||||
def mark_field(mark_type: str, default=None):
|
||||
def mark_field(mark_type: str):
|
||||
return IntegerField(
|
||||
mark_type + " Mark",
|
||||
default=default,
|
||||
validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)],
|
||||
description=f"Between {MIN_MARK} and {MAX_MARK}.",
|
||||
)
|
||||
|
||||
|
||||
@cache
|
||||
def selection_mark_field_choices():
|
||||
choices = [(mark, str(mark)) for mark in range(MAX_MARK, MIN_MARK - 1, -1)]
|
||||
choices.insert(0, (-1, "Not assigned yet"))
|
||||
|
||||
return choices
|
||||
|
||||
|
||||
def selection_mark_field(mark_type: str, default):
|
||||
choices = selection_mark_field_choices()
|
||||
|
||||
if default == None:
|
||||
default = -1
|
||||
|
||||
return SelectField(
|
||||
mark_type + " Mark",
|
||||
default=default,
|
||||
choices=choices,
|
||||
validators=[DataRequired()],
|
||||
render_kw={"class": "form-control"},
|
||||
)
|
||||
|
||||
|
||||
def parse_selection_mark_field(field):
|
||||
data = int(field.data)
|
||||
if data == -1:
|
||||
return None
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def user_info_fields():
|
||||
phone_number = StringField(
|
||||
"Phone Number",
|
||||
|
|
Loading…
Reference in a new issue