def for_moderation(request, revision_id): items = [ EditPageItem(PageRevision.objects.get(id=revision_id).page), AddPageItem(PageRevision.objects.get(id=revision_id).page), ApproveModerationEditPageItem( PageRevision.objects.get(id=revision_id)), RejectModerationEditPageItem(PageRevision.objects.get(id=revision_id)), ] for fn in hooks.get_hooks("construct_wagtail_userbar"): fn(request, items) # Render the items rendered_items = [item.render(request) for item in items] # Remove any unrendered items rendered_items = [item for item in rendered_items if item] # Render the edit bird return TemplateResponse( request, "wagtailadmin/userbar/base.html", { "items": rendered_items, }, )
def for_frontend(request, page_id): items = [ EditPageItem(Page.objects.get(id=page_id)), AddPageItem(Page.objects.get(id=page_id)), ] for fn in hooks.get_hooks('construct_wagtail_userbar'): fn(request, items) # Render the items rendered_items = [item.render(request) for item in items] # Remove any unrendered items rendered_items = [item for item in rendered_items if item] # Render the edit bird return render(request, 'wagtailadmin/userbar/base.html', { 'items': rendered_items, })
def for_frontend(request, page_id): items = [ EditPageItem(Page.objects.get(id=page_id)), AddPageItem(Page.objects.get(id=page_id)), ] for fn in hooks.get_hooks("construct_wagtail_userbar"): fn(request, items) # Render the items rendered_items = [item.render(request) for item in items] # Remove any unrendered items rendered_items = [item for item in rendered_items if item] # Render the edit bird return TemplateResponse( request, "wagtailadmin/userbar/base.html", { "items": rendered_items, }, )
def wagtailuserbar(context, position="bottom-right"): # Find request object try: request = context["request"] except KeyError: return "" # Don't render without a user because we can't check their permissions try: user = request.user except AttributeError: return "" # Don't render if user doesn't have permission to access the admin area if not user.has_perm("wagtailadmin.access_admin"): return "" # Render the userbar using the user's preferred admin language userprofile = UserProfile.get_for_user(user) with translation.override(userprofile.get_preferred_language()): page = get_page_instance(context) try: revision_id = request.revision_id except AttributeError: revision_id = None if page and page.id: if revision_id: items = [ AdminItem(), ExplorePageItem( PageRevision.objects.get(id=revision_id).page), EditPageItem( PageRevision.objects.get(id=revision_id).page), ApproveModerationEditPageItem( PageRevision.objects.get(id=revision_id)), RejectModerationEditPageItem( PageRevision.objects.get(id=revision_id)), ] else: # Not a revision items = [ AdminItem(), ExplorePageItem(Page.objects.get(id=page.id)), EditPageItem(Page.objects.get(id=page.id)), AddPageItem(Page.objects.get(id=page.id)), ] else: # Not a page. items = [AdminItem()] for fn in hooks.get_hooks("construct_wagtail_userbar"): fn(request, items) # Render the items rendered_items = [item.render(request) for item in items] # Remove any unrendered items rendered_items = [item for item in rendered_items if item] # Render the userbar items return render_to_string( "wagtailadmin/userbar/base.html", { "request": request, "items": rendered_items, "position": position, "page": page, "revision_id": revision_id, }, )
def wagtailuserbar(context, position='bottom-right'): # Find request object try: request = context['request'] except KeyError: return '' # Don't render without a user because we can't check their permissions try: user = request.user except AttributeError: return '' # Don't render if user doesn't have permission to access the admin area if not user.has_perm('wagtailadmin.access_admin'): return '' page = get_page_instance(context) try: revision_id = request.revision_id except AttributeError: revision_id = None if page and page.id: if revision_id: items = [ AdminItem(), ExplorePageItem(PageRevision.objects.get(id=revision_id).page), EditPageItem(PageRevision.objects.get(id=revision_id).page), ApproveModerationEditPageItem( PageRevision.objects.get(id=revision_id)), RejectModerationEditPageItem( PageRevision.objects.get(id=revision_id)), ] else: # Not a revision items = [ AdminItem(), ExplorePageItem(Page.objects.get(id=page.id)), EditPageItem(Page.objects.get(id=page.id)), AddPageItem(Page.objects.get(id=page.id)), ] else: # Not a page. items = [AdminItem()] for fn in hooks.get_hooks('construct_wagtail_userbar'): fn(request, items) # Render the items rendered_items = [item.render(request) for item in items] # Remove any unrendered items rendered_items = [item for item in rendered_items if item] # Render the userbar items return render_to_string( 'wagtailadmin/userbar/base.html', { 'request': request, 'items': rendered_items, 'position': position, 'page': page, 'revision_id': revision_id })
def wagtailuserbar(context, position='bottom-right'): # Find request object try: request = context['request'] except KeyError: return '' # Don't render without a user because we can't check their permissions try: user = request.user except AttributeError: return '' # Don't render if user doesn't have permission to access the admin area if not user.has_perm('wagtailadmin.access_admin'): return '' # Don't render if this is a preview. Since some routes can render the userbar without going through Page.serve(), # request.is_preview might not be defined. if getattr(request, 'is_preview', False): return '' # Only render if the context contains a variable referencing a saved page page = get_page_instance(context) if page is None: return '' # Dont render anything if the page has not been saved - i.e. a preview if page.pk is None: return '' try: revision_id = request.revision_id except AttributeError: revision_id = None if revision_id is None: items = [ AdminItem(), ExplorePageItem(Page.objects.get(id=page.id)), EditPageItem(Page.objects.get(id=page.id)), AddPageItem(Page.objects.get(id=page.id)), ] else: items = [ AdminItem(), ExplorePageItem(PageRevision.objects.get(id=revision_id).page), EditPageItem(PageRevision.objects.get(id=revision_id).page), AddPageItem(PageRevision.objects.get(id=revision_id).page), ApproveModerationEditPageItem( PageRevision.objects.get(id=revision_id)), RejectModerationEditPageItem( PageRevision.objects.get(id=revision_id)), ] for fn in hooks.get_hooks('construct_wagtail_userbar'): fn(request, items) # Render the items rendered_items = [item.render(request) for item in items] # Remove any unrendered items rendered_items = [item for item in rendered_items if item] # Render the userbar items return render_to_string( 'wagtailadmin/userbar/base.html', { 'request': request, 'items': rendered_items, 'position': position, 'page': page, 'revision_id': revision_id })