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
d7b75342
Verified
Commit
d7b75342
authored
5 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add QuerySet for extra lessons
parent
a6e7d260
No related branches found
No related tags found
1 merge request
!51
Include extra lessons
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/chronos/models.py
+42
-5
42 additions, 5 deletions
aleksis/apps/chronos/models.py
with
42 additions
and
5 deletions
aleksis/apps/chronos/models.py
+
42
−
5
View file @
d7b75342
...
...
@@ -946,14 +946,24 @@ class SupervisionSubstitution(ExtensibleModel):
verbose_name_plural
=
_
(
"
Supervision substitutions
"
)
class
EventQuerySet
(
DateRangeQuerySet
):
class
TimetableQuerySet
(
models
.
QuerySet
):
"""
Common filters
Models need following fields:
- groups
- teachers
- rooms (_multiple_rooms=True)/room (_multiple_rooms=False)
"""
_multiple_rooms
=
True
def
filter_participant
(
self
,
person
:
Union
[
Person
,
int
]):
"""
Filter for all
lesson
s a participant (student) attends.
"""
"""
Filter for all
object
s a participant (student) attends.
"""
return
self
.
filter
(
Q
(
groups_members
=
person
))
def
filter_group
(
self
,
group
:
Union
[
Group
,
int
]):
"""
Filter for all
even
ts a group (class) attends.
"""
"""
Filter for all
objec
ts a group (class) attends.
"""
if
isinstance
(
group
,
int
):
group
=
Group
.
objects
.
get
(
pk
=
group
)
...
...
@@ -970,9 +980,12 @@ class EventQuerySet(DateRangeQuerySet):
return
self
.
filter
(
teachers
=
teacher
)
def
filter_room
(
self
,
room
:
Union
[
Room
,
int
]):
"""
Filter for all
lesson
s taking part in a certain room.
"""
"""
Filter for all
object
s taking part in a certain room.
"""
return
self
.
filter
(
rooms
=
room
)
if
self
.
_multiple_rooms
:
return
self
.
filter
(
rooms
=
room
)
else
:
return
self
.
filter
(
room
=
room
)
def
filter_from_type
(
self
,
type_
:
str
,
pk
:
int
)
->
Optional
[
models
.
QuerySet
]:
if
type_
==
"
group
"
:
...
...
@@ -1002,6 +1015,10 @@ class EventQuerySet(DateRangeQuerySet):
return
None
class
EventQuerySet
(
DateRangeQuerySet
,
TimetableQuerySet
):
pass
class
Event
(
ExtensibleModel
):
label_
=
"
event
"
...
...
@@ -1032,7 +1049,27 @@ class Event(ExtensibleModel):
verbose_name_plural
=
_
(
"
Events
"
)
class
ExtraLessonQuerySet
(
TimetableQuerySet
):
_multiple_rooms
=
False
def
within_dates
(
self
,
start
:
date
,
end
:
date
):
week_start
=
CalendarWeek
.
from_date
(
start
)
week_end
=
CalendarWeek
.
from_date
(
end
)
return
self
.
filter
(
week__gte
=
week_start
.
week
,
week__lte
=
week_end
.
week
,
period__weekday__gte
=
start
.
weekday
(),
period__weekday__lte
=
end
.
weekday
(),
)
def
on_day
(
self
,
day
:
date
):
self
.
within_dates
(
day
,
day
)
class
ExtraLesson
(
ExtensibleModel
):
objects
=
models
.
Manager
.
from_queryset
(
ExtraLessonQuerySet
)()
week
=
models
.
IntegerField
(
verbose_name
=
_
(
"
Week
"
),
default
=
CalendarWeek
.
current_week
)
period
=
models
.
ForeignKey
(
"
TimePeriod
"
,
models
.
CASCADE
,
related_name
=
"
extra_lessons
"
)
...
...
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