Allow search mailboxes by name or domain
This commit is contained in:
parent
b21bc1363d
commit
5836d6e6ed
|
@ -138,6 +138,10 @@ class MailboxUpdateForm(forms.ModelForm):
|
|||
model = Mailbox
|
||||
|
||||
|
||||
class MailboxSearchForm(forms.Form):
|
||||
name = forms.CharField(required=False)
|
||||
address = forms.CharField(required=False)
|
||||
|
||||
class RecordCreateForm(ValidateZoneMixin, forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
{% extends "musician/mail_base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap4 i18n %}
|
||||
|
||||
{% block tabcontent %}
|
||||
<div class="tab-pane fade show active" id="mailboxes" role="tabpanel" aria-labelledby="mailboxes-tab">
|
||||
|
||||
<div class="mt-4 search-form">
|
||||
<form method="get" class="form-inline">
|
||||
<div class="form-group mr-sm-2">
|
||||
<label class="sr-only" for="id_name">Name</label>
|
||||
<input type="text" name="name" class="form-control" placeholder="Name" title="" id="id_name">
|
||||
</div>
|
||||
<div class="form-group mr-sm-2">
|
||||
<label class="sr-only" for="id_address">Address</label>
|
||||
<input type="text" name="address" class="form-control" placeholder="Address" title="" id="id_address">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<table class="table service-list">
|
||||
<colgroup>
|
||||
<col span="1" style="width: 25%;">
|
||||
|
|
|
@ -5,6 +5,8 @@ from typing import Any
|
|||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.mail import mail_managers
|
||||
from django.db.models import Value
|
||||
from django.db.models.functions import Concat
|
||||
from django.http import (HttpResponse, HttpResponseNotFound,
|
||||
HttpResponseRedirect)
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
@ -30,11 +32,10 @@ from orchestra.contrib.mailboxes.models import Address, Mailbox
|
|||
from orchestra.contrib.saas.models import SaaS
|
||||
from orchestra.utils.html import html_to_pdf
|
||||
|
||||
# from .auth import login as auth_login
|
||||
from .auth import logout as auth_logout
|
||||
from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm,
|
||||
MailboxUpdateForm, MailForm, RecordCreateForm,
|
||||
RecordUpdateForm)
|
||||
MailboxSearchForm, MailboxUpdateForm, MailForm,
|
||||
RecordCreateForm, RecordUpdateForm)
|
||||
from .mixins import (CustomContextMixin, ExtendedPaginationMixin,
|
||||
UserTokenRequiredMixin)
|
||||
from .models import Address as AddressService
|
||||
|
@ -346,6 +347,31 @@ class MailboxListView(ServiceListView):
|
|||
# Translators: This message appears on the page title
|
||||
'title': _('Mailboxes'),
|
||||
}
|
||||
search_form_class = MailboxSearchForm
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super().get_queryset()
|
||||
|
||||
search_form = self.search_form_class(self.request.GET)
|
||||
cleaned_data = search_form.cleaned_data if search_form.is_valid() else {}
|
||||
|
||||
if "address" in cleaned_data:
|
||||
qs = qs.annotate(
|
||||
full_address=Concat("addresses__name", Value("@"), "addresses__domain__name")
|
||||
).filter(
|
||||
full_address__icontains=cleaned_data["address"]
|
||||
)
|
||||
|
||||
if "name" in cleaned_data:
|
||||
qs = qs.filter(name__icontains=cleaned_data["name"])
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['form'] = self.search_form_class()#self.request.GET)
|
||||
return context
|
||||
|
||||
|
||||
class MailboxCreateView(CustomContextMixin, UserTokenRequiredMixin, CreateView):
|
||||
|
|
Loading…
Reference in a new issue