Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp-notification
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp-notification
Commits
2bffcb20
Commit
2bffcb20
authored
3 years ago
by
Fay Arnold
Browse files
Options
Downloads
Patches
Plain Diff
add webpushnotification dependency and post_save hook for notifications
parent
4a62ae1e
No related branches found
No related tags found
No related merge requests found
Pipeline
#11134
passed with stage
in 52 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp_notification/models.py
+30
-0
30 additions, 0 deletions
djangoldp_notification/models.py
setup.cfg
+1
-0
1 addition, 0 deletions
setup.cfg
with
31 additions
and
0 deletions
djangoldp_notification/models.py
+
30
−
0
View file @
2bffcb20
import
requests
import
json
from
django.conf
import
settings
from
django.contrib.auth
import
get_user_model
from
django.core.mail
import
send_mail
...
...
@@ -275,6 +276,35 @@ def send_email_on_notification(sender, instance, created, **kwargs):
html_message
=
html_message
)
@receiver
(
post_save
,
sender
=
Notification
)
def
send_webpush_on_notification
(
sender
,
instance
,
created
,
**
kwargs
):
if
instance
.
summary
:
if
instance
.
user
:
# if the person exists and accepts notifications
try
:
# local author
if
instance
.
author
.
startswith
(
settings
.
SITE_URL
):
who
=
str
(
Model
.
resolve_id
(
instance
.
author
.
replace
(
settings
.
SITE_URL
,
''
)).
get_full_name
())
# external author
else
:
who
=
requests
.
get
(
instance
.
author
).
json
()[
'
name
'
]
except
:
who
=
"
Quelqu
'
un
"
payload
=
{
"
head
"
:
"
Notification from
"
+
who
,
"
body
"
:
instance
.
summary
,
"
id
"
:
instance
.
user
.
id
}
# make the payload that we wanna send?
url
=
settings
.
SITE_URL
+
reverse
(
"
send_webpush
"
)
# get the url to post webpush to
response
=
requests
.
post
(
url
,
data
=
json
.
dumps
(
payload
)
)
@receiver
(
post_save
,
sender
=
settings
.
AUTH_USER_MODEL
)
def
create_user_settings
(
sender
,
instance
,
created
,
**
kwargs
):
try
:
...
...
This diff is collapsed.
Click to expand it.
setup.cfg
+
1
−
0
View file @
2bffcb20
...
...
@@ -12,6 +12,7 @@ packages = find:
install_requires
=
djangoldp~=2.1.0
djangoldp_account~=2.1
djangoldp_webpushnotification~=1.0.0
[options.extras_require]
include_package_data
= 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