Make email "source" filter use a dropdown, in bouncer UI.
This commit is contained in:
parent
0ddb5bffd7
commit
c42e80f87a
|
@ -85,6 +85,23 @@ class BooleanSearchFilter(SearchFilter):
|
||||||
["True", "False"])
|
["True", "False"])
|
||||||
|
|
||||||
|
|
||||||
|
class ChoiceSearchFilter(SearchFilter):
|
||||||
|
"""
|
||||||
|
Generic search filter where the user may only select among a specific set
|
||||||
|
of choices.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, choices):
|
||||||
|
self.choices = choices
|
||||||
|
|
||||||
|
def __call__(self, name, label=None, **kwargs):
|
||||||
|
super(ChoiceSearchFilter, self).__init__(name, label=label, **kwargs)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def value_control(self):
|
||||||
|
return tags.select(self.name, self.search.config.get(self.name), self.choices)
|
||||||
|
|
||||||
|
|
||||||
def EnumSearchFilter(enum):
|
def EnumSearchFilter(enum):
|
||||||
options = enum.items()
|
options = enum.items()
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import datetime
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
from rattail.bouncer import get_handler
|
from rattail.bouncer import get_handler
|
||||||
|
from rattail.bouncer.config import get_profile_keys
|
||||||
|
|
||||||
import formalchemy
|
import formalchemy
|
||||||
from pyramid.response import FileResponse
|
from pyramid.response import FileResponse
|
||||||
|
@ -41,7 +42,7 @@ from tailbone.db import Session
|
||||||
from tailbone.views import SearchableAlchemyGridView, CrudView
|
from tailbone.views import SearchableAlchemyGridView, CrudView
|
||||||
from tailbone.forms import renderers
|
from tailbone.forms import renderers
|
||||||
from tailbone.forms.renderers.bouncer import BounceMessageFieldRenderer
|
from tailbone.forms.renderers.bouncer import BounceMessageFieldRenderer
|
||||||
from tailbone.grids.search import BooleanSearchFilter
|
from tailbone.grids.search import BooleanSearchFilter, ChoiceSearchFilter
|
||||||
|
|
||||||
|
|
||||||
class EmailBouncesGrid(SearchableAlchemyGridView):
|
class EmailBouncesGrid(SearchableAlchemyGridView):
|
||||||
|
@ -51,6 +52,10 @@ class EmailBouncesGrid(SearchableAlchemyGridView):
|
||||||
mapped_class = model.EmailBounce
|
mapped_class = model.EmailBounce
|
||||||
config_prefix = 'emailbounces'
|
config_prefix = 'emailbounces'
|
||||||
|
|
||||||
|
def __init__(self, request):
|
||||||
|
super(EmailBouncesGrid, self).__init__(request)
|
||||||
|
self.handler_options = [('', '(any)')] + sorted(get_profile_keys(self.rattail_config))
|
||||||
|
|
||||||
def join_map(self):
|
def join_map(self):
|
||||||
return {
|
return {
|
||||||
'processed_by': lambda q: q.outerjoin(model.User),
|
'processed_by': lambda q: q.outerjoin(model.User),
|
||||||
|
@ -71,7 +76,8 @@ class EmailBouncesGrid(SearchableAlchemyGridView):
|
||||||
return q.filter(model.EmailBounce.processed != None)
|
return q.filter(model.EmailBounce.processed != None)
|
||||||
|
|
||||||
return self.make_filter_map(
|
return self.make_filter_map(
|
||||||
ilike=['config_key', 'bounce_recipient_address', 'intended_recipient_address'],
|
exact=['config_key'],
|
||||||
|
ilike=['bounce_recipient_address', 'intended_recipient_address'],
|
||||||
processed={'is': processed_is, 'nt': processed_nt},
|
processed={'is': processed_is, 'nt': processed_nt},
|
||||||
processed_by=self.filter_ilike(model.User.username))
|
processed_by=self.filter_ilike(model.User.username))
|
||||||
|
|
||||||
|
@ -80,6 +86,7 @@ class EmailBouncesGrid(SearchableAlchemyGridView):
|
||||||
include_filter_config_key=True,
|
include_filter_config_key=True,
|
||||||
filter_type_config_key='lk',
|
filter_type_config_key='lk',
|
||||||
filter_label_config_key="Source",
|
filter_label_config_key="Source",
|
||||||
|
filter_factory_config_key=ChoiceSearchFilter(self.handler_options),
|
||||||
filter_factory_processed=BooleanSearchFilter,
|
filter_factory_processed=BooleanSearchFilter,
|
||||||
filter_type_processed='is',
|
filter_type_processed='is',
|
||||||
processed=False,
|
processed=False,
|
||||||
|
|
Loading…
Reference in a new issue