Skip to content

Commit

Permalink
Update log mechanics (#866)
Browse files Browse the repository at this point in the history
* Add log models

* Add log models

* Complete academic disciplines part

* Finish status log

* Minor issues

* Tests
  • Loading branch information
Dmi4er4 authored Aug 18, 2024
1 parent 4f61c4a commit b8a5231
Show file tree
Hide file tree
Showing 29 changed files with 1,191 additions and 197 deletions.
2 changes: 1 addition & 1 deletion apps/admission/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-08 14:00+0000\n"
"POT-Creation-Date: 2024-08-12 14:53+0000\n"
"PO-Revision-Date: 2024-07-23 17:04+0000\n"
"Last-Translator: Дмитрий Чернушевич <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion apps/htmlpages/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-08 14:00+0000\n"
"POT-Creation-Date: 2024-08-12 14:53+0000\n"
"PO-Revision-Date: 2015-03-18 08:34+0000\n"
"Last-Translator: Jannis Leidel <[email protected]>\n"
"Language-Team: Russian (http://www.transifex.com/projects/p/django/language/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def handle(self, *args, **options):
"graduated_on": graduated_on,
})
update_student_status(student_profile, new_status=StudentStatuses.GRADUATE,
editor=admin, status_changed_at=graduated_on)
editor=admin, changed_at=graduated_on)
cache_key_pattern = GraduateProfile.HISTORY_CACHE_KEY_PATTERN
cache_key = cache_key_pattern.format(site_id=settings.SITE_ID)
cache.delete(cache_key)
Expand Down
5 changes: 3 additions & 2 deletions apps/learning/tests/test_service_personal_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ def test_service_update_personal_assignment_stats_published(django_capture_on_co
assert 'count' in solutions_stats
assert solutions_stats['count'] == 2
assert 'first' in solutions_stats
assert solutions_stats['first'] == comment1.created.replace(microsecond=0)
delta = timedelta(seconds=1)
assert comment1.created - delta <= solutions_stats['first'] <= comment1.created + delta
assert 'last' in solutions_stats
assert solutions_stats['last'] == fixed_dt.replace(microsecond=0)
assert fixed_dt - delta <= solutions_stats['last'] <= fixed_dt + delta


@pytest.mark.django_db
Expand Down
2 changes: 1 addition & 1 deletion apps/projects/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-08 14:00+0000\n"
"POT-Creation-Date: 2024-08-12 14:53+0000\n"
"PO-Revision-Date: 2022-02-21 15:24+0000\n"
"Last-Translator: Сергей Жеревчук <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
162 changes: 160 additions & 2 deletions apps/staff/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import django_filters
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, Layout, Row, Submit
from crispy_forms.layout import Div, Layout, Row, Submit, Column
from django.conf import settings

from django.utils.translation import gettext_lazy as _

from core.models import Branch
from courses.utils import get_current_term_pair
from learning.models import Invitation
from users.models import StudentProfile, StudentTypes
from learning.settings import StudentStatuses
from study_programs.models import AcademicDiscipline
from users.models import StudentProfile, StudentTypes, StudentAcademicDisciplineLog, StudentStatusLog


class StudentProfileFilter(django_filters.FilterSet):
Expand Down Expand Up @@ -107,3 +110,158 @@ def qs(self):
if not self.is_bound or not self.is_valid():
return self.queryset.none()
return super().qs

class StudentAcademicDisciplineLogFilter(django_filters.FilterSet):
academic_discipline = django_filters.ModelChoiceFilter(
label=_('Field of study'),
queryset=AcademicDiscipline.objects.all(),
required=False
)
former_academic_discipline = django_filters.ModelChoiceFilter(
label=_('Former field of study'),
queryset=AcademicDiscipline.objects.all(),
required=False
)
is_processed = django_filters.BooleanFilter(
label=_('Is processed'),
required=False
)
branch = django_filters.ModelChoiceFilter(
label=_('Branch'),
queryset=Branch.objects.filter(site_id=settings.SITE_ID, active=True),
field_name='student_profile__branch'
)
type = django_filters.ChoiceFilter(
label=_("Type"),
choices=StudentTypes.choices,
field_name='student_profile__type'
)

class Meta:
model = StudentAcademicDisciplineLog
fields = ['academic_discipline', 'former_academic_discipline', 'is_processed', 'branch', 'type']

@property
def qs(self):
queryset = super().qs
return queryset.select_related(
'academic_discipline',
'former_academic_discipline',
'student_profile__branch',
'student_profile__user'
)


@property
def form(self):
if not hasattr(self, '_form'):
self._form = super().form

self._form.fields['branch'].label_from_instance=lambda obj: obj.name

self._form.helper = FormHelper()
self._form.helper.form_method = "GET"
self._form.helper.layout = Layout(
Row(
Column(
"former_academic_discipline",
"academic_discipline",
css_class="col-xs-5"
),
Column(
Column("type", "branch", css_class="col-xs-7"),
Column("is_processed", css_class="col-xs-5"),
css_class="col-xs-5"
),
Column(
Submit("", _("Filter"), css_class="btn-block -inline-submit"),
Submit("download_csv", _('Download'), css_class="btn-block -inline-submit"),
Submit("mark_processed", _('Mark processed'), css_class="btn-block -inline-submit"),
css_class="col-xs-2",
)
)
)
return self._form

class StudentStatusLogFilter(django_filters.FilterSet):
STATUS_CHOICES = (("empty", _("Studying")),) + StudentStatuses.choices
status = django_filters.ChoiceFilter(
label=_('Status'),
choices=STATUS_CHOICES,
required=False,
method='filter_by_status'
)
former_status = django_filters.ChoiceFilter(
label=_('Former status'),
choices=STATUS_CHOICES,
required=False,
method='filter_by_former_status'
)
is_processed = django_filters.BooleanFilter(
label=_('Is processed'),
required=False
)
branch = django_filters.ModelChoiceFilter(
label=_('Branch'),
queryset=Branch.objects.filter(site_id=settings.SITE_ID, active=True),
field_name='student_profile__branch'
)
type = django_filters.ChoiceFilter(
label=_("Type"),
choices=StudentTypes.choices,
field_name='student_profile__type',
required=False
)

class Meta:
model = StudentStatusLog
fields = ['status', 'former_status', 'is_processed', 'branch', 'type']

def filter_by_status(self, queryset, name, value):
if value == "empty":
return queryset.filter(status="")
return queryset.filter(**{name: value})

def filter_by_former_status(self, queryset, name, value):
if value == "empty":
return queryset.filter(former_status="")
return queryset.filter(**{name: value})

@property
def qs(self):
queryset = super().qs
return queryset.select_related(
'student_profile__branch',
'student_profile__user'
)

@property
def form(self):
if not hasattr(self, '_form'):
self._form = super().form

self._form.fields['branch'].label_from_instance=lambda obj: obj.name

self._form.helper = FormHelper()
self._form.helper.form_method = "GET"
self._form.helper.layout = Layout(
Row(
Column(
"former_status",
"status",
css_class="col-xs-5"
),
Column(
Column("type", "branch", css_class="col-xs-7"),
Column("is_processed", css_class="col-xs-5"),
css_class="col-xs-5"
),
Column(
Submit("", _("Filter"), css_class="btn-block -inline-submit"),
Submit("download_csv", _('Download'), css_class="btn-block -inline-submit"),
Submit("mark_processed", _('Mark processed'), css_class="btn-block -inline-submit"),
css_class="col-xs-2",
)
)
)
return self._form
7 changes: 7 additions & 0 deletions apps/staff/templates/staff/exports.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ <h4 class="list-group-item-heading">За семестр</h4>
<h4 class="list-group-item-heading"><a href="{% url 'staff:enrollment_invitations_list' %}">Приглашенные студенты</a></h4>
</div>
</div>
<h2>Списки для приказов</h2>
<div class="list-group-item">
<h4 class="list-group-item-heading"><a href="{% url 'staff:academic_discipline_log_list' %}">Смена направления обучения</a></h4>
</div>
<div class="list-group-item">
<h4 class="list-group-item-heading"><a href="{% url 'staff:status_log_list' %}">Смена статуса</a></h4>
</div>
<h2>Проекты</h2>
<div class="list-group">
<div class="list-group-item">
Expand Down
Empty file added apps/staff/tests/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions apps/staff/tests/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import factory.fuzzy
from learning.settings import StudentStatuses
from study_programs.tests.factories import AcademicDisciplineFactory
from users.models import StudentStatusLog, StudentAcademicDisciplineLog
from users.tests.factories import StudentProfileFactory, CuratorFactory

__all__ = ('StudentStatusLogFactory', 'StudentAcademicDisciplineLogFactory')

class StudentStatusLogFactory(factory.django.DjangoModelFactory):
class Meta:
model = StudentStatusLog

status = factory.fuzzy.FuzzyChoice([x for x, _ in StudentStatuses.choices])
entry_author = factory.SubFactory(CuratorFactory)

@factory.lazy_attribute
def student_profile(self):
return StudentProfileFactory(status=self.status)

class StudentAcademicDisciplineLogFactory(factory.django.DjangoModelFactory):
class Meta:
model = StudentAcademicDisciplineLog

academic_discipline = factory.SubFactory(AcademicDisciplineFactory)
entry_author = factory.SubFactory(CuratorFactory)

@factory.lazy_attribute
def student_profile(self):
return StudentProfileFactory(academic_disciplines=[self.academic_discipline])

16 changes: 2 additions & 14 deletions apps/staff/tests.py → apps/staff/tests/test_diplomas.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ 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 Expand Up @@ -201,8 +189,8 @@ def test_official_diplomas_list_should_be_sorted(client):

soup = BeautifulSoup(response.content, "html.parser")
user_links = [a["href"] for a in soup.select("div.container > ul > li > a")]
assert user_links[0] == g2.student_profile.user.get_absolute_url()
assert user_links[1] == g1.student_profile.user.get_absolute_url()
assert user_links[-2] == g2.student_profile.user.get_absolute_url()
assert user_links[-1] == g1.student_profile.user.get_absolute_url()


@pytest.mark.django_db
Expand Down
Loading

0 comments on commit b8a5231

Please sign in to comment.