Classes to manually run form validation for clinicedc/edc projects
Project description
edc-form-runners
Classes to manually run modelform validation for clinicedc/edc projects.
Rerun modelform validation
You can use the FormRunner to rerun modelform validation on all instances for a model.
You could do this:
runner = FormRunner(modelform)
runner.run()
If modelform validation does not validate, the validation message is captures in model Issue.
You could also run for every model in your EDC deployment by getting the ModelForm class from the admin registry and running FormRunner:
from django.apps import apps as django_apps
from edc_form_runners.form_runners import (
FormRunner,
FormRunnerError,
get_modelform_cls,
)
for app_config in django_apps.get_app_configs():
if app_config.name.startswith("edc_"):
continue
for model_cls in app_config.get_models():
if model_cls == Appointment:
continue
print(model_cls._meta.label_lower)
try:
modelform = get_modelform_cls(model_cls._meta.label_lower)
except FormRunnerError as e:
print(e)
else:
print(modelform)
try:
runner = FormRunner(modelform)
except AttributeError as e:
print(f"{e}. See {model_cls._meta.label_lower}.")
else:
try:
runner.run()
except (AttributeError, FieldError) as e:
print(f"{e}. See {model_cls._meta.label_lower}.")
You could also create a custom FormRunner for your model to add extra fields and ignore others.
For example:
class AppointmentFormRunner(FormRunner):
def __init__(self, modelform_cls: ModelForm = None, **kwargs):
modelform_cls = modelform_cls or AppointmentForm
extra_fieldnames = ["appt_datetime"]
ignore_fieldnames = ["appt_close_datetime"]
super().__init__(
modelform_cls=modelform_cls,
extra_formfields=extra_fieldnames,
ignore_formfields=ignore_fieldnames,
**kwargs,
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
edc-form-runners-0.1.0.tar.gz
(32.0 kB
view hashes)
Built Distribution
Close
Hashes for edc_form_runners-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5cef5ab283057ca111f1400d2b4d3e2392c15989b749cfeb5e7659c0ebd9aa3 |
|
MD5 | 0c9fce986ac6d7b1ae11a0e52d7fb986 |
|
BLAKE2b-256 | 7c8dff0f90b4f2ce8646d4478a9f29a26a06825ffd195bcb4a18eb48f87c9162 |