Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp-notification
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
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
b87d9a0d
Commit
b87d9a0d
authored
4 years ago
by
Calum Mackervoy
Committed by
Jean-Baptiste Pasquier
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feature: sends notifications to subscribers post delete
parent
e42758dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp_notification/models.py
+7
-4
7 additions, 4 deletions
djangoldp_notification/models.py
with
7 additions
and
4 deletions
djangoldp_notification/models.py
+
7
−
4
View file @
b87d9a0d
...
@@ -4,7 +4,7 @@ import requests
...
@@ -4,7 +4,7 @@ import requests
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.mail
import
send_mail
from
django.core.mail
import
send_mail
from
django.db
import
models
from
django.db
import
models
from
django.db.models.signals
import
post_save
from
django.db.models.signals
import
post_save
,
post_delete
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
django.template
import
loader
from
django.template
import
loader
from
django.urls
import
NoReverseMatch
from
django.urls
import
NoReverseMatch
...
@@ -87,9 +87,11 @@ class Subscription(Model):
...
@@ -87,9 +87,11 @@ class Subscription(Model):
super
(
Subscription
,
self
).
save
(
*
args
,
**
kwargs
)
super
(
Subscription
,
self
).
save
(
*
args
,
**
kwargs
)
# --- SUBSCRIPTION SYSTEM ---
# --- SUBSCRIPTION SYSTEM ---
@receiver
(
post_save
,
dispatch_uid
=
"
callback_notif
"
)
@receiver
(
post_save
,
dispatch_uid
=
"
callback_notif
"
)
def
send_notification
(
sender
,
instance
,
created
,
**
kwargs
):
@receiver
(
post_delete
,
dispatch_uid
=
"
delete_callback_notif
"
)
def
send_notification
(
sender
,
instance
,
**
kwargs
):
if
sender
!=
Notification
:
if
sender
!=
Notification
:
threads
=
[]
threads
=
[]
try
:
try
:
...
@@ -101,13 +103,14 @@ def send_notification(sender, instance, created, **kwargs):
...
@@ -101,13 +103,14 @@ def send_notification(sender, instance, created, **kwargs):
# dispatch a notification for every Subscription on this resource
# dispatch a notification for every Subscription on this resource
for
subscription
in
Subscription
.
objects
.
filter
(
models
.
Q
(
object
=
url_resource
)
|
models
.
Q
(
object
=
url_container
)):
for
subscription
in
Subscription
.
objects
.
filter
(
models
.
Q
(
object
=
url_resource
)
|
models
.
Q
(
object
=
url_container
)):
if
not
instance
.
is_backlink
:
if
not
instance
.
is_backlink
:
process
=
Thread
(
target
=
send_request
,
args
=
[
subscription
.
inbox
,
url_resource
,
instance
,
created
])
process
=
Thread
(
target
=
send_request
,
args
=
[
subscription
.
inbox
,
url_resource
,
instance
,
kwargs
.
get
(
"
created
"
,
False
)])
process
.
start
()
process
.
start
()
threads
.
append
(
process
)
threads
.
append
(
process
)
def
send_request
(
target
,
object_iri
,
instance
,
created
):
def
send_request
(
target
,
object_iri
,
instance
,
created
):
unknown
=
_
(
"
Auteur inconnu
"
)
unknown
=
str
(
_
(
"
Auteur inconnu
"
)
)
author
=
getattr
(
getattr
(
instance
,
MODEL_MODIFICATION_USER_FIELD
,
unknown
),
"
urlid
"
,
unknown
)
author
=
getattr
(
getattr
(
instance
,
MODEL_MODIFICATION_USER_FIELD
,
unknown
),
"
urlid
"
,
unknown
)
request_type
=
"
creation
"
if
created
else
"
update
"
request_type
=
"
creation
"
if
created
else
"
update
"
...
...
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