Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AlekSIS/official/AlekSIS-App-Alsijil
  • sunweaver/AlekSIS-App-Alsijil
  • 8tincsoVluke/AlekSIS-App-Alsijil
  • perfreicpo/AlekSIS-App-Alsijil
  • noifobarep/AlekSIS-App-Alsijil
  • 7ingannisdo/AlekSIS-App-Alsijil
  • unmruntartpa/AlekSIS-App-Alsijil
  • balrorebta/AlekSIS-App-Alsijil
  • comliFdifwa/AlekSIS-App-Alsijil
  • 3ranaadza/AlekSIS-App-Alsijil
10 results
Show changes
Commits on Source (4)
......@@ -79,11 +79,7 @@ class SelectForm(forms.Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["group"].queryset = (
Group.objects.for_current_school_term_or_all()
.annotate(lessons_count=Count("lessons"))
.filter(lessons_count__gt=0)
)
self.fields["group"].queryset = Group.get_groups_with_lessons()
PersonalNoteFormSet = forms.modelformset_factory(
......
from datetime import date
from typing import Dict, Optional, Union
from django.db.models import Exists, OuterRef, QuerySet
from django.db.models import Exists, OuterRef, Q, QuerySet
from django.db.models.aggregates import Count
import reversion
from calendarweek import CalendarWeek
......@@ -204,3 +205,28 @@ def get_extra_marks(
stats[extra_mark] = qs
return stats
@Group.class_method
def get_groups_with_lessons(cls: Group):
"""Get all groups which have related lessons or child groups with related lessons."""
group_pks = (
cls.objects.for_current_school_term_or_all()
.annotate(lessons_count=Count("lessons"))
.filter(lessons_count__gt=0)
.values_list("pk", flat=True)
)
groups = cls.objects.filter(
Q(child_groups__pk__in=group_pks) | Q(pk__in=group_pks)
).distinct()
return groups
@Person.method
def get_owner_groups_with_lessons(self: Person):
"""Get all groups the person is an owner of and which have related lessons.
Groups which have child groups with related lessons are also included.
"""
return Group.get_groups_with_lessons().filter(owners=self)
......@@ -17,7 +17,7 @@
$(document).ready(function () {
$("#id_date_start").change(function () {
$("#id_date_end").val($("#id_date_start").val());
$("#id_date_end").change();
initDatePicker("#id_date_end");
});
});
</script>
......
......@@ -463,11 +463,7 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
def my_students(request: HttpRequest) -> HttpResponse:
context = {}
relevant_groups = (
Group.objects.for_current_school_term_or_all()
.annotate(lessons_count=Count("lessons"))
.filter(lessons_count__gt=0, owners=request.user.person)
)
relevant_groups = request.user.person.get_owner_groups_with_lessons()
persons = Person.objects.filter(member_of__in=relevant_groups)
context["persons"] = persons
return render(request, "alsijil/class_register/persons.html", context)
......@@ -475,12 +471,7 @@ def my_students(request: HttpRequest) -> HttpResponse:
def my_groups(request: HttpRequest) -> HttpResponse:
context = {}
groups = (
Group.objects.for_current_school_term_or_all()
.annotate(lessons_count=Count("lessons"))
.filter(lessons_count__gt=0, owners=request.user.person)
)
context["groups"] = groups
context["groups"] = request.user.person.get_owner_groups_with_lessons()
return render(request, "alsijil/class_register/groups.html", context)
......