summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2019-11-29 15:03:07 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2019-12-06 09:35:02 (GMT)
commit2920cf5d79a403f67992fdb582412015d0a62475 (patch)
tree6f9e79cd8329d66002f43daaa4937efc47a20579
parent964d0a87aad2ac57fdab77e84783ca7044ec3277 (diff)
downloadcombo-2920cf5d79a403f67992fdb582412015d0a62475.zip
combo-2920cf5d79a403f67992fdb582412015d0a62475.tar.gz
combo-2920cf5d79a403f67992fdb582412015d0a62475.tar.bz2
lingo: add search field (#21626)
-rw-r--r--combo/apps/lingo/manager_views.py10
-rw-r--r--combo/apps/lingo/templates/lingo/basketitem_error_list.html4
-rw-r--r--tests/test_lingo_manager.py35
3 files changed, 49 insertions, 0 deletions
diff --git a/combo/apps/lingo/manager_views.py b/combo/apps/lingo/manager_views.py
index 1c26470..2897b2b 100644
--- a/combo/apps/lingo/manager_views.py
+++ b/combo/apps/lingo/manager_views.py
@@ -109,6 +109,11 @@ class BasketItemErrorListView(ListView):
template_name = 'lingo/basketitem_error_list.html'
paginate_by = 10
+ def get_context_data(self, **kwargs):
+ context = super(BasketItemErrorListView, self).get_context_data(**kwargs)
+ context['query'] = self.request.GET.get('q') or ''
+ return context
+
def get_queryset(self):
raw = (
'SELECT %s FROM lingo_transaction '
@@ -122,6 +127,11 @@ class BasketItemErrorListView(ListView):
.annotate(transaction_status=RawSQL(raw % 'status', []))
.filter(regie__webservice_url='')
.order_by())
+
+ terms = self.request.GET.get('q')
+ if terms:
+ queryset = queryset.filter(subject__icontains=terms)
+
queryset1 = (
queryset
.filter(
diff --git a/combo/apps/lingo/templates/lingo/basketitem_error_list.html b/combo/apps/lingo/templates/lingo/basketitem_error_list.html
index a689e37..b410297 100644
--- a/combo/apps/lingo/templates/lingo/basketitem_error_list.html
+++ b/combo/apps/lingo/templates/lingo/basketitem_error_list.html
@@ -12,6 +12,10 @@
{% block content %}
+<form>
+ <p><input name="q" type="search" value="{{ query }}"> <button>{% trans 'Search' %}</button></p>
+</form>
+
{% if object_list %}
<table class="main">
<thead>
diff --git a/tests/test_lingo_manager.py b/tests/test_lingo_manager.py
index f1f4c42..05ab92c 100644
--- a/tests/test_lingo_manager.py
+++ b/tests/test_lingo_manager.py
@@ -393,6 +393,41 @@ def test_basketitem_error_list(app, admin_user, payment_backend):
assert '/manage/lingo/?q=%s' % transaction22.bank_transaction_id not in resp.text
+def test_basketitem_error_list_search(app, admin_user, payment_backend):
+ regie = Regie.objects.create(
+ label='test-regie', slug='test-regie', payment_backend=payment_backend)
+ user = User.objects.create_user('dimebag', 'dime@bag.pan', 'pwd')
+
+ item = BasketItem.objects.create(
+ user=user,
+ regie=regie,
+ subject='item 1',
+ source_url='http://example.net/1',
+ amount=1)
+ transaction = Transaction.objects.create(
+ status=eopayment.ERROR,
+ order_id='order id 1',
+ bank_transaction_id='bank_id_1',
+ amount=1)
+ transaction.items.add(item)
+
+ app = login(app)
+ resp = app.get('/manage/lingo/payments/error/', status=200)
+ assert list(resp.context['object_list']) == [item]
+
+ resp.form['q'] = 'item 42'
+ resp = resp.form.submit()
+ assert list(resp.context['object_list']) == []
+
+ resp.form['q'] = 'item 1'
+ resp = resp.form.submit()
+ assert list(resp.context['object_list']) == [item]
+
+ resp.form['q'] = 'item'
+ resp = resp.form.submit()
+ assert list(resp.context['object_list']) == [item]
+
+
def test_configure_tipi_cell(app, admin_user):
page = Page(title='tipi', slug='tipi', template_name='standard')
page.save()