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
+
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()
#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')
{{ form.notify_reply_to_comments }}{% trans "Notify me when someone replies to one of my comments on any post using the <pre>@username</pre> notation" %}\r
</td>\r
</tr>\r
+ <tr>\r
+ <td>\r
+ {{ form.send_digest }}{% trans "Send me the daily digest with information about the site activity" %}\r
+ </td>\r
+ </tr>\r
</table>\r
<div class="submit-row">\r
<input type="submit" class="submit" name="save" value="{% trans "Update" %}"/>\r
<input type="submit" class="submit" name="notswitch" value="{% trans "Start notifications" %}"/> \r
{% endif %}\r
</div>\r
+ {{ form.user }}\r
</form>\r
</div>\r
{% endblock %}\r
\r
@user_view('users/subscriptions.html', 'subscriptions', _('subscription settings'), _('subscriptions'), True, tabbed=False)\r
def user_subscriptions(request, user):\r
- if request.method == 'POST':\r
- form = SubscriptionSettingsForm(request.POST)\r
+ if request.method == 'POST': \r
+ form = SubscriptionSettingsForm(data=request.POST, instance=user.subscription_settings)\r
\r
- if 'notswitch' in request.POST:\r
- user.subscription_settings.enable_notifications = not user.subscription_settings.enable_notifications\r
- user.subscription_settings.save()\r
+ if form.is_valid():\r
+ if form.cleaned_data['user'] != user.id:\r
+ return HttpResponseUnauthorized(request)\r
\r
- if user.subscription_settings.enable_notifications:\r
- request.user.message_set.create(message=_('Notifications are now enabled'))\r
- else:\r
- request.user.message_set.create(message=_('Notifications are now disabled'))\r
+ if 'notswitch' in request.POST:\r
+ user.subscription_settings.enable_notifications = not user.subscription_settings.enable_notifications\r
+ user.subscription_settings.save()\r
\r
- form.is_valid()\r
- for k, v in form.cleaned_data.items():\r
- setattr(user.subscription_settings, k, v)\r
+ if user.subscription_settings.enable_notifications:\r
+ request.user.message_set.create(message=_('Notifications are now enabled'))\r
+ else:\r
+ request.user.message_set.create(message=_('Notifications are now disabled'))\r
\r
- user.subscription_settings.save()\r
- request.user.message_set.create(message=_('New subscription settings are now saved'))\r
+ form.save()\r
+ request.user.message_set.create(message=_('New subscription settings are now saved'))\r
+ else:\r
+ print form.errors\r
else:\r
- form = SubscriptionSettingsForm(user.subscription_settings.__dict__)\r
+ form = SubscriptionSettingsForm(instance=user.subscription_settings)\r
\r
notificatons_on = user.subscription_settings.enable_notifications\r
\r