mirror of
https://github.com/ae-utbm/sith.git
synced 2025-12-17 05:13:25 +00:00
Fix pagination on matmat, don't allow empty matmat search and add htmx pagination
This commit is contained in:
@@ -161,6 +161,7 @@
|
|||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
hx-target="#content"
|
hx-target="#content"
|
||||||
hx-push-url="true"
|
hx-push-url="true"
|
||||||
|
hx-trigger="click, keyup[key=='ArrowLeft'] from:body"
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
href="?{{ querystring(page=current_page.previous_page_number()) }}"
|
href="?{{ querystring(page=current_page.previous_page_number()) }}"
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
@@ -195,12 +196,13 @@
|
|||||||
{% if current_page.has_next() %}
|
{% if current_page.has_next() %}
|
||||||
<a
|
<a
|
||||||
{% if use_htmx -%}
|
{% if use_htmx -%}
|
||||||
hx-get="?querystring(page=current_page.next_page_number())"
|
hx-get="?{{querystring(page=current_page.next_page_number())}}"
|
||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
hx-target="#content"
|
hx-target="#content"
|
||||||
hx-push-url="true"
|
hx-push-url="true"
|
||||||
|
hx-trigger="click, keyup[key=='ArrowRight'] from:body"
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
href="?querystring(page=current_page.next_page_number())"
|
href="?{{querystring(page=current_page.next_page_number())}}"
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
><button>
|
><button>
|
||||||
<i class="fa fa-caret-right"></i>
|
<i class="fa fa-caret-right"></i>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2025-11-30 18:23+0100\n"
|
"POT-Creation-Date: 2025-12-17 00:03+0100\n"
|
||||||
"PO-Revision-Date: 2016-07-18\n"
|
"PO-Revision-Date: 2016-07-18\n"
|
||||||
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
||||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||||
@@ -4388,6 +4388,10 @@ msgstr "Ce citoyen n'a pas encore rejoint la galaxie"
|
|||||||
msgid "Last/First name or nickname"
|
msgid "Last/First name or nickname"
|
||||||
msgstr "Nom de famille, prénom ou surnom"
|
msgstr "Nom de famille, prénom ou surnom"
|
||||||
|
|
||||||
|
#: matmat/forms.py
|
||||||
|
msgid "Empty search"
|
||||||
|
msgstr "Recherche vide"
|
||||||
|
|
||||||
#: matmat/templates/matmat/search_form.jinja
|
#: matmat/templates/matmat/search_form.jinja
|
||||||
msgid "Search user"
|
msgid "Search user"
|
||||||
msgstr "Rechercher un utilisateur"
|
msgstr "Rechercher un utilisateur"
|
||||||
|
|||||||
@@ -16,13 +16,14 @@
|
|||||||
# details.
|
# details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License along with
|
# You should have received a copy of the GNU General Public License along with
|
||||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import User
|
from core.models import User
|
||||||
@@ -46,3 +47,8 @@ class SearchForm(forms.ModelForm):
|
|||||||
self.fields[key].required = False
|
self.fields[key].required = False
|
||||||
if key not in initial:
|
if key not in initial:
|
||||||
self.fields[key].initial = None
|
self.fields[key].initial = None
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
data = self.cleaned_data
|
||||||
|
if all(data[key] in self.fields[key].empty_values for key in self.fields):
|
||||||
|
raise ValidationError(_("Empty search"))
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
{% if is_fragment %}
|
||||||
|
{% extends "core/base_fragment.jinja" %}
|
||||||
|
{% else %}
|
||||||
{% extends "core/base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
{% from "core/macros.jinja" import user_mini_profile, paginate_jinja %}
|
{% endif %}
|
||||||
{% from "core/macros.jinja" import user_mini_profile, paginate_jinja with context %}
|
|
||||||
|
{% from "core/macros.jinja" import user_mini_profile, paginate_htmx with context %}
|
||||||
|
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans %}Search user{% endtrans %}
|
{% trans %}Search user{% endtrans %}
|
||||||
@@ -20,7 +25,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% if page_obj.has_other_pages() %}
|
{% if page_obj.has_other_pages() %}
|
||||||
{{ paginate_jinja(page_obj, paginator) }}
|
{{ paginate_htmx(page_obj, paginator) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<hr>
|
<hr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -33,3 +33,27 @@ class TestMatmatronch(TestCase):
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert list(response.context_data["object_list"]) == [self.users[2]]
|
assert list(response.context_data["object_list"]) == [self.users[2]]
|
||||||
|
|
||||||
|
def test_empty_search(self):
|
||||||
|
self.client.force_login(subscriber_user.make())
|
||||||
|
response = self.client.get(reverse("matmat:search"))
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert list(response.context_data["object_list"]) == []
|
||||||
|
assert not response.context_data["form"].is_valid()
|
||||||
|
|
||||||
|
response = self.client.get(
|
||||||
|
reverse(
|
||||||
|
"matmat:search",
|
||||||
|
query={
|
||||||
|
"promo": "",
|
||||||
|
"role": "",
|
||||||
|
"department": "",
|
||||||
|
"semester": "",
|
||||||
|
"date_of_birth": "",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert list(response.context_data["object_list"]) == []
|
||||||
|
assert not response.context_data["form"].is_valid()
|
||||||
|
assert "Empty search" in response.context_data["form"].non_field_errors()
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
# details.
|
# details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License along with
|
# You should have received a copy of the GNU General Public License along with
|
||||||
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
@@ -28,10 +28,11 @@ from django.views.generic.edit import FormMixin
|
|||||||
from core.auth.mixins import FormerSubscriberMixin
|
from core.auth.mixins import FormerSubscriberMixin
|
||||||
from core.models import User, UserQuerySet
|
from core.models import User, UserQuerySet
|
||||||
from core.schemas import UserFilterSchema
|
from core.schemas import UserFilterSchema
|
||||||
|
from core.views.mixins import AllowFragment
|
||||||
from matmat.forms import SearchForm
|
from matmat.forms import SearchForm
|
||||||
|
|
||||||
|
|
||||||
class MatmatronchView(FormerSubscriberMixin, FormMixin, ListView):
|
class MatmatronchView(AllowFragment, FormerSubscriberMixin, FormMixin, ListView):
|
||||||
model = User
|
model = User
|
||||||
paginate_by = 20
|
paginate_by = 20
|
||||||
template_name = "matmat/search_form.jinja"
|
template_name = "matmat/search_form.jinja"
|
||||||
|
|||||||
Reference in New Issue
Block a user