Add a mixin for ModelForms that allow limiting data to LocalSites.
Review Request #10364 — Created Dec. 26, 2018 and submitted
LocalSiteAwareModelFormMixin, which can be mixed into
ModelFormthat may need to deal with
LocalSites. 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
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 the
LocalSitefield, though, the relation
fields will be validated to ensure they're on the same site, if a site
Forms can be limited to a particular
LocalSiteduring 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
All unit tests passed.
Tested this with upcoming changes that convert forms over to using
this, and RBCommons usage of those forms.