Reputation: 627
I have a mini app where one type of users only has view access/rights to the wagtail admin interface. Those users can inspect models I have registered with modeladmin
. Right now if such a user logs in, they see an empty page (besides the menu), i.e. no last activity or such for them. Makes sense, since they don't have admin rights. But I'd like to avoid an empty page and display some custom html to them.
I know about registering a custom inspect/index view template in wagtail_hooks.py
by setting the [inspect | index]_template_name
attribute, but that's on the model level.
Is it possible to use a custom template replacing wagtailadmin/home.html
?
EDIT
The docs show ways to edit some parts of the admin area like the branding or the welcome message. But not for the main content.
EDIT 2
To build upon @gasmans answer. If you need the request object you can create a panel like this
# wagtail_hooks.py
class WelcomePanel:
order = 50
def __init__(self, request):
self.request = request
self.logged_in_user = request.user.username
def render(self):
return render_to_string('wagtailadmin/home/my_message.html', {
'logged_in_user': self.logged_in_user,
}, request=self.request)
# simply pass the 'request' to the panel
@hooks.register('construct_homepage_panels')
def add_another_welcome_panel(request, panels):
panels.append(WelcomePanel(request))
Upvotes: 1
Views: 563
Reputation: 25237
The standard way of adding new items to the Wagtail admin homepage is the construct_homepage_panels
hook: https://docs.wagtail.io/en/stable/reference/hooks.html#construct-homepage-panels
Overriding the homepage template is an option too, but is less stable - the layout or content of the homepage (and thus the variables passed to it) may change in future Wagtail releases.
Upvotes: 2
Reputation: 627
I got it.
Create a template file dashboard/templates/wagtailadmin/home.html
and copy all html from Wagtails source template. Then add your own content.
{% extends "wagtailadmin/home.html" %}
{% load wagtailadmin_tags i18n %}
{% block titletag %}{% trans "Dashboard" %}{% endblock %}
{% block bodyclass %}homepage{% endblock %}
{% block content %}
<header class="merged nice-padding">
<div class="row row-flush">
<div class="col1">
<div class="avatar"><img src="{% avatar_url user %}" alt="" /></div>
</div>
<div class="col9">
<h1>{% block branding_welcome %}{% blocktrans %}Welcome to the {{ site_name }} Wagtail CMS{% endblocktrans %}{% endblock %}</h1>
<div class="user-name">{{ user.get_full_name|default:user.get_username }}</div>
</div>
</div>
</header>
{% if panels %}
{% for panel in panels %}
{{ panel.render }}
{% endfor %}
{% else %}
<p>{% trans "This is your dashboard on which helpful information about content you've created will be displayed." %}</p>
{% endif %}
<!-- Here comes the custom code -->
<h1>Custom content</h1>
{% endblock %}
Upvotes: 2