1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

SelectField for final_part_mark

This commit is contained in:
Mo 2021-07-12 19:49:10 +02:00
parent 5b62f9e78e
commit 3b6f92efd9
3 changed files with 12 additions and 8 deletions

View file

@ -57,7 +57,7 @@ This URL leads to the home page where you can login with this testing admin acco
- Homepage text changeable - Homepage text changeable
- Email integration? - Email integration?
- 2FA? - 2FA?
- Students code for getting information? - Students code for getting information and giving feedback
- Database scripts - Database scripts
- Logging - Logging
- Documentation with Sphinx - Documentation with Sphinx

View file

@ -4,7 +4,7 @@ from flask_admin.menu import MenuLink
from flask_admin.model.template import EndpointLinkRowAction from flask_admin.model.template import EndpointLinkRowAction
from flask_security import current_user, hash_password from flask_security import current_user, hash_password
from sqlalchemy import func from sqlalchemy import func
from wtforms import Form, BooleanField, SelectField, TextField, RadioField, IntegerField from wtforms import Form, BooleanField, SelectField, TextField, RadioField
from wtforms.validators import DataRequired, Email, Optional from wtforms.validators import DataRequired, Email, Optional
from flask_admin.contrib.sqla.fields import QuerySelectMultipleField, QuerySelectField from flask_admin.contrib.sqla.fields import QuerySelectMultipleField, QuerySelectField
from flask_admin.helpers import get_form_data from flask_admin.helpers import get_form_data
@ -112,11 +112,8 @@ class SemesterView(SecureModelView):
column_details_list = column_list + ["active_users"] column_details_list = column_list + ["active_users"]
form_columns = ["semester_label", "year", "transfer_parts", "transfer_assistants"] form_columns = ["semester_label", "year", "transfer_parts", "transfer_assistants"]
semesterLabels = ["WS", "SS"]
form_extra_fields = { form_extra_fields = {
"semester_label": RadioField( "semester_label": RadioField("Semester", choices=["WS", "SS"], validators=[DataRequired()]),
"Semester", choices=list(zip(semesterLabels, semesterLabels)), validators=[DataRequired()]
),
"year": TextField("Year", validators=[DataRequired()]), "year": TextField("Year", validators=[DataRequired()]),
"transfer_parts": BooleanField( "transfer_parts": BooleanField(
"Transfer parts", "Transfer parts",
@ -242,7 +239,8 @@ class PartStudentView(SecureModelView):
class EditForm(CreateForm): class EditForm(CreateForm):
student = None student = None
part = None part = None
final_part_mark = IntegerField("Final Part Mark", validators=[Optional()]) marks = range(16)[::-1]
final_part_mark = SelectField("Final Part Mark", choices=[(-1, "-")] + list(zip(marks, marks)), coerce=int)
form = EditForm form = EditForm
@ -267,6 +265,12 @@ class PartStudentView(SecureModelView):
else: else:
return super().handle_view_exception(exc) return super().handle_view_exception(exc)
def update_model(self, form, model):
if form.final_part_mark.data == -1:
form.final_part_mark.data = None
return super().update_model(form, model)
class GroupView(SecureModelView): class GroupView(SecureModelView):
class CreateForm(Form): class CreateForm(Form):

View file

@ -293,7 +293,7 @@ class ExperimentMark(db.Model):
__table_args__ = (db.UniqueConstraint(part_student_id, group_experiment_id),) __table_args__ = (db.UniqueConstraint(part_student_id, group_experiment_id),)
def repr(self): def repr(self):
return f"Oral {round(self.oral_mark, 1)}; Prot {round(self.protocol_mark, 1)}" return f"Oral {self.oral_mark}; Prot {self.protocol_mark}"
def __repr__(self): def __repr__(self):
return f"<EXPMARL {self.repr()}>" return f"<EXPMARL {self.repr()}>"