Skip to content

Commit

Permalink
Hotfix (#865)
Browse files Browse the repository at this point in the history
* Hotfix

* Hotfix
  • Loading branch information
Dmi4er4 authored Aug 8, 2024
1 parent 1d14d48 commit 4f61c4a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
11 changes: 6 additions & 5 deletions apps/staff/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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"),
Expand Down
3 changes: 1 addition & 2 deletions apps/staff/templates/staff/exports.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ <h4 class="list-group-item-heading">За семестр</h4>
* для курсов клуба и центра данные о преподавателях не включены.<br>
</div>
<div class="list-group-item">
<h4 class="list-group-item-heading">Приглашенные студенты</h4>
<a href="{% url 'staff:enrollment_invitations_list' %}">Перейти к списку</a>
<h4 class="list-group-item-heading"><a href="{% url 'staff:enrollment_invitations_list' %}">Приглашенные студенты</a></h4>
</div>
</div>
<h2>Проекты</h2>
Expand Down
14 changes: 14 additions & 0 deletions apps/staff/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions apps/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f61c4a

Please sign in to comment.