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
637d35d9
Verified
Commit
637d35d9
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Don't send notifications for changes in irrelevant time range
parent
31043aa6
No related branches found
No related tags found
1 merge request
!242
Resolve "Notification for changes in the substitution plan"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/chronos/model_extensions.py
+24
-5
24 additions, 5 deletions
aleksis/apps/chronos/model_extensions.py
aleksis/apps/chronos/models.py
+28
-0
28 additions, 0 deletions
aleksis/apps/chronos/models.py
aleksis/apps/chronos/preferences.py
+12
-1
12 additions, 1 deletion
aleksis/apps/chronos/preferences.py
with
64 additions
and
6 deletions
aleksis/apps/chronos/model_extensions.py
+
24
−
5
View file @
637d35d9
from
datetime
import
date
import
zoneinfo
from
datetime
import
date
,
timedelta
from
typing
import
Optional
,
Union
from
typing
import
Optional
,
Union
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
from
django.conf
import
settings
from
django.conf
import
settings
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
django.urls
import
reverse
from
django.urls
import
reverse
from
django.utils
import
timezone
from
django.utils.formats
import
date_format
from
django.utils.formats
import
date_format
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
ngettext
from
django.utils.translation
import
ngettext
...
@@ -19,6 +21,7 @@ from aleksis.apps.chronos.models import (
...
@@ -19,6 +21,7 @@ from aleksis.apps.chronos.models import (
SupervisionSubstitution
,
SupervisionSubstitution
,
)
)
from
aleksis.core.models
import
Announcement
,
Group
,
Notification
,
Person
from
aleksis.core.models
import
Announcement
,
Group
,
Notification
,
Person
from
aleksis.core.util.core_helpers
import
get_site_preferences
from
.managers
import
TimetableType
from
.managers
import
TimetableType
from
.models
import
Lesson
,
LessonPeriod
,
Subject
from
.models
import
Lesson
,
LessonPeriod
,
Subject
...
@@ -172,6 +175,21 @@ def send_notifications(sender: Revision, **kwargs):
...
@@ -172,6 +175,21 @@ def send_notifications(sender: Revision, **kwargs):
if
change
.
deleted
:
if
change
.
deleted
:
continue
continue
dt_start
,
dt_end
=
change
.
instance
.
time_range
dt_start
=
dt_start
.
replace
(
tzinfo
=
zoneinfo
.
ZoneInfo
(
settings
.
TIME_ZONE
))
dt_end
=
dt_end
.
replace
(
tzinfo
=
zoneinfo
.
ZoneInfo
(
settings
.
TIME_ZONE
))
send_time
=
get_site_preferences
()[
"
chronos__time_for_sending_notifications
"
]
start_range
=
timezone
.
now
().
replace
(
hour
=
send_time
.
hour
,
minute
=
send_time
.
minute
)
if
timezone
.
now
().
time
()
>
send_time
:
start_range
=
start_range
-
timedelta
(
days
=
1
)
end_range
=
start_range
+
timedelta
(
days
=
1
)
if
dt_start
<=
end_range
and
dt_end
>=
start_range
:
# Skip this because it's not in the current range for notifications
continue
recipients
=
[]
recipients
=
[]
if
isinstance
(
change
.
instance
,
LessonSubstitution
):
if
isinstance
(
change
.
instance
,
LessonSubstitution
):
recipients
+=
change
.
instance
.
lesson_period
.
lesson
.
teachers
.
all
()
recipients
+=
change
.
instance
.
lesson_period
.
lesson
.
teachers
.
all
()
...
@@ -333,11 +351,12 @@ def send_notifications(sender: Revision, **kwargs):
...
@@ -333,11 +351,12 @@ def send_notifications(sender: Revision, **kwargs):
new
=
change
.
instance
.
teacher
.
full_name
,
new
=
change
.
instance
.
teacher
.
full_name
,
)
)
day
=
(
change
.
instance
.
date
if
hasattr
(
change
.
instance
,
"
date
"
)
else
change
.
instance
.
date_start
)
url
=
urljoin
(
url
=
urljoin
(
settings
.
BASE_URL
,
reverse
(
"
my_timetable_by_date
"
,
args
=
[
day
.
year
,
day
.
month
,
day
.
day
])
settings
.
BASE_URL
,
reverse
(
"
my_timetable_by_date
"
,
args
=
[
dt_start
.
date
().
year
,
dt_start
.
date
().
month
,
dt_start
.
date
().
day
],
),
)
)
for
recipient
in
recipients
:
for
recipient
in
recipients
:
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/chronos/models.py
+
28
−
0
View file @
637d35d9
...
@@ -469,6 +469,12 @@ class LessonSubstitution(ExtensibleModel, TeacherPropertiesMixin, WeekRelatedMix
...
@@ -469,6 +469,12 @@ class LessonSubstitution(ExtensibleModel, TeacherPropertiesMixin, WeekRelatedMix
week
=
CalendarWeek
(
week
=
self
.
week
,
year
=
self
.
year
)
week
=
CalendarWeek
(
week
=
self
.
week
,
year
=
self
.
year
)
return
week
[
self
.
lesson_period
.
period
.
weekday
]
return
week
[
self
.
lesson_period
.
period
.
weekday
]
@property
def
time_range
(
self
):
return
timezone
.
datetime
.
combine
(
self
.
date
,
self
.
lesson_period
.
period
.
time_start
),
timezone
.
datetime
.
combine
(
self
.
date
,
self
.
lesson_period
.
period
.
time_end
)
def
get_teachers
(
self
):
def
get_teachers
(
self
):
return
self
.
teachers
return
self
.
teachers
...
@@ -1024,6 +1030,16 @@ class SupervisionSubstitution(ExtensibleModel):
...
@@ -1024,6 +1030,16 @@ class SupervisionSubstitution(ExtensibleModel):
def
teachers
(
self
):
def
teachers
(
self
):
return
[
self
.
teacher
]
return
[
self
.
teacher
]
@property
def
time_range
(
self
):
return
timezone
.
datetime
.
combine
(
self
.
date
,
self
.
supervision
.
break_item
.
time_start
or
self
.
supervision
.
break_item
.
time_end
,
),
timezone
.
datetime
.
combine
(
self
.
date
,
self
.
supervision
.
break_item
.
time_end
or
self
.
supervision
.
break_item
.
time_start
,
)
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"
{
self
.
supervision
}
,
{
date_format
(
self
.
date
)
}
"
return
f
"
{
self
.
supervision
}
,
{
date_format
(
self
.
date
)
}
"
...
@@ -1136,6 +1152,12 @@ class Event(SchoolTermRelatedExtensibleModel, GroupPropertiesMixin, TeacherPrope
...
@@ -1136,6 +1152,12 @@ class Event(SchoolTermRelatedExtensibleModel, GroupPropertiesMixin, TeacherPrope
"""
Get teachers relation.
"""
"""
Get teachers relation.
"""
return
self
.
teachers
return
self
.
teachers
@property
def
time_range
(
self
):
return
timezone
.
datetime
.
combine
(
self
.
date_start
,
self
.
period_from
.
time_start
),
timezone
.
datetime
.
combine
(
self
.
date_end
,
self
.
period_to
.
time_end
)
class
Meta
:
class
Meta
:
# Heads up: Link to period implies uniqueness per site
# Heads up: Link to period implies uniqueness per site
ordering
=
[
"
date_start
"
]
ordering
=
[
"
date_start
"
]
...
@@ -1207,6 +1229,12 @@ class ExtraLesson(
...
@@ -1207,6 +1229,12 @@ class ExtraLesson(
"""
Get subject.
"""
"""
Get subject.
"""
return
self
.
subject
return
self
.
subject
@property
def
time_range
(
self
):
return
timezone
.
datetime
.
combine
(
self
.
date
,
self
.
period
.
time_start
),
timezone
.
datetime
.
combine
(
self
.
date
,
self
.
period
.
time_end
)
class
Meta
:
class
Meta
:
# Heads up: Link to period implies uniqueness per site
# Heads up: Link to period implies uniqueness per site
verbose_name
=
_
(
"
Extra lesson
"
)
verbose_name
=
_
(
"
Extra lesson
"
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/chronos/preferences.py
+
12
−
1
View file @
637d35d9
from
datetime
import
time
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
from
dynamic_preferences.preferences
import
Section
from
dynamic_preferences.preferences
import
Section
from
dynamic_preferences.types
import
BooleanPreference
,
IntegerPreference
from
dynamic_preferences.types
import
BooleanPreference
,
IntegerPreference
,
TimePreference
from
aleksis.core.registries
import
person_preferences_registry
,
site_preferences_registry
from
aleksis.core.registries
import
person_preferences_registry
,
site_preferences_registry
...
@@ -67,3 +69,12 @@ class AffectedGroupsUseParentGroups(BooleanPreference):
...
@@ -67,3 +69,12 @@ class AffectedGroupsUseParentGroups(BooleanPreference):
verbose_name
=
_
(
verbose_name
=
_
(
"
Show parent groups in header box in substitution views instead of original groups
"
"
Show parent groups in header box in substitution views instead of original groups
"
)
)
@site_preferences_registry.register
class
TimeForSendingNotifications
(
TimePreference
):
section
=
chronos
name
=
"
time_for_sending_notifications
"
default
=
time
(
17
,
00
)
verbose_name
=
_
(
"
Time for sending notifications for the next day
"
)
required
=
True
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