mirror of
https://github.com/ae-utbm/sith.git
synced 2026-03-29 14:59:45 +00:00
apply review comments
This commit is contained in:
11
club/api.py
11
club/api.py
@@ -9,7 +9,6 @@ from api.auth import ApiKeyAuth
|
|||||||
from api.permissions import CanView, HasPerm
|
from api.permissions import CanView, HasPerm
|
||||||
from club.models import Club, Membership
|
from club.models import Club, Membership
|
||||||
from club.schemas import (
|
from club.schemas import (
|
||||||
ClubProfileSchema,
|
|
||||||
ClubSchema,
|
ClubSchema,
|
||||||
ClubSearchFilterSchema,
|
ClubSearchFilterSchema,
|
||||||
SimpleClubSchema,
|
SimpleClubSchema,
|
||||||
@@ -29,16 +28,6 @@ class ClubController(ControllerBase):
|
|||||||
def search_club(self, filters: Query[ClubSearchFilterSchema]):
|
def search_club(self, filters: Query[ClubSearchFilterSchema]):
|
||||||
return filters.filter(Club.objects.order_by("name")).values()
|
return filters.filter(Club.objects.order_by("name")).values()
|
||||||
|
|
||||||
@route.get(
|
|
||||||
"/search-profile",
|
|
||||||
response=PaginatedResponseSchema[ClubProfileSchema],
|
|
||||||
url_name="search_club_profile",
|
|
||||||
)
|
|
||||||
@paginate(PageNumberPaginationExtra, page_size=50)
|
|
||||||
def search_club_profile(self, filters: Query[ClubSearchFilterSchema]):
|
|
||||||
"""Same as /api/club/search, but with more returned data"""
|
|
||||||
return filters.filter(Club.objects.order_by("name"))
|
|
||||||
|
|
||||||
@route.get(
|
@route.get(
|
||||||
"/{int:club_id}",
|
"/{int:club_id}",
|
||||||
response=ClubSchema,
|
response=ClubSchema,
|
||||||
|
|||||||
@@ -33,7 +33,9 @@
|
|||||||
<div class="row gap-4x">
|
<div class="row gap-4x">
|
||||||
{{ form }}
|
{{ form }}
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" class="btn btn-blue margin-bottom" value="{% trans %}Search{% endtrans %}">
|
<button type="submit" class="btn btn-blue margin-bottom">
|
||||||
|
<i class="fa fa-magnifying-glass"></i>{% trans %}Search{% endtrans %}
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<h3>{% trans %}Club list{% endtrans %}</h3>
|
<h3>{% trans %}Club list{% endtrans %}</h3>
|
||||||
{% if user.has_perm("club.add_club") %}
|
{% if user.has_perm("club.add_club") %}
|
||||||
|
|||||||
@@ -30,8 +30,12 @@ def test_club_queryset_having_board_member():
|
|||||||
assert set(club_ids) == {clubs[1].id, clubs[2].id}
|
assert set(club_ids) == {clubs[1].id, clubs[2].id}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("nb_additional_clubs", [10, 30])
|
||||||
|
@pytest.mark.parametrize("is_fragment", [True, False])
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_club_list(client: Client):
|
def test_club_list(client: Client, nb_additional_clubs: int, is_fragment):
|
||||||
client.force_login(baker.make(User))
|
client.force_login(baker.make(User))
|
||||||
res = client.get(reverse("club:club_list"))
|
baker.make(Club, _quantity=nb_additional_clubs)
|
||||||
|
headers = {"HX-Request": True} if is_fragment else {}
|
||||||
|
res = client.get(reverse("club:club_list"), headers=headers)
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
|
|||||||
@@ -59,14 +59,6 @@ class TestClubSearch(TestCase):
|
|||||||
ids = {d["id"] for d in response.json()["results"]}
|
ids = {d["id"] for d in response.json()["results"]}
|
||||||
assert ids == {c.id for c in [self.clubs[0], self.clubs[1], self.clubs[3]]}
|
assert ids == {c.id for c in [self.clubs[0], self.clubs[1], self.clubs[3]]}
|
||||||
|
|
||||||
def test_club_search_profile(self):
|
|
||||||
self.client.force_login(self.user)
|
|
||||||
url = reverse("api:search_club_profile")
|
|
||||||
response = self.client.get(url, {"search": "AE"})
|
|
||||||
assert response.status_code == 200
|
|
||||||
ids = {d["id"] for d in response.json()["results"]}
|
|
||||||
assert ids == {c.id for c in [self.clubs[0], self.clubs[1], self.clubs[3]]}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
class TestFetchClub:
|
class TestFetchClub:
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class ClubListView(AllowFragment, FormMixin, ListView):
|
|||||||
form: ClubSearchForm = self.get_form()
|
form: ClubSearchForm = self.get_form()
|
||||||
qs = self.queryset
|
qs = self.queryset
|
||||||
if not form.is_bound:
|
if not form.is_bound:
|
||||||
return qs
|
return qs.filter(is_active=True)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return qs.none()
|
return qs.none()
|
||||||
if name := form.cleaned_data.get("name"):
|
if name := form.cleaned_data.get("name"):
|
||||||
|
|||||||
Reference in New Issue
Block a user