From 4f61c4afa42de69e79d18e308ff74ada637c72f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A7=D0=B5?= <39742182+Dmi4er4@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:18:39 +0300 Subject: [PATCH] Hotfix (#865) * Hotfix * Hotfix --- apps/staff/filters.py | 11 ++++++----- apps/staff/templates/staff/exports.html | 3 +-- apps/staff/tests.py | 14 ++++++++++++++ apps/staff/views.py | 7 +++---- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/apps/staff/filters.py b/apps/staff/filters.py index e3be4b962..99ae02223 100644 --- a/apps/staff/filters.py +++ b/apps/staff/filters.py @@ -8,6 +8,7 @@ from core.models import Branch from courses.utils import get_current_term_pair +from learning.models import Invitation from users.models import StudentProfile, StudentTypes @@ -67,7 +68,7 @@ def qs(self): class EnrollmentInvitationFilter(django_filters.FilterSet): - branch = django_filters.ChoiceFilter( + branches = django_filters.ChoiceFilter( label="Отделение", required=True, empty_label=None, @@ -77,13 +78,13 @@ class EnrollmentInvitationFilter(django_filters.FilterSet): lookup_expr='icontains') class Meta: - model = StudentProfile - fields = ['branch', 'name'] + model = Invitation + fields = ['branches', 'name'] def __init__(self, site_branches: List[Branch], data=None, **kwargs): assert len(site_branches) > 0 super().__init__(data=data, **kwargs) - self.filters['branch'].extra["choices"] = [(b.pk, b.name) for b in site_branches] + self.filters['branches'].extra["choices"] = [(b.pk, b.name) for b in site_branches] @property def form(self): @@ -93,7 +94,7 @@ def form(self): self._form.helper.form_method = "GET" self._form.helper.layout = Layout( Row( - Div("branch", css_class="col-xs-3"), + Div("branches", css_class="col-xs-3"), Div("name", css_class="col-xs-6"), Div(Submit('', _('Filter'), css_class="btn-block -inline-submit"), css_class="col-xs-3"), diff --git a/apps/staff/templates/staff/exports.html b/apps/staff/templates/staff/exports.html index 75c1826ad..dafb49e5d 100644 --- a/apps/staff/templates/staff/exports.html +++ b/apps/staff/templates/staff/exports.html @@ -54,8 +54,7 @@

За семестр

* для курсов клуба и центра данные о преподавателях не включены.
-

Приглашенные студенты

- Перейти к списку +

Приглашенные студенты

Проекты

diff --git a/apps/staff/tests.py b/apps/staff/tests.py index aeb4b4e93..4b87fd0db 100644 --- a/apps/staff/tests.py +++ b/apps/staff/tests.py @@ -2,9 +2,11 @@ import pytest from bs4 import BeautifulSoup +from django.conf import settings from django.utils.encoding import smart_bytes +from core.models import Branch from core.tests.factories import BranchFactory from core.tests.settings import ANOTHER_DOMAIN from core.urls import reverse @@ -74,6 +76,18 @@ def test_view_student_progress_report_full_download_csv(client): assert response.status_code == 200 assert response["Content-Type"] == "text/csv" +@pytest.mark.django_db +def test_enrollment_invitation_list_view(client, assert_redirect): + url = reverse("staff:enrollment_invitations_list") + curator = CuratorFactory() + client.login(curator) + response = client.get(url) + assert response.status_code == 302 + branch = Branch.objects.for_site(site_id=settings.SITE_ID)[0].id + url_redirect = f"{url}?branches={branch}" + response = client.get(url_redirect) + assert response.status_code == 200 + @pytest.mark.django_db def test_view_student_progress_report_for_term(client): diff --git a/apps/staff/views.py b/apps/staff/views.py index 0e6450926..fc3492ca5 100644 --- a/apps/staff/views.py +++ b/apps/staff/views.py @@ -421,17 +421,16 @@ class EnrollmentInvitationListView(CuratorOnlyMixin, TemplateView): template_name = "lms/staff/enrollment_invitations.html" class InputSerializer(serializers.Serializer): - branch = serializers.ChoiceField(required=True, choices=()) + branches = serializers.ChoiceField(required=True, choices=()) def get(self, request, *args, **kwargs): site_branches = Branch.objects.for_site(site_id=settings.SITE_ID) assert len(site_branches) > 0 serializer = self.InputSerializer(data=request.GET) - serializer.fields["branch"].choices = [(b.pk, b.name) for b in site_branches] + serializer.fields["branches"].choices = [(b.pk, b.name) for b in site_branches] if not serializer.initial_data: branch = site_branches[0] - current_term = get_current_term_pair(branch.get_timezone()) - url = f"{request.path}?branch={branch.pk}&semester={current_term.slug}" + url = f"{request.path}?branches={branch.pk}" return HttpResponseRedirect(url) serializer.is_valid(raise_exception=False) # Filterset knows how to validate input data too