Created
September 17, 2020 18:08
-
-
Save cnk/ff82eb910e42a26b108395a149ea7025 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################################# | |
# Patch the wagtail.admin.forms.pages.PageViewRestrictionForm class to filter groups to only those available | |
# to the current site. | |
################################################################################################################# | |
def page_view_restriction_init(self, *args, **kwargs): | |
super(PageViewRestrictionForm, self).__init__(*args, **kwargs) | |
self.fields['groups'].widget = forms.CheckboxSelectMultiple() | |
# BEGIN PATCH | |
current_site = Site.find_for_request(get_current_request()) | |
self.fields['groups'].queryset = Group.objects.filter(name__istartswith=current_site.hostname) | |
# END PATCH | |
# and now use this method instead of the usual init | |
wagtail.admin.forms.pages.PageViewRestrictionForm.__init__ = page_view_restriction_init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Further questions showed up that
get_current_request
is from a custom middleware we have installed - that is a light wrapper around CrquestMiddleware#python