def set_home_view(self, request, object_id): page_content = self.get_object(request, object_id=unquote(object_id)) if page_content is None: raise self._get_404_exception(object_id) page = page_content.page if not page.has_change_permission(request.user): raise PermissionDenied("You do not have permission to set 'home'.") if not page.is_potential_home(): return HttpResponseBadRequest( force_text(_("The page is not eligible to be home."))) new_home_tree, old_home_tree = page.set_as_homepage(request.user) # Check if one of the affected pages either from the old homepage # or the homepage had an apphook attached if old_home_tree: apphooks_affected = old_home_tree.has_apphooks() else: apphooks_affected = False if not apphooks_affected: apphooks_affected = new_home_tree.has_apphooks() if apphooks_affected: # One or more pages affected by this operation was attached to an apphook. # As a result, fire the apphook reload signal to reload the url patterns. set_restart_trigger() info = (self.model._meta.app_label, self.model._meta.model_name) return HttpResponseRedirect( reverse("admin:{}_{}_changelist".format(*info)))
def update_apphooks(self): # User has changed the apphooks on the page. # Update the public version of the page to reflect this change immediately. self.instance.publisher_public.update( application_urls=self.instance.application_urls, application_namespace=self.instance.application_namespace, ) # Connects the apphook restart handler to the request finished signal set_restart_trigger()
def update_apphooks(self): # User has changed the apphooks on the page. # Update the public version of the page to reflect this change immediately. public_id = self.instance.publisher_public_id self._meta.model.objects.filter(pk=public_id).update( application_urls=self.instance.application_urls, application_namespace=(self.instance.application_namespace or None), ) # Connects the apphook restart handler to the request finished signal set_restart_trigger()
def post_delete_page(instance, **kwargs): if instance.application_urls: set_restart_trigger()