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
4800d5b6
Commit
4800d5b6
authored
Aug 13, 2012
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decorator for muting notifications + Issue #11 fix
parent
2eae064d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
6 deletions
+22
-6
django_notify/__init__.py
+5
-0
django_notify/decorators.py
+12
-0
django_notify/models.py
+4
-4
django_notify/settings.py
+1
-2
No files found.
django_notify/__init__.py
View file @
4800d5b6
...
...
@@ -4,6 +4,8 @@ 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,
...
...
@@ -22,6 +24,9 @@ def notify(message, key, target_object=None, url=None):
"""
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."
))
...
...
django_notify/decorators.py
View file @
4800d5b6
...
...
@@ -3,6 +3,17 @@ from django.utils import simplejson as json
from
django.http
import
HttpResponse
from
django.contrib.auth.decorators
import
login_required
import
django_notify
def
disable_notify
(
func
):
"""Disable notifications within a """
def
wrap
(
request
,
*
args
,
**
kwargs
):
django_notify
.
_disable_notifications
=
True
response
=
func
(
request
,
*
args
,
**
kwargs
)
django_notify
.
_disable_notifications
=
False
return
response
return
wrap
def
login_required_ajax
(
func
):
"""Similar to login_required. But if the request is an ajax request, then
it returns an error in json with a 403 status code."""
...
...
@@ -25,3 +36,4 @@ def json_view(func):
response
.
write
(
data
)
return
response
return
wrap
django_notify/models.py
View file @
4800d5b6
...
...
@@ -22,7 +22,7 @@ class NotificationType(models.Model):
return
self
.
key
class
Meta
:
db_table
space
=
settings
.
DB_TABLESPACE
db_table
=
settings
.
DB_TABLE_PREFIX
+
'_notificationtype'
verbose_name
=
_
(
u'type'
)
verbose_name_plural
=
_
(
u'types'
)
...
...
@@ -36,7 +36,7 @@ class Settings(models.Model):
return
_
(
u"Settings for
%
s"
)
%
self
.
user
.
username
class
Meta
:
db_table
space
=
settings
.
DB_TABLESPACE
db_table
=
settings
.
DB_TABLE_PREFIX
+
'_settings'
verbose_name
=
_
(
u'settings'
)
verbose_name_plural
=
_
(
u'settings'
)
...
...
@@ -52,7 +52,7 @@ class Subscription(models.Model):
return
_
(
"Subscription for:
%
s"
)
%
str
(
self
.
settings
.
user
.
username
)
class
Meta
:
db_table
space
=
settings
.
DB_TABLESPACE
db_table
=
settings
.
DB_TABLE_PREFIX
+
'_subscription'
verbose_name
=
_
(
u'subscription'
)
verbose_name_plural
=
_
(
u'subscriptions'
)
...
...
@@ -97,6 +97,6 @@ class Notification(models.Model):
return
"
%
s:
%
s"
%
(
str
(
self
.
subscription
.
settings
.
user
),
self
.
message
)
class
Meta
:
db_table
space
=
settings
.
DB_TABLESPACE
db_table
=
settings
.
DB_TABLE_PREFIX
+
'_notification'
verbose_name
=
_
(
u'notification'
)
verbose_name_plural
=
_
(
u'notifications'
)
django_notify/settings.py
View file @
4800d5b6
...
...
@@ -2,8 +2,7 @@ from django.conf import settings as django_settings
_
=
lambda
x
:
x
# don't change this :)
DB_TABLESPACE
=
'notify'
DB_TABLE_PREFIX
=
'notify'
# You need to switch this setting on, otherwise nothing will happen :)
ENABLED
=
getattr
(
django_settings
,
"NOTIFY_ENABLED"
,
True
)
...
...
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