From 7c38023b28d23aa3912781c9e6bb6bdeefa58826 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: Mon, 2 Sep 2024 17:35:22 +0300 Subject: [PATCH] Complete (#871) --- apps/learning/admin.py | 18 ++++++++++++++++-- apps/learning/forms.py | 3 +-- apps/learning/tests/test_enrollment.py | 10 ++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/learning/admin.py b/apps/learning/admin.py index 526bd4f2f..f5b5f42d6 100644 --- a/apps/learning/admin.py +++ b/apps/learning/admin.py @@ -1,7 +1,7 @@ from dal_select2.widgets import Select2Multiple +from django.contrib.admin import SimpleListFilter from modeltranslation.admin import TranslationAdmin -from django.conf import settings from django.contrib import admin from django.db import models as db_models, models from django.utils.safestring import mark_safe @@ -24,6 +24,19 @@ from .services.personal_assignment_service import update_personal_assignment_score from .settings import AssignmentScoreUpdateSource, EnrollmentGradeUpdateSource +class CourseFilter(SimpleListFilter): + title = _('Course') + parameter_name = 'course' + template = 'admin/dropdown_listfilter.html' + + def lookups(self, request, model_admin): + courses = Course.objects.all().order_by('-pk').select_related('meta_course', 'semester') + return [(course.pk, str(course)) for course in courses] + + def queryset(self, request, queryset): + if self.value(): + return queryset.filter(course__pk=self.value()) + return queryset class CourseTeacherAdmin(BaseModelAdmin): list_display = ('teacher', 'course') @@ -123,7 +136,8 @@ class EnrollmentAdmin(BaseModelAdmin): list_filter = [ 'course__main_branch__site', 'course__main_branch', - ('course__semester', AdminRelatedDropdownFilter) + ('course__semester', AdminRelatedDropdownFilter), + CourseFilter, ] search_fields = ['course__meta_course__name', 'student__last_name'] exclude = ['grade_changed'] diff --git a/apps/learning/forms.py b/apps/learning/forms.py index 4c9f1a70e..c52ba067f 100644 --- a/apps/learning/forms.py +++ b/apps/learning/forms.py @@ -293,8 +293,7 @@ class CourseEnrollmentForm(forms.Form): ) reason = forms.CharField( label=_("Почему вы выбрали этот курс?"), - widget=forms.Textarea(), - required=False) + widget=forms.Textarea()) def __init__(self, **kwargs): ask_enrollment_reason = kwargs.pop('ask_enrollment_reason', None) diff --git a/apps/learning/tests/test_enrollment.py b/apps/learning/tests/test_enrollment.py index c47eef7df..18bb8a6eb 100644 --- a/apps/learning/tests/test_enrollment.py +++ b/apps/learning/tests/test_enrollment.py @@ -218,8 +218,13 @@ def test_enrollment_leave_reason(client): client.post(co.get_enroll_url(), data={ "type": EnrollmentTypes.REGULAR }) + assert Enrollment.active.count() == 0 + client.post(co.get_enroll_url(), data={ + "type": EnrollmentTypes.REGULAR, + "reason": "reason" + }) assert Enrollment.active.count() == 1 - assert Enrollment.objects.first().reason_entry == '' + assert "reason" in Enrollment.objects.first().reason_entry client.post(co.get_unenroll_url(), data={ "type": EnrollmentTypes.REGULAR, "reason": "foo" @@ -230,7 +235,8 @@ def test_enrollment_leave_reason(client): assert 'foo' in e.reason_leave # Enroll for the second time and leave with another reason client.post(co.get_enroll_url(), data={ - "type": EnrollmentTypes.REGULAR + "type": EnrollmentTypes.REGULAR, + "reason": "reason" }) assert Enrollment.active.count() == 1 client.post(co.get_unenroll_url(), data={