Add a mixin for ModelForms that allow limiting data to LocalSites.
Review Request #10364 — Created Dec. 26, 2018 and submitted
This introduces
LocalSiteAwareModelFormMixin
, which can be mixed into
anyModelForm
that may need to deal withLocalSite
s. It handles
validation of any relation fields (such as Many-to-Many/Foreign Key
choice fields) to ensure that any values selected are compatible with
the form.By default, forms are not tied to any
LocalSite
. They can create new
objects or edit existing ones, allowing the changing of a site, the same
way they do today. Based on theLocalSite
field, though, the relation
fields will be validated to ensure they're on the same site, if a site
is chosen.Forms can be limited to a particular
LocalSite
during construction. In
this mode, they can only create or edit instances for that site, and
relation values can only be chosen if they're bound to that site.This ensures consistent, testable behavior that can be plugged into any
ModelForm
. Future changes will begin to migrate some forms over to
this.
All unit tests passed.
Tested this with upcoming changes that convert forms over to using
this, and RBCommons usage of those forms.