Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-wiki
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-wiki
Commits
da730eb9
Commit
da730eb9
authored
Jul 25, 2017
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move from init to models file.
parent
7df38983
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
44 deletions
+37
-44
django_notify/__init__.py
+0
-41
django_notify/models.py
+36
-1
wiki/plugins/notifications/models.py
+1
-2
No files found.
django_notify/__init__.py
View file @
da730eb9
from
django.contrib.contenttypes.models
import
ContentType
from
django.db.models
import
Model
from
django.utils.translation
import
ugettext
as
_
import
models
_disable_notifications
=
False
def
notify
(
message
,
key
,
target_object
=
None
,
url
=
None
):
"""
Notify subscribing users of a new event. Key can be any kind of string,
just make sure to reuse it where applicable! Object_id is some identifier
of an object, for instance if a user subscribes to a specific comment thread,
you could write:
notify("there was a response to your comment", "comment_response",
target_object=PostersObject,
url=reverse('comments:view', args=(PostersObject.id,)))
The below example notifies everyone subscribing to the "new_comments" key
with the message "New comment posted".
notify("New comment posted", "new_comments")
"""
if
_disable_notifications
:
return
0
if
target_object
:
if
not
isinstance
(
target_object
,
Model
):
raise
TypeError
(
_
(
u"You supplied a target_object that's not an instance of a django Model."
))
object_id
=
target_object
.
id
else
:
object_id
=
None
objects
=
models
.
Notification
.
create_notifications
(
key
,
object_id
=
object_id
,
message
=
message
,
url
=
url
)
return
len
(
objects
)
\ No newline at end of file
django_notify/models.py
View file @
da730eb9
# -*- coding: utf-8 -*-
from
django.db
import
models
from
django.db.models
import
Q
from
django.db.models
import
Q
,
Model
from
django.contrib.auth.models
import
User
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -8,6 +8,8 @@ from django.contrib.contenttypes.models import ContentType
from
django_notify
import
settings
_disable_notifications
=
False
class
NotificationType
(
models
.
Model
):
"""
Notification types are added on-the-fly by the
...
...
@@ -105,3 +107,36 @@ class Notification(models.Model):
db_table
=
settings
.
DB_TABLE_PREFIX
+
'_notification'
verbose_name
=
_
(
u'notification'
)
verbose_name_plural
=
_
(
u'notifications'
)
def
notify
(
message
,
key
,
target_object
=
None
,
url
=
None
):
"""
Notify subscribing users of a new event. Key can be any kind of string,
just make sure to reuse it where applicable! Object_id is some identifier
of an object, for instance if a user subscribes to a specific comment thread,
you could write:
notify("there was a response to your comment", "comment_response",
target_object=PostersObject,
url=reverse('comments:view', args=(PostersObject.id,)))
The below example notifies everyone subscribing to the "new_comments" key
with the message "New comment posted".
notify("New comment posted", "new_comments")
"""
if
_disable_notifications
:
return
0
if
target_object
:
if
not
isinstance
(
target_object
,
Model
):
raise
TypeError
(
_
(
u"You supplied a target_object that's not an instance of a django Model."
))
object_id
=
target_object
.
id
else
:
object_id
=
None
objects
=
Notification
.
create_notifications
(
key
,
object_id
=
object_id
,
message
=
message
,
url
=
url
)
return
len
(
objects
)
wiki/plugins/notifications/models.py
View file @
da730eb9
...
...
@@ -3,8 +3,7 @@ from django.core.urlresolvers import reverse
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.db.models
import
signals
from
django_notify
import
notify
from
django_notify.models
import
Subscription
from
django_notify.models
import
notify
,
Subscription
from
wiki
import
models
as
wiki_models
from
wiki.models.pluginbase
import
ArticlePlugin
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment