Implement MailingList view supporting pagination.
This commit is contained in:
parent
cb7587c202
commit
b08ecdef17
31
musician/templates/musician/components/table_paginator.html
Normal file
31
musician/templates/musician/components/table_paginator.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
{# <!-- table footer based paginator for ListView --> #}
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2">{{ page_obj.paginator.count }} items in total</td>
|
||||
<td class="text-center">
|
||||
{% if page_obj.has_previous %}
|
||||
<a href="?page=1&per_page={{ page_obj.paginator.per_page }}">«</a>
|
||||
<a href="?page={{ page_obj.previous_page_number }}&per_page={{ page_obj.paginator.per_page }}">‹</a>
|
||||
{% endif %}
|
||||
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
|
||||
{% if page_obj.has_next %}
|
||||
<a href="?page={{ page_obj.next_page_number }}&per_page={{ page_obj.paginator.per_page }}">›</a>
|
||||
<a href="?page={{ page_obj.paginator.num_pages }}&per_page={{ page_obj.paginator.per_page }}">»</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td colspan="2" class="text-right">
|
||||
<form method="get">
|
||||
Showing
|
||||
<select name="{{ per_page_param }}">
|
||||
{% for value in per_page_values %}
|
||||
{% with page_obj.paginator.per_page as per_page %}
|
||||
<option value="{{ value }}" {% if value == per_page %}selected{% endif %}>{{ value }}</option>
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
per page
|
||||
<input type="submit" value="apply" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
|
@ -3,7 +3,30 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
<h1>Section title</h1>
|
||||
<h1>Mailing lists</h1>
|
||||
<p>Little description of what to be expected...</p>
|
||||
|
||||
<table class="table table-hover">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Status</th>
|
||||
<th scope="col">Address</th>
|
||||
<th scope="col">Admin email</th>
|
||||
<th scope="col">Configure</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for resource in object_list %}
|
||||
<tr>
|
||||
<th scope="row">{{ resource.name }}</th>
|
||||
<td>{{ resource.status }}</td>
|
||||
<td>{{ resource.address_name}}@{{ resource.address_domain.name }}</td>
|
||||
<td>{{ resource.admin_email }}</td>
|
||||
<td><a href="#TODO-{{ resource.manager_url }}" target="_blank" rel="noopener noreferrer">Mailtrain</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
{% include "musician/components/table_paginator.html" %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
|
|
@ -34,8 +34,30 @@ class MailView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
|||
template_name = "musician/mail.html"
|
||||
|
||||
|
||||
class MailingListsView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
||||
class MailingListsView(CustomContextMixin, UserTokenRequiredMixin, ListView):
|
||||
template_name = "musician/mailinglists.html"
|
||||
paginate_by = 20
|
||||
paginate_by_kwarg = 'per_page'
|
||||
|
||||
def get_queryset(self):
|
||||
return self.orchestra.retrieve_service_list('mailinglist')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update({
|
||||
'page_param': self.page_kwarg,
|
||||
'per_page_values': [5, 10, 20, 50],
|
||||
'per_page_param': self.paginate_by_kwarg,
|
||||
})
|
||||
return context
|
||||
|
||||
def get_paginate_by(self, queryset):
|
||||
per_page = self.request.GET.get(self.paginate_by_kwarg) or self.paginate_by
|
||||
try:
|
||||
paginate_by = int(per_page)
|
||||
except ValueError:
|
||||
paginate_by = self.paginate_by
|
||||
return paginate_by
|
||||
|
||||
|
||||
class DatabasesView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
||||
|
|
Loading…
Reference in a new issue