Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Chronos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Chronos
Commits
d7034148
Verified
Commit
d7034148
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Extend querysets for holidays and groups
parent
d106cacb
No related branches found
No related tags found
1 merge request
!138
Extend querysets for holidays and groups
Pipeline
#6403
passed
4 years ago
Stage: test
Stage: build
Stage: publish
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/chronos/managers.py
+28
-2
28 additions, 2 deletions
aleksis/apps/chronos/managers.py
aleksis/apps/chronos/models.py
+6
-1
6 additions, 1 deletion
aleksis/apps/chronos/models.py
with
34 additions
and
3 deletions
aleksis/apps/chronos/managers.py
+
28
−
2
View file @
d7034148
from
datetime
import
date
,
datetime
,
timedelta
from
enum
import
Enum
from
typing
import
Optional
,
Union
from
typing
import
Iterable
,
Optional
,
Union
from
django.contrib.sites.managers
import
CurrentSiteManager
as
_CurrentSiteManager
from
django.db
import
models
from
django.db.models
import
Count
,
F
,
Q
,
QuerySet
from
django.db.models
import
Count
,
ExpressionWrapper
,
F
,
Func
,
Q
,
QuerySet
,
Value
from
django.db.models.fields
import
DateField
from
django.db.models.functions
import
Concat
from
calendarweek
import
CalendarWeek
...
...
@@ -298,6 +300,13 @@ class LessonDataQuerySet(models.QuerySet, WeekQuerySetMixin):
|
Q
(
**
{
self
.
_period_path
+
"
lesson__groups__parent_groups
"
:
group
})
)
def
filter_groups
(
self
,
groups
:
Iterable
[
Group
])
->
QuerySet
:
"""
Filter for all lessons one of the groups regularly attends.
"""
return
self
.
filter
(
Q
(
**
{
self
.
_period_path
+
"
lesson__groups__in
"
:
groups
})
|
Q
(
**
{
self
.
_period_path
+
"
lesson__groups__parent_groups__in
"
:
groups
})
)
def
filter_teacher
(
self
,
teacher
:
Union
[
Person
,
int
]):
"""
Filter for all lessons given by a certain teacher.
"""
qs1
=
self
.
filter
(
**
{
self
.
_period_path
+
"
lesson__teachers
"
:
teacher
})
...
...
@@ -589,6 +598,10 @@ class TimetableQuerySet(models.QuerySet):
else
:
return
self
.
filter
(
Q
(
groups
=
group
)
|
Q
(
groups__parent_groups
=
group
))
def
filter_groups
(
self
,
groups
:
Iterable
[
Group
])
->
QuerySet
:
"""
Filter for all objects one of the groups attends.
"""
return
self
.
filter
(
Q
(
groups__in
=
groups
)
|
Q
(
groups__parent_groups__in
=
groups
)).
distinct
()
def
filter_teacher
(
self
,
teacher
:
Union
[
Person
,
int
]):
"""
Filter for all lessons given by a certain teacher.
"""
return
self
.
filter
(
teachers
=
teacher
)
...
...
@@ -663,6 +676,19 @@ class ExtraLessonQuerySet(TimetableQuerySet, SchoolTermRelatedQuerySet, GroupByP
"""
Filter all extra lessons on a day.
"""
return
self
.
within_dates
(
day
,
day
)
def
annotate_day
(
self
):
weekday_to_date
=
ExpressionWrapper
(
Func
(
Concat
(
F
(
"
year
"
),
F
(
"
week
"
)),
Value
(
"
IYYYIW
"
),
output_field
=
DateField
(),
function
=
"
TO_DATE
"
,
)
+
F
(
"
period__weekday
"
),
output_field
=
DateField
(),
)
return
self
.
annotate
(
day
=
weekday_to_date
)
class
GroupPropertiesMixin
:
"""
Mixin for common group properties.
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/chronos/models.py
+
6
−
1
View file @
d7034148
...
...
@@ -3,7 +3,7 @@
from
__future__
import
annotations
from
datetime
import
date
,
datetime
,
time
,
timedelta
from
typing
import
Dict
,
List
,
Optional
,
Tuple
,
Union
from
typing
import
Dict
,
Iterator
,
List
,
Optional
,
Tuple
,
Union
from
django.core.exceptions
import
ValidationError
from
django.db
import
models
...
...
@@ -685,6 +685,11 @@ class Holiday(ExtensibleModel):
date_end
=
models
.
DateField
(
verbose_name
=
_
(
"
End date
"
),
null
=
True
)
comments
=
models
.
TextField
(
verbose_name
=
_
(
"
Comments
"
),
blank
=
True
,
null
=
True
)
def
get_days
(
self
)
->
Iterator
[
date
]:
delta
=
self
.
date_end
-
self
.
date_start
for
i
in
range
(
delta
.
days
+
1
):
yield
self
.
date_start
+
timedelta
(
days
=
i
)
@classmethod
def
on_day
(
cls
,
day
:
date
)
->
Optional
[
"
Holiday
"
]:
holidays
=
cls
.
objects
.
on_day
(
day
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment