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
OpenEdx
django-wiki
Commits
64a20e8a
Commit
64a20e8a
authored
Aug 06, 2012
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding notifications for article edits and creations
parent
700e4662
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
79 additions
and
21 deletions
+79
-21
django_notify/__init__.py
+2
-3
django_notify/models.py
+21
-7
setup.py
+1
-0
wiki/core/plugins_load.py
+1
-2
wiki/core/plugins_registry.py
+7
-0
wiki/forms.py
+1
-0
wiki/plugins/notifications/forms.py
+4
-3
wiki/plugins/notifications/models.py
+41
-3
wiki/plugins/notifications/wiki_plugin.py
+1
-3
No files found.
django_notify/__init__.py
View file @
64a20e8a
...
...
@@ -26,12 +26,10 @@ def notify(message, key, target_object=None, url=None):
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
content_type
=
ContentType
.
get_object_for_this_type
(
target_object
)
else
:
object_id
=
None
content_type
=
None
objects
=
models
.
Notification
.
create_notifications
(
key
,
object_id
=
object_id
,
content_type
=
content_type
)
message
=
message
,
url
=
url
)
return
len
(
objects
)
\ No newline at end of file
django_notify/models.py
View file @
64a20e8a
# -*- coding: utf-8 -*-
from
django.db
import
models
from
django.db.models
import
Q
from
django.contrib.auth.models
import
User
...
...
@@ -15,12 +16,18 @@ class NotificationType(models.Model):
blank
=
True
,
null
=
True
)
content_type
=
models
.
ForeignKey
(
ContentType
,
blank
=
True
,
null
=
True
)
def
__unicode__
(
self
):
return
self
.
key
class
Settings
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
)
interval
=
models
.
SmallIntegerField
(
choices
=
settings
.
INTERVALS
,
verbose_name
=
_
(
u'interval'
),
default
=
settings
.
INTERVALS_DEFAULT
)
def
__unicode__
(
self
):
return
self
.
user
class
Subscription
(
models
.
Model
):
settings
=
models
.
ForeignKey
(
Settings
)
...
...
@@ -29,6 +36,9 @@ class Subscription(models.Model):
help_text
=
_
(
u'Leave this blank to subscribe to any kind of object'
))
send_emails
=
models
.
BooleanField
(
default
=
True
)
def
__unicode__
(
self
):
return
_
(
"Subscription for:
%
s"
)
%
self
.
settings
.
user
class
Notification
(
models
.
Model
):
subscription
=
models
.
ForeignKey
(
Subscription
)
...
...
@@ -43,15 +53,20 @@ class Notification(models.Model):
if
not
key
or
not
isinstance
(
key
,
str
):
raise
KeyError
(
'No notification key (string) specified.'
)
notification_type
=
NotificationType
.
objects
.
get_or_create
(
key
=
key
)
object_id
=
kwargs
.
pop
(
'object_id'
,
None
)
objects_created
=
[]
for
subscription
in
Subscription
.
objects
.
filter
(
Q
(
key
=
key
)
|
Q
(
key
=
None
),
notification_type
=
notification_type
,
):
subscriptions
=
Subscription
.
objects
.
filter
(
Q
(
notification_type__key
=
key
)
|
Q
(
notification_type__key
=
None
),)
if
object_id
:
subscriptions
=
subscriptions
.
filter
(
Q
(
object_id
=
object_id
)
|
Q
(
object_id
=
None
))
for
subscription
in
subscriptions
:
objects_created
.
append
(
cls
.
objects
.
create
(
subscription
=
subscription
,
**
kwargs
)
)
return
objects_created
\ No newline at end of file
def
__unicode__
(
self
):
return
"
%
s:
%
s"
%
(
self
.
subscription
.
settings
.
user
,
self
.
message
)
setup.py
View file @
64a20e8a
# -*- coding: utf-8 -*-
import
os
from
setuptools
import
setup
,
find_packages
...
...
wiki/core/plugins_load.py
View file @
64a20e8a
...
...
@@ -35,5 +35,4 @@ def load(modname, verbose=False, failfast=False):
get_module
(
app
,
modname
,
verbose
,
failfast
)
def
load_wiki_plugins
():
load
(
'wiki_plugin'
)
load
(
'wiki_plugin'
,
verbose
=
False
)
wiki/core/plugins_registry.py
View file @
64a20e8a
from
django.utils.importlib
import
import_module
_cache
=
{}
_settings_forms
=
[]
...
...
@@ -17,4 +18,10 @@ def register(PluginClass):
settings_form
=
getattr
(
PluginClass
,
'settings_form'
,
None
)
if
settings_form
:
if
isinstance
(
settings_form
,
basestring
):
klassname
=
settings_form
.
split
(
"."
)[
-
1
]
modulename
=
"."
.
join
(
settings_form
.
split
(
"."
)[:
-
1
])
form_module
=
import_module
(
modulename
)
settings_form
=
getattr
(
form_module
,
klassname
)
_settings_forms
.
append
(
settings_form
)
wiki/forms.py
View file @
64a20e8a
# -*- coding: utf-8 -*-
from
django
import
forms
from
django.utils.translation
import
ugettext
as
_
from
itertools
import
chain
...
...
wiki/plugins/notifications/forms.py
View file @
64a20e8a
from
django
import
forms
from
django.utils.translation
import
ugettext
as
_
import
model
s
import
setting
s
from
django_notify.models
import
Settings
,
NotificationType
from
django.contrib.contenttypes.models
import
ContentType
from
django.utils.safestring
import
mark_safe
...
...
@@ -14,12 +14,12 @@ class SubscriptionForm(forms.Form):
settings_write_access
=
False
def
__init__
(
self
,
article
,
user
,
*
args
,
**
kwargs
):
import
models
self
.
article
=
article
self
.
user
=
user
initial
=
kwargs
.
pop
(
'initial'
,
None
)
self
.
settings
=
Settings
.
objects
.
get_or_create
(
user
=
user
,)[
0
]
self
.
notification_type
=
NotificationType
.
objects
.
get_or_create
(
key
=
models
.
NOTIFICATION_
ARTICLE_EDIT
,
self
.
notification_type
=
NotificationType
.
objects
.
get_or_create
(
key
=
settings
.
ARTICLE_EDIT
,
content_type
=
ContentType
.
objects
.
get_for_model
(
article
))[
0
]
self
.
edit_notifications
=
models
.
ArticleSubscription
.
objects
.
filter
(
settings
=
self
.
settings
,
article
=
article
,
...
...
@@ -41,6 +41,7 @@ class SubscriptionForm(forms.Form):
return
_
(
'Your notification settings were unchanged, so nothing saved.'
)
def
save
(
self
,
*
args
,
**
kwargs
):
import
models
cd
=
self
.
cleaned_data
if
not
self
.
changed_data
:
return
...
...
wiki/plugins/notifications/models.py
View file @
64a20e8a
# -*- coding: utf-8 -*-
from
django_notify.models
import
Subscription
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.db.models
import
signals
from
wiki
.models
import
pluginbase
from
wiki
import
models
as
wiki_models
NOTIFICATION_ARTICLE_EDIT
=
'article_edit'
from
django_notify
import
notify
from
django.core.urlresolvers
import
reverse
class
ArticleSubscription
(
pluginbase
.
ArticlePlugin
,
Subscription
):
import
settings
class
ArticleSubscription
(
wiki_models
.
pluginbase
.
ArticlePlugin
,
Subscription
):
def
__unicode__
(
self
):
return
(
_
(
u"
%(user)
s subscribing to
%(article)
s (
%(type)
s)"
)
%
{
'user'
:
self
.
settings
.
user
.
username
,
'article'
:
self
.
article
.
current_revision
.
title
,
'type'
:
self
.
notification_type
.
label
})
def
post_article_save
(
instance
,
**
kwargs
):
if
kwargs
.
get
(
'created'
,
False
):
urlpath
=
wiki_models
.
URLPath
.
objects
.
filter
(
articles
=
instance
)
if
urlpath
:
url
=
reverse
(
'wiki:get_url'
,
urlpath
.
path
)
else
:
url
=
None
notify
(
_
(
u'New article created:
%
s'
)
%
instance
.
title
,
settings
.
ARTICLE_CREATE
,
target_object
=
instance
.
id
,
url
=
url
)
def
post_article_revision_save
(
instance
,
**
kwargs
):
if
kwargs
.
get
(
'created'
,
False
):
try
:
urlpath
=
wiki_models
.
URLPath
.
objects
.
get
(
articles
=
instance
.
article
)
url
=
reverse
(
'wiki:get_url'
,
args
=
(
urlpath
.
path
,))
except
wiki_models
.
URLPath
.
DoesNotExist
:
url
=
None
notify
(
_
(
u'Article modified:
%
s'
)
%
instance
.
title
,
settings
.
ARTICLE_EDIT
,
target_object
=
instance
.
article
,
url
=
url
)
# Create notifications when new articles are saved. We do NOT care
# about Article objects that are just modified, because many properties
# are modified without any notifications necessary!
signals
.
post_save
.
connect
(
post_article_save
,
sender
=
wiki_models
.
Article
,)
# Whenever a new revision is created, we notifý users that an article
# was edited
signals
.
post_save
.
connect
(
post_article_revision_save
,
sender
=
wiki_models
.
ArticleRevision
,)
# TODO: We should notify users when the current_revision of an article is
# changed...
wiki/plugins/notifications/wiki_plugin.py
View file @
64a20e8a
from
wiki.core
import
plugins_registry
import
forms
class
NotifyPlugin
(
plugins_registry
.
BasePlugin
):
settings_form
=
forms
.
SubscriptionForm
settings_form
=
'wiki.plugins.notifications.forms.SubscriptionForm'
def
__init__
(
self
):
#print "I WAS LOADED!"
...
...
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