Projet

Général

Profil

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

Lauréline Guérin, 02 décembre 2019 10:26

Télécharger (3,61 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 '
......
121 126
            .annotate(bank_transaction_id=RawSQL(raw % 'bank_transaction_id', []))
122 127
            .annotate(transaction_status=RawSQL(raw % 'status', []))
123 128
            .order_by())
129

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

  
124 134
        queryset1 = (
125 135
            queryset
126 136
            .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
357 357
    assert '/manage/lingo/?q=%s' % transaction22.bank_transaction_id not in resp.text
358 358

  
359 359

  
360
def test_basketitem_error_list_search(app, admin_user, payment_backend):
361
    regie = Regie.objects.create(
362
        label='test-regie', slug='test-regie', payment_backend=payment_backend)
363
    user = User.objects.create_user('dimebag', 'dime@bag.pan', 'pwd')
364

  
365
    item = BasketItem.objects.create(
366
        user=user,
367
        regie=regie,
368
        subject='item 1',
369
        source_url='http://example.net/1',
370
        amount=1)
371
    transaction = Transaction.objects.create(
372
        status=eopayment.ERROR,
373
        order_id='order id 1',
374
        bank_transaction_id='bank_id_1',
375
        amount=1)
376
    transaction.items.add(item)
377

  
378
    app = login(app)
379
    resp = app.get('/manage/lingo/payments/error/', status=200)
380
    assert list(resp.context['object_list']) == [item]
381

  
382
    resp.form['q'] = 'item 42'
383
    resp = resp.form.submit()
384
    assert list(resp.context['object_list']) == []
385

  
386
    resp.form['q'] = 'item 1'
387
    resp = resp.form.submit()
388
    assert list(resp.context['object_list']) == [item]
389

  
390
    resp.form['q'] = 'item'
391
    resp = resp.form.submit()
392
    assert list(resp.context['object_list']) == [item]
393

  
394

  
360 395
def test_configure_tipi_cell(app, admin_user):
361 396
    page = Page(title='tipi', slug='tipi', template_name='standard')
362 397
    page.save()
363
-