forked from jtauber-archive/django-notification
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow notice_setting_for_user to be overriden
- Loading branch information
Showing
6 changed files
with
60 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from django.core.exceptions import ObjectDoesNotExist | ||
|
||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from .conf import settings | ||
from .utils import load_media_defaults | ||
|
||
|
||
class DefaultHookSet(object): | ||
|
||
def notice_setting_for_user(self, user, notice_type, medium, scoping=None): | ||
kwargs = { | ||
"notice_type": notice_type, | ||
"medium": medium | ||
} | ||
if scoping: | ||
kwargs.update({ | ||
"scoping_content_type": ContentType.objects.get_for_model(scoping), | ||
"scoping_object_id": scoping.pk | ||
}) | ||
else: | ||
kwargs.update({ | ||
"scoping_content_type__isnull": True, | ||
"scoping_object_id__isnull": True | ||
}) | ||
try: | ||
return user.noticesetting_set.get(**kwargs) | ||
except ObjectDoesNotExist: | ||
_, NOTICE_MEDIA_DEFAULTS = load_media_defaults() | ||
if scoping is None: | ||
kwargs.pop("scoping_content_type__isnull") | ||
kwargs.pop("scoping_object_id__isnull") | ||
kwargs.update({ | ||
"scoping_content_type": None, | ||
"scoping_object_id": None | ||
}) | ||
default = (NOTICE_MEDIA_DEFAULTS[medium] <= notice_type.default) | ||
kwargs.update({"send": default}) | ||
setting = user.noticesetting_set.create(**kwargs) | ||
return setting | ||
|
||
|
||
class HookProxy(object): | ||
|
||
def __getattr__(self, attr): | ||
return getattr(settings.PINAX_NOTIFICATIONS_HOOKSET, attr) | ||
|
||
|
||
hookset = HookProxy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters