From 2bca5279a85b7e720e79d0b8d237fb421ea42294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Sat, 31 Oct 2026 15:07:58 +0100 Subject: [PATCH] fix(multiseek): pusty wynik nie pokazuje nieaktualnego licznika (FD#503) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Licznik „Razem" pochodzi z 30-minutowego cache agregatów, a klucz zależy tylko od formularza. Gdy rekord zniknął z wyników w czasie życia wpisu, lista była pusta, a pasek dalej pokazywał „Razem: 1" i przyciski wyświetlania/druku. Pusty wynik przy niezerowym wpisie przelicza teraz agregaty. Komunikat „Brak elementów" trafia poza
    , bo każdy
  1. dostaje z CSS numer i pusta lista wyglądała jak pozycja „0.". Fixes Freshdesk FD#503 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Mr7s9on2cdYwgnDrRWrtHo --- src/bpp/newsfragments/+fd503.bugfix.md | 1 + .../test_mymultiseek_count_cache.py | 65 ++++++++++++++++++- src/bpp/views/mymultiseek.py | 4 ++ .../templates/multiseek/report-body-list.html | 6 +- 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/bpp/newsfragments/+fd503.bugfix.md diff --git a/src/bpp/newsfragments/+fd503.bugfix.md b/src/bpp/newsfragments/+fd503.bugfix.md new file mode 100644 index 000000000..65bd5859a --- /dev/null +++ b/src/bpp/newsfragments/+fd503.bugfix.md @@ -0,0 +1 @@ +Wyszukiwanie bez wyników pokazuje teraz „Razem: 0" zamiast nieaktualnego licznika, a komunikat „Brak elementów" nie jest już numerowany jako pozycja „0." (FD#503). diff --git a/src/bpp/tests/test_views/test_mymultiseek_count_cache.py b/src/bpp/tests/test_views/test_mymultiseek_count_cache.py index 819dc016c..6181e2f5e 100644 --- a/src/bpp/tests/test_views/test_mymultiseek_count_cache.py +++ b/src/bpp/tests/test_views/test_mymultiseek_count_cache.py @@ -18,13 +18,15 @@ from django.test.utils import CaptureQueriesContext from django.urls import reverse from django.utils import translation -from multiseek.logic import STARTS_WITH +from model_bakery import baker +from multiseek.logic import EQUAL_NONE, STARTS_WITH from multiseek.views import MULTISEEK_SESSION_KEY, MULTISEEK_SESSION_KEY_REMOVED -from bpp.models import Rekord +from bpp.models import Autor, Rekord from bpp.tests.util import any_ciagle TYTUL_PREFIX = "CCache multiseek" +LIST_REPORT_TYPE = "0" TABLE_REPORT_TYPE = "1" @@ -136,3 +138,62 @@ def test_zalogowanie_ma_osobny_cache(client, admin_client, dwa_rekordy, locmem_c _ustaw_filtr(admin_client, TYTUL_PREFIX) res = admin_client.get(reverse("multiseek:results")) assert res.context["paginator_count"] == 2 + + +@pytest.mark.django_db +@pytest.mark.parametrize("report_type", [LIST_REPORT_TYPE, TABLE_REPORT_TYPE]) +def test_fd503_pusty_wynik_przelicza_nieaktualny_licznik( + client, standard_data, locmem_cache, report_type +): + """FD#503: rekord zniknął z wyników w czasie życia wpisu cache — lista + była już pusta, a pasek dalej pokazywał „Razem: 1".""" + rekord = any_ciagle(tytul_oryginalny=f"{TYTUL_PREFIX} znika", rok=2024) + _ustaw_filtr(client, TYTUL_PREFIX, report_type) + assert client.get(reverse("multiseek:results")).context["paginator_count"] == 1 + + rekord.delete() + + res = client.get(reverse("multiseek:results")) + assert res.context["paginator_count"] == 0 + assert "Razem: 0" in res.content.decode() + + +@pytest.mark.django_db +def test_fd503_autor_bez_prac_ma_licznik_zero(client, standard_data): + """FD#503: bez cache autor bez prac daje 0 — rozjazd z ticketu nie + pochodzi z zapytania, tylko z nieaktualnego wpisu cache.""" + autor = baker.make(Autor) + with translation.override(django_settings.LANGUAGE_CODE): + operator = str(EQUAL_NONE) + + session = client.session + session[MULTISEEK_SESSION_KEY] = json.dumps( + { + "form_data": [ + None, + { + "field": "Nazwisko i imię", + "operator": operator, + "value": str(autor.pk), + "prev_op": None, + }, + ], + "ordering": {}, + "report_type": LIST_REPORT_TYPE, + } + ) + session.save() + + assert client.get(reverse("multiseek:results")).context["paginator_count"] == 0 + + +@pytest.mark.django_db +def test_fd503_brak_elementow_nie_jest_numerowana_pozycja(client, standard_data): + """FD#503: komunikat o braku wyników jako
  2. dostawał z CSS numer „0.".""" + _ustaw_filtr(client, f"{TYTUL_PREFIX} nie ma", LIST_REPORT_TYPE) + + tresc = client.get(reverse("multiseek:results")).content.decode() + + lista = tresc[tresc.index("")] + assert "Brak elementów" in tresc + assert "Brak elementów" not in lista diff --git a/src/bpp/views/mymultiseek.py b/src/bpp/views/mymultiseek.py index af8fece1d..c98bc79eb 100644 --- a/src/bpp/views/mymultiseek.py +++ b/src/bpp/views/mymultiseek.py @@ -208,6 +208,10 @@ def get_context_data(self, **kwargs): # kazda zmiana formularza / wyrzucenie rekordu zmienia klucz. cache_key = self._aggregate_cache_key() agregaty = cache.get(cache_key) + # Wszystkie rekordy zniknely z wynikow w czasie zycia wpisu: pusta + # lista obok niezerowego licznika to widoczna sprzecznosc (FD#503). + if agregaty is not None and agregaty["paginator_count"] and not qset.exists(): + agregaty = None if agregaty is None: if ctx["report_type"] in EXTRA_TYPES: # Licznik i sumy jednym skanem — przy DISTINCT + join do diff --git a/src/django_bpp/templates/multiseek/report-body-list.html b/src/django_bpp/templates/multiseek/report-body-list.html index 1a013236e..24aa84bcf 100644 --- a/src/django_bpp/templates/multiseek/report-body-list.html +++ b/src/django_bpp/templates/multiseek/report-body-list.html @@ -50,8 +50,10 @@ {% endif %}
  3. - {% empty %} -
  4. {% trans "No elements" %}
  5. {% endfor %}
+ {# Poza
    : każdy
  1. dostaje z CSS numer, więc komunikat byłby pozycją „0.". #} + {% if not object_list %} +

    {% trans "No elements" %}

    + {% endif %}