From 0f24e95796d0c5c109de8e757e10b5ae9a22c98b Mon Sep 17 00:00:00 2001 From: fsantos Date: Thu, 24 Jan 2013 15:34:48 +0000 Subject: [PATCH] NOTIFICATION_UNCONFIGURABLE_MEDIA setting I created this setting to avoid users opting out of notifications coming from certain media (E.G. a logging backend) --- docs/settings.rst | 10 ++++++++++ notification/views.py | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 0f409d3b..ed6b5fce 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -20,6 +20,16 @@ NOTIFICATION_BACKENDS TODO: Describe usage. Look at Pinax +NOTIFICATION_UNCONFIGURABLE_MEDIA +--------------------------------- + +**Default**:: + + [] + +A list of backends (see above) which the user cannot configure using the `notifications_settings` view's form. + + DEFAULT_HTTP_PROTOCOL --------------------- diff --git a/notification/views.py b/notification/views.py index cc524f2a..0ecdd318 100644 --- a/notification/views.py +++ b/notification/views.py @@ -1,11 +1,13 @@ from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from django.template import RequestContext +from django.conf import settings from django.contrib.auth.decorators import login_required from notification.models import NoticeSetting, NoticeType, NOTICE_MEDIA +NOTIFICATION_UNCONFIGURABLE_MEDIA = getattr(settings, 'NOTIFICATION_UNCONFIGURABLE_MEDIA', []) @login_required def notice_settings(request): @@ -29,9 +31,18 @@ def notice_settings(request): """ notice_types = NoticeType.objects.all() settings_table = [] + + notice_media = [] + + for medium_id, medium_display in NOTICE_MEDIA: + if medium_display in NOTIFICATION_UNCONFIGURABLE_MEDIA: + continue + else: + notice_media.append((medium_id, medium_display)) + for notice_type in notice_types: settings_row = [] - for medium_id, medium_display in NOTICE_MEDIA: + for medium_id, medium_display in notice_media: form_label = "%s_%s" % (notice_type.label, medium_id) setting = NoticeSetting.for_user(request.user, notice_type, medium_id) if request.method == "POST": @@ -51,7 +62,7 @@ def notice_settings(request): return HttpResponseRedirect(next_page) notice_settings = { - "column_headers": [medium_display for medium_id, medium_display in NOTICE_MEDIA], + "column_headers": [medium_display for medium_id, medium_display in notice_media], "rows": settings_table, }