Projet

Général

Profil

0001-search-do-not-consider-page-with-sub_slug-40108.patch

Thomas Noël, 25 février 2020 17:13

Télécharger (1,98 ko)

Voir les différences:

Subject: [PATCH] search: do not consider page with sub_slug (#40108)

 combo/apps/search/utils.py |  2 +-
 tests/test_search.py       | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
combo/apps/search/utils.py
44 44
    IndexedCell.objects.all().delete()
45 45
    external_urls = {}
46 46
    for klass in CellBase.get_cell_classes():
47
        for cell in klass.objects.filter(page__snapshot__isnull=True).exclude(placeholder__startswith='_'):
47
        for cell in klass.objects.filter(page__snapshot__isnull=True).filter(page__sub_slug='').exclude(placeholder__startswith='_'):
48 48
            cell_type = ContentType.objects.get_for_model(cell)
49 49
            indexed_cell = IndexedCell(cell_type=cell_type, cell_pk=cell.id)
50 50
            try:
tests/test_search.py
510 510
    assert len(hits) == 0
511 511
    hits = search_site(request, 'barfoo')
512 512
    assert len(hits) == 1
513

  
514

  
515
def test_no_sub_slug_search(app):
516
    page = Page(title='example page', slug='example-page')
517
    page.save()
518
    TextCell(page=page, text='<p>foobar</p>', order=0, public=True).save()
519
    page = Page(title='example page with sub_slug', slug='sub-slugged-page',
520
                sub_slug='(?P<foo>\d+)')
521
    page.save()
522
    TextCell(page=page, text='<p>barfoo</p>', order=0, public=True).save()
523

  
524
    request = RequestFactory().get('/')
525
    request.user = AnonymousUser()
526
    index_site()
527
    hits = search_site(request, 'foobar')
528
    assert len(hits) == 1
529
    hits = search_site(request, 'barfoo')
530
    assert len(hits) == 0
513
-