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; padding-left: 2rem;
/** sidebar width **/ /** sidebar width **/
margin-left: 280px; margin-left: 280px;
height: 100vh; min-height: 100vh;
} }
/** services **/ /** services **/

View File

@ -2,6 +2,15 @@
{% load i18n %} {% load i18n %}
{% block tabcontent %} {% 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"> <div class="tab-pane fade show active" id="addresses" role="tabpanel" aria-labelledby="addresses-tab">
<table class="table service-list"> <table class="table service-list">
<colgroup> <colgroup>

View File

@ -1,38 +1,18 @@
{# <!-- table footer based paginator for ListView --> #} {# <!-- table footer based paginator for ListView --> #}
{% load i18n %} {% load i18n bootstrap4 %}
<tfoot> <tfoot>
<tr> <tr>
<td colspan="2">{{ page_obj.paginator.count }} items in total</td> <td colspan="100%">
<td class="text-center"> <div class="d-flex justify-content-center">
<nav aria-label="Page navigation"> {% bootstrap_pagination page_obj extra="per_page" %}
<ul class="pagination justify-content-center"> </div>
<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> </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"> <form method="get">
Showing Showing
<select name="{{ per_page_param }}"> <select name="{{ per_page_param }}">
@ -47,4 +27,5 @@
</form> </form>
</td> </td>
</tr> </tr>
{% endcomment %}
</tfoot> </tfoot>

View File

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