Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Lesrooster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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®
Onboarding
AlekSIS-App-Lesrooster
Commits
ecb5a981
Verified
Commit
ecb5a981
authored
11 months ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add recurrence builder for usage in importer etc.
parent
ed59d880
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!32
Recurrence builder
Pipeline
#179147
passed with warnings
11 months ago
Stage: prepare
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+2
-2
2 additions, 2 deletions
.gitlab-ci.yml
aleksis/apps/lesrooster/models.py
+26
-0
26 additions, 0 deletions
aleksis/apps/lesrooster/models.py
aleksis/apps/lesrooster/tests/test_recurrence.py
+79
-0
79 additions, 0 deletions
aleksis/apps/lesrooster/tests/test_recurrence.py
with
107 additions
and
2 deletions
.gitlab-ci.yml
+
2
−
2
View file @
ecb5a981
...
@@ -3,8 +3,8 @@ include:
...
@@ -3,8 +3,8 @@ include:
file
:
/ci/general.yml
file
:
/ci/general.yml
-
project
:
"
AlekSIS/official/AlekSIS"
-
project
:
"
AlekSIS/official/AlekSIS"
file
:
/ci/prepare/lock.yml
file
:
/ci/prepare/lock.yml
#
- project: "AlekSIS/official/AlekSIS"
-
project
:
"
AlekSIS/official/AlekSIS"
#
file: /ci/test.yml
file
:
/ci/test
/test
.yml
-
project
:
"
AlekSIS/official/AlekSIS"
-
project
:
"
AlekSIS/official/AlekSIS"
file
:
/ci/test/lint.yml
file
:
/ci/test/lint.yml
-
project
:
"
AlekSIS/official/AlekSIS"
-
project
:
"
AlekSIS/official/AlekSIS"
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/lesrooster/models.py
+
26
−
0
View file @
ecb5a981
...
@@ -211,6 +211,24 @@ class Slot(ExtensiblePolymorphicModel):
...
@@ -211,6 +211,24 @@ class Slot(ExtensiblePolymorphicModel):
def
get_last_datetime
(
self
)
->
datetime
:
def
get_last_datetime
(
self
)
->
datetime
:
return
self
.
get_datetime_end
(
self
.
time_grid
.
validity_range
.
date_end
)
return
self
.
get_datetime_end
(
self
.
time_grid
.
validity_range
.
date_end
)
def
build_recurrence
(
self
,
*
args
,
**
kwargs
)
->
recurrence
.
Recurrence
:
"""
Build a recurrence for this slot respecting the validity range borders.
"""
pattern
=
recurrence
.
Recurrence
(
dtstart
=
timezone
.
make_aware
(
datetime
.
combine
(
self
.
time_grid
.
validity_range
.
date_start
,
self
.
time_start
)
),
rrules
=
[
recurrence
.
Rule
(
*
args
,
**
kwargs
,
until
=
timezone
.
make_aware
(
datetime
.
combine
(
self
.
time_grid
.
validity_range
.
date_end
,
self
.
time_end
)
),
)
],
)
return
pattern
class
Meta
:
class
Meta
:
constraints
=
[
constraints
=
[
models
.
UniqueConstraint
(
models
.
UniqueConstraint
(
...
@@ -305,6 +323,10 @@ class Lesson(TeacherPropertiesMixin, RoomPropertiesMixin, ExtensibleModel):
...
@@ -305,6 +323,10 @@ class Lesson(TeacherPropertiesMixin, RoomPropertiesMixin, ExtensibleModel):
if
self
.
slot_start
.
time_grid
!=
self
.
slot_end
.
time_grid
:
if
self
.
slot_start
.
time_grid
!=
self
.
slot_end
.
time_grid
:
raise
ValidationError
(
_
(
"
The slots must be in the same time grid.
"
))
raise
ValidationError
(
_
(
"
The slots must be in the same time grid.
"
))
def
build_recurrence
(
self
,
*
args
,
**
kwargs
)
->
"
recurrence.Recurrence
"
:
"""
Build a recurrence for this lesson respecting the validity range borders.
"""
return
self
.
slot_start
.
build_recurrence
(
*
args
,
**
kwargs
)
@property
@property
def
real_recurrence
(
self
)
->
"
recurrence.Recurrence
"
:
def
real_recurrence
(
self
)
->
"
recurrence.Recurrence
"
:
"""
Get the real recurrence adjusted to the validity range and including holidays.
"""
"""
Get the real recurrence adjusted to the validity range and including holidays.
"""
...
@@ -431,6 +453,10 @@ class Supervision(TeacherPropertiesMixin, RoomPropertiesMixin, ExtensibleModel):
...
@@ -431,6 +453,10 @@ class Supervision(TeacherPropertiesMixin, RoomPropertiesMixin, ExtensibleModel):
verbose_name
=
_
(
"
Supervision
"
)
verbose_name
=
_
(
"
Supervision
"
)
verbose_name_plural
=
_
(
"
Supervisions
"
)
verbose_name_plural
=
_
(
"
Supervisions
"
)
def
build_recurrence
(
self
,
*
args
,
**
kwargs
)
->
"
recurrence.Recurrence
"
:
"""
Build a recurrence for this supervision respecting the validity range borders.
"""
return
self
.
break_slot
.
build_recurrence
(
*
args
,
**
kwargs
)
@property
@property
def
real_recurrence
(
self
)
->
"
recurrence.Recurrence
"
:
def
real_recurrence
(
self
)
->
"
recurrence.Recurrence
"
:
"""
Get the real recurrence adjusted to the validity range and including holidays.
"""
"""
Get the real recurrence adjusted to the validity range and including holidays.
"""
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/lesrooster/tests/test_recurrence.py
0 → 100644
+
79
−
0
View file @
ecb5a981
from
datetime
import
date
,
datetime
,
time
from
pprint
import
pprint
from
django.utils.timezone
import
get_current_timezone
import
pytest
import
recurrence
from
aleksis.apps.lesrooster.models
import
(
BreakSlot
,
Lesson
,
Slot
,
Supervision
,
TimeGrid
,
ValidityRange
,
)
from
aleksis.core.models
import
SchoolTerm
pytestmark
=
pytest
.
mark
.
django_db
@pytest.fixture
def
school_term
():
date_start
=
date
(
2024
,
1
,
1
)
date_end
=
date
(
2024
,
6
,
1
)
school_term
=
SchoolTerm
.
objects
.
create
(
name
=
"
Test
"
,
date_start
=
date_start
,
date_end
=
date_end
)
return
school_term
@pytest.fixture
def
validity_range
(
school_term
):
validity_range
=
ValidityRange
.
objects
.
create
(
school_term
=
school_term
,
date_start
=
school_term
.
date_start
,
date_end
=
school_term
.
date_end
)
return
validity_range
@pytest.fixture
def
time_grid
(
validity_range
):
return
TimeGrid
.
objects
.
get
(
validity_range
=
validity_range
,
group
=
None
)
def
test_slot_build_recurrence
(
time_grid
):
slot
=
Slot
.
objects
.
create
(
time_grid
=
time_grid
,
weekday
=
0
,
period
=
1
,
time_start
=
time
(
8
,
0
),
time_end
=
time
(
9
,
0
)
)
rec
=
slot
.
build_recurrence
(
recurrence
.
WEEKLY
)
pprint
(
rec
.
rrules
[
0
].
__dict__
)
assert
rec
.
dtstart
==
datetime
(
2024
,
1
,
1
,
8
,
0
,
tzinfo
=
get_current_timezone
())
assert
len
(
rec
.
rrules
)
==
1
rrule
=
rec
.
rrules
[
0
]
assert
rrule
.
until
==
datetime
(
2024
,
6
,
1
,
9
,
0
,
tzinfo
=
get_current_timezone
())
assert
rrule
.
freq
==
2
assert
rrule
.
interval
==
1
def
test_lesson_recurrence
(
time_grid
):
slot
=
Slot
.
objects
.
create
(
time_grid
=
time_grid
,
weekday
=
0
,
period
=
1
,
time_start
=
time
(
8
,
0
),
time_end
=
time
(
9
,
0
)
)
break_slot
=
BreakSlot
.
objects
.
create
(
time_grid
=
time_grid
,
weekday
=
0
,
time_start
=
time
(
9
,
0
),
time_end
=
time
(
9
,
15
)
)
lesson
=
Lesson
.
objects
.
create
(
slot_start
=
slot
,
slot_end
=
slot
,
)
assert
lesson
.
build_recurrence
(
recurrence
.
WEEKLY
)
==
slot
.
build_recurrence
(
recurrence
.
WEEKLY
)
supervision
=
Supervision
.
objects
.
create
(
break_slot
=
break_slot
)
assert
supervision
.
build_recurrence
(
recurrence
.
WEEKLY
)
==
break_slot
.
build_recurrence
(
recurrence
.
WEEKLY
)
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