FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 8ca86794 authored by Dr Catherine Pitt's avatar Dr Catherine Pitt
Browse files

Select a default form type dynamically for form generation

This sets up the main form generation form to pick a default form type
dynamically when rendering the form. If there is more than one form type
available to the person generating the form no default is returned,
forcing them to actively select one. But if they only have one type
available to them that type is set as the default to save them a click.
This was motivated by the need to allow embedded companies to generate
registration forms for their staff, but they should only be allowed to
generate 'visitor' forms. It therefore makes no sense to make them click
to pick that option.
parent f7478a12
No related branches found
No related tags found
No related merge requests found
Pipeline #352043 passed
......@@ -7,6 +7,7 @@ from wtforms import BooleanField, IntegerField, RadioField, TextAreaField, valid
from chemistry_starters.forms.widgets import StrippedStringField
from chemistry_starters.roles import roles
from chemistry_starters.utils.form_generation import get_form_type_default
form_types = [(x, roles[x]["form_title"]) for x in roles]
......@@ -17,7 +18,10 @@ class GenerateFormsForm(FlaskForm):
"""
form_type = RadioField(
"Type of form to generate", [validators.InputRequired()], choices=form_types
"Type of form to generate",
[validators.InputRequired()],
choices=form_types,
default=get_form_type_default,
)
starter_email = StrippedStringField(
"Contact email address for starter", [validators.Optional(), validators.Email()]
......
"""
Helper functions for the form generation views
"""
from flask import g
from chemistry_starters import database
from chemistry_starters.forms import form_generation as forms
......@@ -36,3 +37,17 @@ def is_form_imported(uuid):
"""
import_date = database.get_form_column("_imported_on", uuid)
return import_date is not None
def get_form_type_default():
"""
Get the default form type
Usually there is no default type, but if the person only has one form type
available, return that
"""
form_types = database.form_types_for_person(g.crsid)
if len(form_types) == 1:
return form_types[0]
else:
return None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment