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
e665f1f2
Verified
Commit
e665f1f2
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Move util code for getting first/last weekdays/periods to util.py
parent
3fe94035
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!13
Resolve "Support import from MySQL"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/untis/util/mysql/importers/absences.py
+5
-14
5 additions, 14 deletions
aleksis/apps/untis/util/mysql/importers/absences.py
aleksis/apps/untis/util/mysql/util.py
+33
-0
33 additions, 0 deletions
aleksis/apps/untis/util/mysql/util.py
with
38 additions
and
14 deletions
aleksis/apps/untis/util/mysql/importers/absences.py
+
5
−
14
View file @
e665f1f2
...
...
@@ -6,7 +6,7 @@ from .... import models as mysql_models
from
..util
import
(
run_default_filter
,
get_term
,
untis_date_to_date
,
untis_date_to_date
,
move_weekday_to_range
,
get_first_period
,
get_last_period
,
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -52,21 +52,12 @@ def import_absences(
weekday_to
=
date_to
.
weekday
()
# Check min/max weekdays
first_weekday
=
sorted
(
time_periods_ref
.
keys
())[
0
]
last_weekday
=
sorted
(
time_periods_ref
.
keys
())[
-
1
]
if
weekday_from
<
first_weekday
:
weekday_from
=
first_weekday
if
weekday_from
>
last_weekday
:
weekday_from
=
last_weekday
if
weekday_to
<
first_weekday
:
weekday_to
=
first_weekday
if
weekday_to
>
last_weekday
:
weekday_to
=
last_weekday
weekday_from
=
move_weekday_to_range
(
time_periods_ref
,
weekday_from
)
weekday_to
=
move_weekday_to_range
(
time_periods_ref
,
weekday_to
)
# Check min/max periods
first_period
=
sorte
d
(
time_periods_ref
[
first_weekday
].
keys
())[
0
]
last_period
=
sorte
d
(
time_periods_ref
[
first_weekday
].
keys
())[
-
1
]
first_period
=
get_first_perio
d
(
time_periods_ref
,
weekday_from
)
last_period
=
get_last_perio
d
(
time_periods_ref
,
weekday_from
)
if
period_from
==
0
:
period_from
=
first_period
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/util/mysql/util.py
+
33
−
0
View file @
e665f1f2
...
...
@@ -147,3 +147,36 @@ def connect_untis_fields(obj: Model, attr: str, limit: int) -> List[str]:
all_data
+=
data
return
all_data
def
get_first_weekday
(
time_periods_ref
:
dict
)
->
int
:
"""
Get first weekday from time periods reference
"""
return
sorted
(
time_periods_ref
.
keys
())[
0
]
def
get_last_weekday
(
time_periods_ref
:
dict
)
->
int
:
"""
Get last weekday from time periods reference
"""
return
sorted
(
time_periods_ref
.
keys
())[
-
1
]
def
get_first_period
(
time_periods_ref
:
dict
,
weekday
:
int
)
->
int
:
"""
Get first period on a weekday from time periods reference
"""
return
sorted
(
time_periods_ref
[
weekday
].
keys
())[
0
]
def
get_last_period
(
time_periods_ref
:
dict
,
weekday
:
int
)
->
int
:
"""
Get last period an a weekday from time periods reference
"""
return
sorted
(
time_periods_ref
[
weekday
].
keys
())[
-
1
]
def
move_weekday_to_range
(
time_periods_ref
:
dict
,
weekday
:
int
)
->
int
:
"""
Move weekday values into school week (e. g. saturday to friday)
"""
first_weekday
=
get_first_weekday
(
time_periods_ref
)
last_weekday
=
get_last_weekday
(
time_periods_ref
)
if
weekday
<
first_weekday
:
weekday
=
first_weekday
if
weekday
>
last_weekday
:
weekday
=
last_weekday
return
weekday
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