From bfdaa85311e23a579470068e1c19e94e04a503b0 Mon Sep 17 00:00:00 2001 From: Adolfo Fitoria Date: Wed, 5 Oct 2011 11:49:34 -0300 Subject: Fixes issue 73: Added entries into livesettings, modified tests to make it work. --- askbot/conf/email.py | 87 ++++++++++++++++++++++++--- askbot/forms.py | 2 +- askbot/management/commands/add_askbot_user.py | 30 ++++----- askbot/models/__init__.py | 5 +- askbot/tests/email_alert_tests.py | 2 +- 5 files changed, 100 insertions(+), 26 deletions(-) diff --git a/askbot/conf/email.py b/askbot/conf/email.py index 5ef6b866..5402cad0 100644 --- a/askbot/conf/email.py +++ b/askbot/conf/email.py @@ -37,19 +37,92 @@ settings.register( ) ) +#settings.register( +# livesettings.StringValue( +# EMAIL, +# 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE', +# default='w', +# choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, +# description=_('Default news notification frequency'), +# help_text=_( +# 'This option currently defines default frequency ' +# 'of emailed updates in the following five categories: ' +# 'questions asked by user, answered by user, individually ' +# 'selected, entire forum (per person tag filter applies) ' +# 'and posts mentioning the user and comment responses' +# ) +# ) +#) + + +settings.register( + livesettings.StringValue( + EMAIL, + 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_Q_ALL', + default='w', + choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, + description=_('Default notification frequency all questions'), + help_text=_( + 'Option to define frequency of emailed updates for: ' + 'all questions.' + ) + ) +) + +settings.register( + livesettings.StringValue( + EMAIL, + 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_Q_ASK', + default='w', + choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, + description=_('Default notification frequency questions asked by the user'), + help_text=_( + 'Option to define frequency of emailed updates for: ' + 'Question asked by the user.' + ) + ) +) + +settings.register( + livesettings.StringValue( + EMAIL, + 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_Q_ANS', + default='w', + choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, + description=_('Default notification frequency questions answered by the user'), + help_text=_( + 'Option to define frequency of emailed updates for: ' + 'Question answered by the user.' + ) + ) +) + +settings.register( + livesettings.StringValue( + EMAIL, + 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_Q_SEL', + default='w', + choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, + description=_('Default notification frequency questions individually \ + selected by the user'), + help_text=_( + 'Option to define frequency of emailed updates for: ' + 'Question individually selected by the user.' + ) + ) +) + settings.register( livesettings.StringValue( EMAIL, - 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE', + 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_M_AND_C', default='w', choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, - description=_('Default news notification frequency'), + description=_('Default notification frequency for mentions \ + and comments'), help_text=_( - 'This option currently defines default frequency ' - 'of emailed updates in the following five categories: ' - 'questions asked by user, answered by user, individually ' - 'selected, entire forum (per person tag filter applies) ' - 'and posts mentioning the user and comment responses' + 'Option to define frequency of emailed updates for: ' + 'Mentions and comments.' ) ) ) diff --git a/askbot/forms.py b/askbot/forms.py index afef2cc5..b0517cce 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -962,7 +962,7 @@ class TagFilterSelectionForm(forms.ModelForm): class EmailFeedSettingField(forms.ChoiceField): def __init__(self, *arg, **kwarg): kwarg['choices'] = const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES - kwarg['initial'] = askbot_settings.DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE + #kwarg['initial'] = askbot_settings.DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE kwarg['widget'] = forms.RadioSelect super(EmailFeedSettingField, self).__init__(*arg, **kwarg) diff --git a/askbot/management/commands/add_askbot_user.py b/askbot/management/commands/add_askbot_user.py index 0b8fd02b..bac18a58 100644 --- a/askbot/management/commands/add_askbot_user.py +++ b/askbot/management/commands/add_askbot_user.py @@ -40,7 +40,7 @@ class Command(BaseCommand): action = 'store', type = 'str', dest = 'frequency', - default = 'w', + default = None, help = 'email subscription frequency (n - never, i - ' 'instant, d - daily, w - weekly, default - w)' ), @@ -62,22 +62,22 @@ class Command(BaseCommand): username = options['username'] frequency = options['frequency'] - if frequency not in ('i', 'd', 'w', 'n'): - raise CommandError( - 'value of --frequency must be one of: ' - 'i, d, w, n' - ) - user = models.User.objects.create_user(username, email) if password: user.set_password(password) user.save() subscription = {'subscribe': 'y'} - email_feeds_form = forms.SimpleEmailSubscribeForm( - subscription, - frequency = frequency - ) - if email_feeds_form.is_valid(): - email_feeds_form.save(user) - else: - raise CommandError('\n'.join(email_feeds_form.errors)) + if frequency in ('i', 'd', 'w', 'n'): + email_feeds_form = forms.SimpleEmailSubscribeForm( + subscription, + frequency = frequency + ) + if email_feeds_form.is_valid(): + email_feeds_form.save(user) + else: + raise CommandError('\n'.join(email_feeds_form.errors)) + elif frequency is not None: + raise CommandError( + 'value of --frequency must be one of: ' + 'i, d, w, n' + ) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 17723ce5..e1677d9f 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1452,12 +1452,13 @@ def user_add_missing_askbot_subscriptions(self): 'feed_type', flat = True ) missing_feed_types = set(need_feed_types) - set(have_feed_types) - frequency = askbot_settings.DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE for missing_feed_type in missing_feed_types: + attr_key = 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_%s' % missing_feed_type.upper() + freq = getattr(askbot_settings, attr_key) feed_setting = EmailFeedSetting( subscriber = self, feed_type = missing_feed_type, - frequency = frequency + frequency = freq ) feed_setting.save() diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py index 1fbe3bf5..dcea2e54 100644 --- a/askbot/tests/email_alert_tests.py +++ b/askbot/tests/email_alert_tests.py @@ -893,7 +893,7 @@ class EmailFeedSettingTests(utils.AskbotTestCase): self.assertEquals( feed.frequency, - askbot_settings.DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE + askbot_settings.DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_Q_ALL ) def test_missing_subscriptions_added_automatically(self): -- cgit v1.2.3-1-g7c22