Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Untis
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-Untis
Commits
50b03138
Verified
Commit
50b03138
authored
2 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Fix queries for next/future terms by wrapping around Untis' db structure
parent
9754df99
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!140
Resolve "Queries for current_{next,future} are still broken"
Pipeline
#65314
passed with warnings
2 years ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.rst
+5
-0
5 additions, 0 deletions
CHANGELOG.rst
aleksis/apps/untis/commands.py
+13
-16
13 additions, 16 deletions
aleksis/apps/untis/commands.py
aleksis/apps/untis/util/mysql/importers/terms.py
+17
-12
17 additions, 12 deletions
aleksis/apps/untis/util/mysql/importers/terms.py
with
35 additions
and
28 deletions
CHANGELOG.rst
+
5
−
0
View file @
50b03138
...
...
@@ -9,6 +9,11 @@ and this project adheres to `Semantic Versioning`_.
Unreleased
----------
Fixed
~~~~~
* Import commands `current_next` and `current_future` imported all terms.
`2.2`_ - 2022-04-10
-------------------
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/commands.py
+
13
−
16
View file @
50b03138
...
...
@@ -5,8 +5,10 @@ from django.utils.functional import classproperty
from
aleksis.apps.untis.util.mysql.importers.terms
import
(
get_future_terms_for_date
,
get_future_terms_for_date_query
,
get_terms
,
get_terms_for_date
,
get_terms_for_date_query
,
)
from
.util.mysql.main
import
untis_import_mysql
as
_untis_import_mysql
...
...
@@ -70,16 +72,20 @@ class CurrentNextImportCommand(ImportCommand):
@classmethod
def
get_terms
(
cls
)
->
Optional
[
QuerySet
]:
terms
=
get_terms_for_date
()
future_terms
=
get_future_terms_for_date
()
if
future_terms
.
exists
():
future_term
=
future_terms
.
first
()
terms
=
(
get_terms
()
.
filter
(
Q
(
pk__in
=
terms
.
values_list
(
"
pk
"
,
flat
=
True
))
|
Q
(
pk
=
future_term
.
pk
))
.
distinct
()
return
get_terms
().
filter
(
get_terms_for_date_query
()
|
Q
(
school_id
=
future_term
.
school_id
,
schoolyear_id
=
future_term
.
schoolyear_id
,
version_id
=
future_term
.
version_id
,
term_id
=
future_term
.
term_id
,
)
)
return
terms
else
:
return
get_terms_for_date
()
class
CurrentFutureImportCommand
(
ImportCommand
):
...
...
@@ -89,16 +95,7 @@ class CurrentFutureImportCommand(ImportCommand):
@classmethod
def
get_terms
(
cls
)
->
Optional
[
QuerySet
]:
terms
=
get_terms_for_date
()
future_terms
=
get_future_terms_for_date
()
terms
=
(
get_terms
()
.
filter
(
Q
(
pk__in
=
terms
.
values_list
(
"
pk
"
,
flat
=
True
))
|
Q
(
pk__in
=
future_terms
.
values_list
(
"
pk
"
,
flat
=
True
))
)
.
distinct
()
)
terms
=
get_terms
().
filter
(
get_future_terms_for_date_query
()
|
get_terms_for_date_query
())
return
terms
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/util/mysql/importers/terms.py
+
17
−
12
View file @
50b03138
...
...
@@ -2,7 +2,7 @@ import logging
from
datetime
import
date
from
typing
import
Dict
,
Optional
from
django.db.models
import
Max
,
OuterRef
,
QuerySet
,
Subquery
from
django.db.models
import
Max
,
OuterRef
,
Q
,
QuerySet
,
Subquery
from
django.utils
import
timezone
from
tqdm
import
tqdm
...
...
@@ -24,27 +24,32 @@ def get_terms() -> QuerySet:
return
run_using
(
mysql_models
.
Terms
.
objects
).
order_by
(
"
datefrom
"
)
def
get_terms_for_date
(
for_date
:
Optional
[
date
]
=
None
)
->
QuerySet
:
"""
Get term query
se
t with term valid for the provided date.
"""
def
get_terms_for_date
_query
(
for_date
:
Optional
[
date
]
=
None
)
->
QuerySet
:
"""
Get term query
objec
t with term valid for the provided date.
"""
if
not
for_date
:
for_date
=
timezone
.
now
().
date
()
qs
=
get_terms
().
filter
(
datefrom__lte
=
date_to_untis_date
(
for_date
),
dateto__gte
=
date_to_untis_date
(
for_date
),
)
return
Q
(
datefrom__lte
=
date_to_untis_date
(
for_date
),
dateto__gte
=
date_to_untis_date
(
for_date
))
def
get_terms_for_date
(
for_date
:
Optional
[
date
]
=
None
)
->
QuerySet
:
"""
Get term queryset with term valid for the provided date.
"""
qs
=
get_terms
().
filter
(
get_terms_for_date_query
(
for_date
))
return
qs
def
get_future_terms_for_date
(
for_date
:
Optional
[
date
]
=
None
)
->
QuerySet
:
"""
Get
all furture terms (after the current
term
)
.
"""
def
get_future_terms_for_date
_query
(
for_date
:
Optional
[
date
]
=
None
)
->
QuerySet
:
"""
Get
term query object with all future
term
s
.
"""
if
not
for_date
:
for_date
=
timezone
.
now
().
date
()
qs
=
get_terms
().
filter
(
datefrom__gt
=
date_to_untis_date
(
for_date
),
)
return
Q
(
datefrom__gt
=
date_to_untis_date
(
for_date
))
def
get_future_terms_for_date
(
for_date
:
Optional
[
date
]
=
None
)
->
QuerySet
:
"""
Get all future terms (after the current term).
"""
qs
=
get_terms
().
filter
(
get_future_terms_for_date_query
(
for_date
))
return
qs
...
...
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