Allow filter address by domain name

This commit is contained in:
Santiago L 2024-01-29 18:32:44 +01:00
parent 52ec1660f6
commit b21bc1363d
4 changed files with 38 additions and 36 deletions

View file

@ -141,7 +141,7 @@ a:hover {
padding-left: 2rem;
/** sidebar width **/
margin-left: 280px;
height: 100vh;
min-height: 100vh;
}
/** services **/

View file

@ -2,6 +2,15 @@
{% load i18n %}
{% block tabcontent %}
<form method="get" class="form-inline mt-4">
<div class="form-group mr-sm-2">
<input type="text" class="form-control" name="domain__name" placeholder="{% trans 'Filter by domain' %}" value="{{ request.GET.domain__name }}">
</div>
<button type="submit" class="btn btn-secondary">{% trans "Search" %}</button>
</form>
<div class="tab-pane fade show active" id="addresses" role="tabpanel" aria-labelledby="addresses-tab">
<table class="table service-list">
<colgroup>

View file

@ -1,38 +1,18 @@
{# <!-- table footer based paginator for ListView --> #}
{% load i18n %}
{% load i18n bootstrap4 %}
<tfoot>
<tr>
<td colspan="2">{{ page_obj.paginator.count }} items in total</td>
<td class="text-center">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
<li class="page-item {{ page_obj.has_previous|yesno:',disabled' }}">
<a class="page-link" {% if page_obj.has_previous %}
href="?page={{ page_obj.previous_page_number }}&per_page={{ page_obj.paginator.per_page }}"
{% else %} href="#" {% endif %} tabindex="-1">
<span aria-hidden="true">&lsaquo;</span>
<span class="sr-only">{% trans "Previous" %}</span>
</a>
</li>
{% for page_number in page_obj.paginator.page_range %}
<li class="page-item {% if page_number == page_obj.number %}active {% endif %}">
<a class="page-link"
href="?page={{ page_number }}&per_page={{ page_obj.paginator.per_page }}">{{ page_number }}</a>
</li>
{% endfor %}
<li class="page-item {{ page_obj.has_next|yesno:',disabled' }}">
<a class="page-link" {% if page_obj.has_next %}
href="?page={{ page_obj.next_page_number }}&per_page={{ page_obj.paginator.per_page }}"
{% else %} href="#" {% endif %}>
<span aria-hidden="true">&rsaquo;</span>
<span class="sr-only">{% trans "Next" %}</span>
</a>
</li>
</ul>
</nav>
<td colspan="100%">
<div class="d-flex justify-content-center">
{% bootstrap_pagination page_obj extra="per_page" %}
</div>
</td>
<td colspan="2" class="text-right">
</tr>
{% comment %}
<!-- commented until django-bootstrap4 accepts changing pagination size -->
<tr>
<td colspan="100%" class="text-center">
<form method="get">
Showing
<select name="{{ per_page_param }}">
@ -47,4 +27,5 @@
</form>
</td>
</tr>
{% endcomment %}
</tfoot>

View file

@ -237,15 +237,22 @@ class AddressListView(ServiceListView):
def get_queryfilter(self):
"""Retrieve query params (if any) to filter queryset"""
domain_id = self.request.GET.get('domain')
if domain_id:
return {"domain": domain_id}
queryfilter = {}
return {}
domain_id = self.clean_domain_id()
if domain_id:
queryfilter.update({"domain": domain_id})
else:
domain_name = self.request.GET.get('domain__name')
if domain_name:
queryfilter.update({"domain__name__icontains": domain_name})
return queryfilter
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
domain_id = self.request.GET.get('domain')
domain_id = self.clean_domain_id()
if domain_id:
qs = Domain.objects.filter(account=self.request.user)
context.update({
@ -254,6 +261,11 @@ class AddressListView(ServiceListView):
context['mailboxes'] = Mailbox.objects.filter(account=self.request.user)
return context
def clean_domain_id(self):
try:
return int(self.request.GET.get('domain', ''))
except ValueError:
return None
class MailCreateView(CustomContextMixin, UserTokenRequiredMixin, CreateView):
service_class = AddressService