Closed btbonval closed 10 years ago
Within CourseForm
, we can validate that the school_id
is in the database. If it is blank or not in the database, set an error for it.
Here's one example of how to validate a form: https://github.com/FinalsClub/karmaworld/blob/a19007eba919017445625562ab19534b7b285c76/karmaworld/apps/courses/forms.py#L23-L39
For a single field, one can write def Form.clean_<fieldname>()
, so maybe clean_school()
would work?
The above example code uses a dynamic fieldname for the honeypot, so it isn't possible to write a single field cleansing function in that case (without using black python magic which would overly complicate matters).
@charlesconnell pointed out why this began failing recently. School used to be a required field. When School is not autocompleted, it is submitted as empty. That would fire off an internal Django magic error.
Since either School or Department may be submitted into Course for the moment, School is no longer required. Arbitrary text is completely ignored and no school is submitted in such cases, but there are no errors because Django and the database don't support "either/or" constraints, as they shouldn't.
This will be addressed in #294 .
Presently there is no form validation or form errors presented when the school is chosen by hand.
We should be able to work this into
CourseForm
orCourseListView
one way or another.The original attempt was to block the Save button until a valid school was chosen, but that doesn't seem to be reliable at the moment.