def get_permission_policy(self): if self.permission_policy: return self.permission_policy elif self.model: return ModelPermissionPolicy(self.model) else: return BlanketPermissionPolicy(None)
def register(self, model, **kwargs): """ Register a model as a setting, adding it to the wagtail admin menu """ # Don't bother registering this if it is already registered if model in self: return model self.append(model) # Register a new menu item in the settings menu @hooks.register("register_settings_menu_item") def menu_hook(): return SettingMenuItem(model, **kwargs) @hooks.register("register_permissions") def permissions_hook(): return Permission.objects.filter( content_type__app_label=model._meta.app_label, codename="change_{}".format(model._meta.model_name), ) # Register an admin URL finder permission_policy = ModelPermissionPolicy(model) finder_class = type( "_SettingsAdminURLFinder", (SettingsAdminURLFinder, ), { "model": model, "permission_policy": permission_policy }, ) register_admin_url_finder(model, finder_class) return model
from wagtail.contrib.redirects.models import Redirect from wagtail.permission_policies import ModelPermissionPolicy permission_policy = ModelPermissionPolicy(Redirect)
class UserAdminURLFinder(ModelAdminURLFinder): edit_url_name = "wagtailusers_users:edit" permission_policy = ModelPermissionPolicy(User)
class SearchPromotionAdminURLFinder(ModelAdminURLFinder): permission_policy = ModelPermissionPolicy(SearchPromotion) def construct_edit_url(self, instance): return reverse("wagtailsearchpromotions:edit", args=(instance.query.id, ))
from wagtail.models import Collection, Locale, Site, Task, Workflow from wagtail.permission_policies import ModelPermissionPolicy from wagtail.permission_policies.collections import CollectionMangementPermissionPolicy site_permission_policy = ModelPermissionPolicy(Site) collection_permission_policy = CollectionMangementPermissionPolicy(Collection) task_permission_policy = ModelPermissionPolicy(Task) workflow_permission_policy = ModelPermissionPolicy(Workflow) locale_permission_policy = ModelPermissionPolicy(Locale)