Projet

Général

Profil

0002-lingo-add-search-field-21626.patch

Lauréline Guérin, 06 décembre 2019 10:10

Télécharger (3,57 ko)

Voir les différences:

Subject: [PATCH 2/3] lingo: add search field (#21626)

 combo/apps/lingo/manager_views.py             | 10 ++++++
 .../lingo/basketitem_error_list.html          |  4 +++
 tests/test_lingo_manager.py                   | 35 +++++++++++++++++++
 3 files changed, 49 insertions(+)
combo/apps/lingo/manager_views.py
109 109
    template_name = 'lingo/basketitem_error_list.html'
110 110
    paginate_by = 10
111 111

  
112
    def get_context_data(self, **kwargs):
113
        context = super(BasketItemErrorListView, self).get_context_data(**kwargs)
114
        context['query'] = self.request.GET.get('q') or ''
115
        return context
116

  
112 117
    def get_queryset(self):
113 118
        raw = (
114 119
            'SELECT %s FROM lingo_transaction '
......
122 127
            .annotate(transaction_status=RawSQL(raw % 'status', []))
123 128
            .filter(regie__webservice_url='')
124 129
            .order_by())
130

  
131
        terms = self.request.GET.get('q')
132
        if terms:
133
            queryset = queryset.filter(subject__icontains=terms)
134

  
125 135
        queryset1 = (
126 136
            queryset
127 137
            .filter(
combo/apps/lingo/templates/lingo/basketitem_error_list.html
12 12

  
13 13
{% block content %}
14 14

  
15
<form>
16
  <p><input name="q" type="search" value="{{ query }}"> <button>{% trans 'Search' %}</button></p>
17
</form>
18

  
15 19
{% if object_list %}
16 20
<table class="main">
17 21
<thead>
tests/test_lingo_manager.py
393 393
    assert '/manage/lingo/?q=%s' % transaction22.bank_transaction_id not in resp.text
394 394

  
395 395

  
396
def test_basketitem_error_list_search(app, admin_user, payment_backend):
397
    regie = Regie.objects.create(
398
        label='test-regie', slug='test-regie', payment_backend=payment_backend)
399
    user = User.objects.create_user('dimebag', 'dime@bag.pan', 'pwd')
400

  
401
    item = BasketItem.objects.create(
402
        user=user,
403
        regie=regie,
404
        subject='item 1',
405
        source_url='http://example.net/1',
406
        amount=1)
407
    transaction = Transaction.objects.create(
408
        status=eopayment.ERROR,
409
        order_id='order id 1',
410
        bank_transaction_id='bank_id_1',
411
        amount=1)
412
    transaction.items.add(item)
413

  
414
    app = login(app)
415
    resp = app.get('/manage/lingo/payments/error/', status=200)
416
    assert list(resp.context['object_list']) == [item]
417

  
418
    resp.form['q'] = 'item 42'
419
    resp = resp.form.submit()
420
    assert list(resp.context['object_list']) == []
421

  
422
    resp.form['q'] = 'item 1'
423
    resp = resp.form.submit()
424
    assert list(resp.context['object_list']) == [item]
425

  
426
    resp.form['q'] = 'item'
427
    resp = resp.form.submit()
428
    assert list(resp.context['object_list']) == [item]
429

  
430

  
396 431
def test_configure_tipi_cell(app, admin_user):
397 432
    page = Page(title='tipi', slug='tipi', template_name='standard')
398 433
    page.save()
399
-