views:

107

answers:

2

I'm using django-notification to allow my users to opt out of certain alerts I generate in my web-application.

By default when I create a new notice type it is enabled rather than disabled In the users notification interface (checked)

I'd like to make some alerts opt-in rather than the default of opt out. I've looked through the docs and been unable to see a way to do this, has anyone else managed to accomplish this?

+2  A: 

Its automatically set based on the 'default' column in the type itself, by default e-mail is a sensitivity of 2, so if you set the default to your new notice type default '1' it will no longer set it on by default for your users, the default when creating new notice types is '2' which would allow it to be sent to everyone.

sontek
Hi Sontek - I'm not entirely clear on how to implement this - does that mean I that at the time I create the new notification type I can specifically specify the default as 1 - so some are enabled and some are not? I currently create notices once with a line such as:notification.create_notice_type("moderation_messages", "Messages from moderators", "Email notification when someone flags one of your posts")
Tristan
Sontek - I see in the Django admin interface I can click on one of the notice types I have created and I am shown its default of "2" - However if I edit that and change it to "1" it doesn't change on any of my users notification pages.
Tristan
Looking at the code thats the only way it could work... Inside NoticeType model:# by default only on for media with sensitivity less than or equal to this number --> default = models.IntegerField(_('default'))and the default:# how spam-sensitive is the medium NOTICE_MEDIA_DEFAULTS = { "1": 2 # email }and in the get_notification_setting method:default = (NOTICE_MEDIA_DEFAULTS[medium] <= notice_type.default)so NOTICE_MEDIA_DEFAULTS[medium] = 2if your notice_type.default is 12 <= 1 = false, so default selection = false.
sontek
The only way this will not work is if the user already has defined some settings, in which case its already stored in the database that they want it to send, so you will have to update the db to set it to false for all users that already have it defined, but it will work just fine for new users/users who haven't defined an option already.
sontek
Thank you very much for taking the time to explain this sontek - Its worked well.
Tristan
A: 

Looking at the code, the determining factor to sending the notice is a comparison between the 'default' column and the sensitivity filter NOTICE_MEDIA_DEFAULTS[medium].

Does this work

from notification import models as notification

notification.create_notice_type("friends_invite", "Invitation Received", "you have received an invitation", default=0)
czarchaic
This is what I told him to do, ^_^
sontek
czarchaic - thank you very much for taking the time to answer this, you were right but I accepted sonteks answer as he got their first, but again, I do really appreciate your help.
Tristan