fairdm.core.formsets#

Shared formsets for the rows of related records a record carries.

Module Contents#

Functions#

date_ordering_formset

Return a formset class that refuses a backwards start/end date pair.

API#

date_ordering_formset(start_type, end_type, message)[source]#

Return a formset class that refuses a backwards start/end date pair.

A formset validates every form before any of them saves, so a per-row clean() that looks its sibling up in the database (as ProjectDate.clean() and DatasetDate.clean() do) sees no unsaved sibling when both dates are new rows in the same submission. The returned formset reads the start and end values off the forms’ cleaned_data instead, so the pair is checked whichever of the two (or both) is unsaved.

The message is passed whole rather than assembled from a noun so that each record type states its own date vocabulary and the sentence stays translatable as one unit.

Args: start_type: The address of the date type marking the start of the pair. end_type: The address of the date type marking the end of the pair. message: The error message, using %(start)s and %(end)s placeholders.

Returns: A BaseInlineFormSet subclass whose clean() raises a ValidationError when the end precedes the start.