From: hernani Date: Thu, 1 Jul 2010 18:19:47 +0000 (+0000) Subject: Adds the option to enable/disable email digests and makes small tweak on the handling... X-Git-Tag: live~651 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/3d835e01926aeec21f78df2012567cdd2f2f7f07?ds=inline Adds the option to enable/disable email digests and makes small tweak on the handling code. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@483 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/forms/qanda.py b/forum/forms/qanda.py index 39f9ca7..d482d01 100644 --- a/forum/forms/qanda.py +++ b/forum/forms/qanda.py @@ -266,30 +266,23 @@ class EditUserForm(forms.Form): raise forms.ValidationError(_('this email has already been registered, please use another one')) return self.cleaned_data['email'] + NOTIFICATION_CHOICES = ( ('i', _('Instantly')), - ('d', _('Daily')), - ('w', _('Weekly')), + #('d', _('Daily')), + #('w', _('Weekly')), ('n', _('No notifications')), ) -class SubscriptionSettingsForm(forms.Form): +class SubscriptionSettingsForm(forms.ModelForm): + user = forms.IntegerField(widget=forms.HiddenInput) member_joins = forms.ChoiceField(widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES) new_question = forms.ChoiceField(widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES) new_question_watched_tags = forms.ChoiceField(widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES) subscribed_questions = forms.ChoiceField(widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES) - all_questions = forms.BooleanField(required=False, initial=False) - all_questions_watched_tags = forms.BooleanField(required=False, initial=False) - questions_asked = forms.BooleanField(required=False, initial=False) - questions_answered = forms.BooleanField(required=False, initial=False) - questions_commented = forms.BooleanField(required=False, initial=False) - questions_viewed = forms.BooleanField(required=False, initial=False) - - notify_answers = forms.BooleanField(required=False, initial=False) - notify_reply_to_comments = forms.BooleanField(required=False, initial=False) - notify_comments_own_post = forms.BooleanField(required=False, initial=False) - notify_comments = forms.BooleanField(required=False, initial=False) - notify_accepted = forms.BooleanField(required=False, initial=False) + class Meta: + model = SubscriptionSettings + diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py index 4cdb2e1..1dd55ab 100644 --- a/forum/management/commands/send_email_alerts.py +++ b/forum/management/commands/send_email_alerts.py @@ -92,7 +92,7 @@ class Command(NoArgsCommand): EMAIL_DIGEST_CONTROL.set_value(digest_control) - users = User.objects.filter(subscription_settings__enable_notifications=True) + users = User.objects.filter(subscription_settings__enable_notifications=True, subscription_settings__send_digest=True) new_members = User.objects.filter(is_active=True, date_joined__gt=from_date).annotate(n_actions=models.Count('actions')).order_by('-n_actions') new_member_count = new_members.count() diff --git a/forum/models/user.py b/forum/models/user.py index 8dd5ff9..f3a0389 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -425,7 +425,7 @@ class SubscriptionSettings(models.Model): #notify if member_joins = models.CharField(max_length=1, default='n') - new_question = models.CharField(max_length=1, default='d') + new_question = models.CharField(max_length=1, default='n') new_question_watched_tags = models.CharField(max_length=1, default='i') subscribed_questions = models.CharField(max_length=1, default='i') diff --git a/forum/skins/default/templates/users/subscriptions.html b/forum/skins/default/templates/users/subscriptions.html index 3b583ad..a27c0fe 100644 --- a/forum/skins/default/templates/users/subscriptions.html +++ b/forum/skins/default/templates/users/subscriptions.html @@ -111,6 +111,11 @@ {{ form.notify_reply_to_comments }}{% trans "Notify me when someone replies to one of my comments on any post using the
@username
notation" %} + + + {{ form.send_digest }}{% trans "Send me the daily digest with information about the site activity" %} + +
@@ -120,6 +125,7 @@ {% endif %}
+ {{ form.user }} {% endblock %} diff --git a/forum/views/users.py b/forum/views/users.py index 885dc91..bf105c9 100644 --- a/forum/views/users.py +++ b/forum/views/users.py @@ -287,26 +287,28 @@ def user_favorites(request, user): @user_view('users/subscriptions.html', 'subscriptions', _('subscription settings'), _('subscriptions'), True, tabbed=False) def user_subscriptions(request, user): - if request.method == 'POST': - form = SubscriptionSettingsForm(request.POST) + if request.method == 'POST': + form = SubscriptionSettingsForm(data=request.POST, instance=user.subscription_settings) - if 'notswitch' in request.POST: - user.subscription_settings.enable_notifications = not user.subscription_settings.enable_notifications - user.subscription_settings.save() + if form.is_valid(): + if form.cleaned_data['user'] != user.id: + return HttpResponseUnauthorized(request) - if user.subscription_settings.enable_notifications: - request.user.message_set.create(message=_('Notifications are now enabled')) - else: - request.user.message_set.create(message=_('Notifications are now disabled')) + if 'notswitch' in request.POST: + user.subscription_settings.enable_notifications = not user.subscription_settings.enable_notifications + user.subscription_settings.save() - form.is_valid() - for k, v in form.cleaned_data.items(): - setattr(user.subscription_settings, k, v) + if user.subscription_settings.enable_notifications: + request.user.message_set.create(message=_('Notifications are now enabled')) + else: + request.user.message_set.create(message=_('Notifications are now disabled')) - user.subscription_settings.save() - request.user.message_set.create(message=_('New subscription settings are now saved')) + form.save() + request.user.message_set.create(message=_('New subscription settings are now saved')) + else: + print form.errors else: - form = SubscriptionSettingsForm(user.subscription_settings.__dict__) + form = SubscriptionSettingsForm(instance=user.subscription_settings) notificatons_on = user.subscription_settings.enable_notifications