Skip to content

Instantly share code, notes, and snippets.

@marteinn
Last active August 10, 2020 13:46
Show Gist options
  • Save marteinn/25d4bd67a102d8eb19c8beb4480b3ee8 to your computer and use it in GitHub Desktop.
Save marteinn/25d4bd67a102d8eb19c8beb4480b3ee8 to your computer and use it in GitHub Desktop.
How to generate a report with all users in Wagtail
{% extends 'wagtailadmin/reports/base_report.html' %}
{% load i18n wagtailadmin_tags %}
{% block results %}
{% if object_list %}
<table class="listing">
<thead>
<tr>
<th class="title">
{% trans 'Name' %}
</th>
<th>
{% trans 'Username' %}
</th>
<th>
{% trans 'Level' %}
</th>
<th>
{% trans 'Status' %}
</th>
<th>
{% trans 'Last login' %}
</th>
</tr>
</thead>
<tbody>
{% for entry in object_list %}
<tr>
<td class="name">
{% include "wagtailadmin/shared/user_avatar.html" with user=entry.user username=entry.username %}
</td>
<td>
{{ entry.get_username }}
</td>
<td class="level" valign="top">{% if entry.is_superuser %}{% trans "Admin" %}{% endif %}</td>
<td class="status" valign="top">
<div class="status-tag {% if entry.is_active %}primary{% endif %}">
{% if entry.is_active %}{% trans "Active" %}{% else %}{% trans "Inactive" %}{% endif %}
</div>
</td>
<td>
{{ entry.last_login }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>{% trans "No users found." %}</p>
{% endif %}
{% endblock %}
{% block no_results %}
<p>{% trans "No users found." %}</p>
{% endblock %}
from wagtail.admin.views.reports import ReportView
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _
class AllUsersReportView(ReportView):
header_icon = 'user'
title = _("All users")
template_name = "reports/all_users_report.html"
list_export = [
"username",
"email",
]
export_headings = {
"username": _("Username"),
"email": _("Email"),
}
def get_queryset(self):
return User.objects.all()
from django.conf.urls import url
from django.urls import reverse
from wagtail.admin.menu import AdminOnlyMenuItem
from wagtail.core import hooks
from .views import AllUsersReportView
@hooks.register('register_reports_menu_item')
def register_unpublished_changes_report_menu_item():
return AdminOnlyMenuItem("All users", reverse('all_users_report'), classnames='icon icon-' + AllUsersReportView.header_icon, order=700)
@hooks.register('register_admin_urls')
def register_unpublished_changes_report_url():
return [
url(r'^reports/all-users/$', AllUsersReportView.as_view(), name='all_users_report'),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment