backoffice: add a channel filter to global listing (#10504)
This commit is contained in:
parent
73d0c692fe
commit
17f0bca426
|
@ -1464,9 +1464,18 @@ def test_global_listing(pub):
|
|||
pub.site_options.write(fd)
|
||||
fd.close()
|
||||
|
||||
resp = app.get('/backoffice/management/listing')
|
||||
resp = app.get('/backoffice/management/listing?limit=500')
|
||||
formdata = formdef.data_class().select(lambda x: x.status == 'wf-new')[0]
|
||||
formdata.submission_channel = 'mail'
|
||||
formdata.store()
|
||||
assert 'Channel' in resp.body
|
||||
assert '>Web<' in resp.body
|
||||
resp.form['submission_channel'] = 'web'
|
||||
resp = resp.form.submit()
|
||||
assert resp.body.count('<tr') == 36
|
||||
resp.form['submission_channel'] = 'mail'
|
||||
resp = resp.form.submit()
|
||||
assert resp.body.count('<tr') == 1
|
||||
|
||||
def test_tracking_code_access(pub):
|
||||
create_user(pub)
|
||||
|
|
|
@ -717,6 +717,25 @@ def test_select_criteria_or_and():
|
|||
assert [x.id for x in data_class.select([st.And([
|
||||
st.Less('id', 10), st.Greater('id', 5)])], order_by='id')] == range(6, 10)
|
||||
|
||||
@postgresql
|
||||
def test_select_criteria_null():
|
||||
test_formdef = FormDef()
|
||||
test_formdef.name = 'table select criteria null'
|
||||
test_formdef.fields = []
|
||||
test_formdef.store()
|
||||
data_class = test_formdef.data_class(mode='sql')
|
||||
assert data_class.count() == 0
|
||||
|
||||
for x in range(50):
|
||||
t = data_class()
|
||||
if x % 3:
|
||||
t.submission_channel = None
|
||||
else:
|
||||
t.submission_channel = 'mail'
|
||||
t.store()
|
||||
|
||||
assert len(data_class.select([st.Null('submission_channel')])) == 33
|
||||
assert len(data_class.select([st.NotNull('submission_channel')])) == 17
|
||||
|
||||
@postgresql
|
||||
def test_sql_table_select_bool():
|
||||
|
|
|
@ -304,6 +304,21 @@ def test_select_criteria_or_and():
|
|||
assert [int(x.id) for x in Foobar.select([st.And([st.Less('value', 10),
|
||||
st.Greater('value', 5)])], order_by='id')] == range(6, 10)
|
||||
|
||||
def test_select_criteria_null():
|
||||
Foobar.wipe()
|
||||
|
||||
for x in range(50):
|
||||
test = Foobar()
|
||||
if x % 3:
|
||||
test.value = None
|
||||
else:
|
||||
test.value = x
|
||||
test.store()
|
||||
|
||||
assert len(Foobar.select()) == 50
|
||||
|
||||
assert len(Foobar.select([st.Null('value')])) == 33
|
||||
assert len(Foobar.select([st.NotNull('value')])) == 17
|
||||
|
||||
def test_select_criteria_ilike():
|
||||
Foobar.wipe()
|
||||
|
|
|
@ -43,7 +43,7 @@ from qommon import ods
|
|||
from qommon.form import *
|
||||
from qommon.sms import SMS
|
||||
from qommon.storage import (Equal, NotEqual, LessOrEqual, GreaterOrEqual, Or,
|
||||
Intersects, ILike, FtsMatch, Contains)
|
||||
Intersects, ILike, FtsMatch, Contains, Null)
|
||||
|
||||
from wcs.forms.backoffice import FormDefUI
|
||||
from wcs.forms.common import FormStatusPage
|
||||
|
@ -506,6 +506,15 @@ class ManagementDirectory(Directory):
|
|||
form.add(DateWidget, 'start', title=_('Start Date'))
|
||||
form.add(DateWidget, 'end', title=_('End Date'))
|
||||
|
||||
if bool(get_publisher().get_site_option('welco_url', 'variables')):
|
||||
form.add(SingleSelectWidget, 'submission_channel',
|
||||
title=_('Channel'),
|
||||
options=[(None, _('All'), ''),
|
||||
('web', _('Web'), 'web'),
|
||||
('mail', _('Mail'), 'mail'),
|
||||
('phone', _('Phone'), 'phone'),
|
||||
('counter', _('Counter'), 'counter')])
|
||||
|
||||
if not offset:
|
||||
offset = 0
|
||||
if not limit:
|
||||
|
@ -668,6 +677,12 @@ class ManagementDirectory(Directory):
|
|||
criterias.append(Intersects('actions_roles_array', user_roles))
|
||||
else:
|
||||
criterias.append(Intersects('concerned_roles_array', user_roles))
|
||||
if get_request().form.get('submission_channel'):
|
||||
if get_request().form.get('submission_channel') == 'web':
|
||||
criterias.append(Null('submission_channel'))
|
||||
else:
|
||||
criterias.append(Equal('submission_channel',
|
||||
get_request().form.get('submission_channel')))
|
||||
return criterias
|
||||
|
||||
def listing(self):
|
||||
|
|
|
@ -168,6 +168,21 @@ class FtsMatch(Criteria):
|
|||
def build_lambda(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
class NotNull(Criteria):
|
||||
def __init__(self, attribute):
|
||||
self.attribute = attribute
|
||||
|
||||
def build_lambda(self):
|
||||
return lambda x: getattr(x, self.attribute, None) is not None
|
||||
|
||||
class Null(Criteria):
|
||||
def __init__(self, attribute):
|
||||
self.attribute = attribute
|
||||
|
||||
def build_lambda(self):
|
||||
return lambda x: getattr(x, self.attribute, None) is None
|
||||
|
||||
|
||||
def parse_clause(clause):
|
||||
# creates a callable out of a clause
|
||||
# (attribute, operator, value)
|
||||
|
|
12
wcs/sql.py
12
wcs/sql.py
|
@ -110,6 +110,18 @@ class NotNull(Criteria):
|
|||
def as_sql_param(self):
|
||||
return {}
|
||||
|
||||
class Null(Criteria):
|
||||
sql_op = 'IS NULL'
|
||||
|
||||
def __init__(self, attribute):
|
||||
self.attribute = attribute
|
||||
|
||||
def as_sql(self):
|
||||
return '%s %s' % (self.attribute, self.sql_op)
|
||||
|
||||
def as_sql_param(self):
|
||||
return {}
|
||||
|
||||
class Or(Criteria):
|
||||
def __init__(self, criterias, **kwargs):
|
||||
self.criterias = []
|
||||
|
|
Loading…
Reference in New Issue