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
decentral1se
djangoldp-notification
Commits
71503c0e
Commit
71503c0e
authored
5 years ago
by
Calum Mackervoy
Committed by
Jean-Baptiste Pasquier
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
All notification fix
parent
c1f320d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp_notification/models.py
+21
-1
21 additions, 1 deletion
djangoldp_notification/models.py
with
21 additions
and
1 deletion
djangoldp_notification/models.py
+
21
−
1
View file @
71503c0e
...
...
@@ -37,6 +37,19 @@ class Notification(Model):
def
__str__
(
self
):
return
'
{}
'
.
format
(
self
.
type
)
def
save
(
self
,
*
args
,
**
kwargs
):
# I cannot send a notification to myself
if
self
.
author
.
startswith
(
settings
.
SITE_URL
):
try
:
# author is a WebID.. convert to local representation
author
=
Model
.
resolve
(
self
.
author
.
replace
(
settings
.
SITE_URL
,
''
))[
1
]
except
NoReverseMatch
:
author
=
None
if
author
==
self
.
user
:
return
super
(
Notification
,
self
).
save
(
*
args
,
**
kwargs
)
class
Subscription
(
Model
):
object
=
models
.
URLField
()
...
...
@@ -61,6 +74,7 @@ def send_notification(sender, instance, created, **kwargs):
except
NoReverseMatch
:
return
# 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
)):
process
=
Thread
(
target
=
send_request
,
args
=
[
subscription
.
inbox
,
url_resource
,
instance
,
created
])
process
.
start
()
...
...
@@ -73,9 +87,11 @@ def send_request(target, object_iri, instance, created):
request_type
=
"
creation
"
if
created
else
"
update
"
try
:
# local inbox
if
target
.
startswith
(
settings
.
SITE_URL
):
user
=
Model
.
resolve_parent
(
target
.
replace
(
settings
.
SITE_URL
,
''
))
Notification
.
objects
.
create
(
user
=
user
,
object
=
object_iri
,
type
=
request_type
,
author
=
author
)
# external inbox
else
:
json
=
{
"
@context
"
:
settings
.
LDP_RDF_CONTEXT
,
...
...
@@ -92,14 +108,18 @@ def send_request(target, object_iri, instance, created):
@receiver
(
post_save
,
sender
=
Notification
)
def
send_email_on_notification
(
sender
,
instance
,
created
,
**
kwargs
):
if
created
and
instance
.
summary
and
settings
.
JABBER_DEFAULT_HOST
and
instance
.
user
.
email
:
# get author name, and store in who
try
:
# local author
if
instance
.
author
.
startswith
(
settings
.
SITE_URL
):
who
=
str
(
Model
.
resolve_id
(
instance
.
author
.
replace
(
settings
.
SITE_URL
,
''
)))
# external author
else
:
who
=
requests
.
get
(
instance
.
author
).
json
()[
'
name
'
]
except
:
who
=
"
Unknown Person
"
# get identifier for resource triggering notification, and store in where
try
:
if
instance
.
object
.
startswith
(
settings
.
SITE_URL
):
where
=
str
(
Model
.
resolve_id
(
instance
.
object
.
replace
(
settings
.
SITE_URL
,
''
)))
...
...
@@ -111,7 +131,7 @@ def send_email_on_notification(sender, instance, created, **kwargs):
if
who
==
where
:
where
=
"
has sent you a private message
"
else
:
where
=
"
mention you on
"
+
where
where
=
"
mention
ed
you on
"
+
where
html_message
=
loader
.
render_to_string
(
'
email.html
'
,
...
...
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