Add a mixin for ModelForms that allow limiting data to LocalSites.

Review Request #10364 — Created Dec. 26, 2018 and submitted

Review Board
10371, 10365

This introduces LocalSiteAwareModelFormMixin, which can be mixed into
any ModelForm that 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
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 the LocalSite 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

All unit tests passed.

Tested this with upcoming changes that convert forms over to using
this, and RBCommons usage of those forms.

  1. Ship It!
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-3.0.x (97d1f67)