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
0596b8b3
Verified
Commit
0596b8b3
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add new helper functions for getting start and end datetime of time periods in templates
parent
46f14742
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Pipeline
#2761
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/chronos/models.py
+10
-0
10 additions, 0 deletions
aleksis/apps/chronos/models.py
aleksis/apps/chronos/templatetags/week_helpers.py
+16
-1
16 additions, 1 deletion
aleksis/apps/chronos/templatetags/week_helpers.py
with
26 additions
and
1 deletion
aleksis/apps/chronos/models.py
+
10
−
0
View file @
0596b8b3
...
@@ -75,6 +75,16 @@ class TimePeriod(ExtensibleModel):
...
@@ -75,6 +75,16 @@ class TimePeriod(ExtensibleModel):
return
wanted_week
[
self
.
weekday
]
return
wanted_week
[
self
.
weekday
]
def
get_datetime_start
(
self
,
week
:
Optional
[
Union
[
CalendarWeek
,
int
]]
=
None
)
->
datetime
:
"""
Get datetime of lesson start in a specific week.
"""
day
=
self
.
get_date
(
week
)
return
datetime
.
combine
(
day
,
self
.
time_start
)
def
get_datetime_end
(
self
,
week
:
Optional
[
Union
[
CalendarWeek
,
int
]]
=
None
)
->
datetime
:
"""
Get datetime of lesson end in a specific week.
"""
day
=
self
.
get_date
(
week
)
return
datetime
.
combine
(
day
,
self
.
time_end
)
@classmethod
@classmethod
def
get_next_relevant_day
(
def
get_next_relevant_day
(
cls
,
day
:
Optional
[
date
]
=
None
,
time
:
Optional
[
time
]
=
None
,
prev
:
bool
=
False
cls
,
day
:
Optional
[
date
]
=
None
,
time
:
Optional
[
time
]
=
None
,
prev
:
bool
=
False
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/chronos/templatetags/week_helpers.py
+
16
−
1
View file @
0596b8b3
from
datetime
import
date
from
datetime
import
date
,
datetime
from
typing
import
Optional
,
Union
from
typing
import
Optional
,
Union
from
django
import
template
from
django
import
template
...
@@ -35,6 +35,21 @@ def period_to_date(week: Union[CalendarWeek, int], period) -> date:
...
@@ -35,6 +35,21 @@ def period_to_date(week: Union[CalendarWeek, int], period) -> date:
return
week_period_to_date
(
week
,
period
)
return
week_period_to_date
(
week
,
period
)
@register.simple_tag
def
period_to_time_start
(
week
:
Union
[
CalendarWeek
,
int
],
period
)
->
date
:
return
period
.
get_datetime_start
(
week
)
@register.simple_tag
def
period_to_time_end
(
week
:
Union
[
CalendarWeek
,
int
],
period
)
->
date
:
return
period
.
get_datetime_end
(
week
)
@register.simple_tag
@register.simple_tag
def
today
()
->
date
:
def
today
()
->
date
:
return
date
.
today
()
return
date
.
today
()
@register.simple_tag
def
now_datetime
()
->
datetime
:
return
datetime
.
now
()
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