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
b95906df
Verified
Commit
b95906df
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Use .annotate() to inject the week number.
parent
9bdf431d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
biscuit/apps/chronos/models.py
+14
-12
14 additions, 12 deletions
biscuit/apps/chronos/models.py
with
14 additions
and
12 deletions
biscuit/apps/chronos/models.py
+
14
−
12
View file @
b95906df
...
...
@@ -36,9 +36,7 @@ class LessonPeriodQuerySet(models.QuerySet):
return
self
.
filter
(
lesson__date_start__lte
=
wanted_week
[
0
]
+
timedelta
(
days
=
1
)
*
(
models
.
F
(
'
period__weekday
'
)
-
1
),
lesson__date_end__gte
=
wanted_week
[
0
]
+
timedelta
(
days
=
1
)
*
(
models
.
F
(
'
period__weekday
'
)
-
1
)
).
extra
(
select
=
{
'
_week
'
:
wanted_week
.
week
}
)
).
annotate_week
(
wanted_week
)
def
within_dates
(
self
,
start
:
date
,
end
:
date
):
return
self
.
filter
(
lesson__date_start__gte
=
start
,
lesson__date_end__lte
=
end
)
...
...
@@ -48,9 +46,7 @@ class LessonPeriodQuerySet(models.QuerySet):
return
self
.
within_dates
(
day
,
day
).
filter
(
period__weekday
=
weekday
).
extra
(
select
=
{
'
_week
'
:
week
.
week
}
)
).
annotate_week
(
week
)
def
at_time
(
self
,
when
:
Optional
[
datetime
]
=
None
):
now
=
when
or
datetime
.
now
()
...
...
@@ -62,9 +58,7 @@ class LessonPeriodQuerySet(models.QuerySet):
period__weekday
=
now
.
isoweekday
(),
period__time_start__lte
=
now
.
time
(),
period__time_end__gte
=
now
.
time
()
).
extra
(
select
=
{
'
_week
'
:
week
.
week
}
)
).
annotate_week
(
week
)
def
filter_participant
(
self
,
person
:
Union
[
Person
,
int
]):
return
self
.
filter
(
...
...
@@ -82,6 +76,16 @@ class LessonPeriodQuerySet(models.QuerySet):
return
self
.
filter
(
Q
(
substitutions__room
=
room
,
substitutions__week
=
models
.
F
(
'
_week
'
))
|
Q
(
room
=
room
))
def
annotate_week
(
self
,
week
:
Union
[
CalendarWeek
,
int
]):
if
isinstance
(
week
,
CalendarWeek
):
week_num
=
week
.
week
else
:
week_num
=
week
return
self
.
annotate
(
_week
=
models
.
Value
(
week_num
,
models
.
IntegerField
())
)
def
next
(
self
,
reference
:
LessonPeriod
,
offset
:
Optional
[
int
]
=
1
)
->
LessonPeriod
:
index
=
list
(
self
.
values_list
(
'
id
'
,
flat
=
True
)).
index
(
reference
.
id
)
...
...
@@ -92,9 +96,7 @@ class LessonPeriodQuerySet(models.QuerySet):
else
:
week
=
reference
.
_week
return
self
.
extra
(
select
=
{
'
_week
'
:
week
}
).
all
()[
next_index
]
return
self
.
annotate_week
(
week
).
all
()[
next_index
]
def
filter_from_query
(
self
,
query_data
:
QueryDict
):
if
query_data
.
get
(
'
group
'
,
None
):
...
...
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