Skip to content

Commit

Permalink
add method for soft validation
Browse files Browse the repository at this point in the history
  • Loading branch information
elichad committed Dec 5, 2023
1 parent a2065e5 commit 43c6fd1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/design/design_patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ This document acts as a reference for where certain design patterns can be found

**Method**:

1.
1. Add a field `<fieldname>-override` to the relevant model. This should be a `BooleanField` defaulting to `False`.
2. On `Form`s connected to the model, manipulate the `helper.layout` to show/hide the new field according to the value of the field you're implementing soft validation on (e.g. the `validate_member_code` method of `TrainingRequestForm` in [`/extforms/forms.py`](../../amy/extforms/forms.py) shows and hides the `member_code_override` field according to the validity of the `member_code`).
3. Build validation carefully for the override and the field it relates to. The override should only be required and `True` if the related field is invalid. In other cases, it should be `False` - this may require updating the value during validation (e.g. the `validate_member_code` method again).
4. Consider adding a filter to help admins find objects where the override was used. Beware that the default `django_filters.BooleanFilter` is not quite appropriate - typically you will want *all* results to be shown when the filter is `False`, and only results that use the override to be shown when the filter is `True` (e.g. `invalid_member_code` filter in `TrainingRequestFilter` in [/extrequests/filters.py](../../amy/extrequests/filters.py)).

**Reference files**:

Expand Down
1 change: 1 addition & 0 deletions docs/design/projects/2023_member_code_enforcement.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Other features added as part of this project:
* Update email autoresponses to include member code information
* Include a question about the Eventbrite event that a preapproved trainee has signed up for (if applicable) and allow admins to filter applications by Eventbrite event URLs or IDs.
* Updates to other questions on the instructor training application
* Utility functions to check if a membership is active on a certain date, find a membership from a member code, and to validate member codes in particular ways.

0 comments on commit 43c6fd1

Please sign in to comment.