]> git.openstreetmap.org Git - osqa.git/commitdiff
Adds the option to enable/disable email digests and makes small tweak on the handling...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 1 Jul 2010 18:19:47 +0000 (18:19 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 1 Jul 2010 18:19:47 +0000 (18:19 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@483 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms/qanda.py
forum/management/commands/send_email_alerts.py
forum/models/user.py
forum/skins/default/templates/users/subscriptions.html
forum/views/users.py

index 39f9ca77cc774872d209ac1f6449503c9bc5839d..d482d01e190750db27dcf833bf205d734b420cef 100644 (file)
@@ -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']
                         
                     raise forms.ValidationError(_('this email has already been registered, please use another one'))
         return self.cleaned_data['email']
+        
 
 NOTIFICATION_CHOICES = (
     ('i', _('Instantly')),
 
 NOTIFICATION_CHOICES = (
     ('i', _('Instantly')),
-    ('d', _('Daily')),
-    ('w', _('Weekly')),
+    #('d', _('Daily')),
+    #('w', _('Weekly')),
     ('n', _('No notifications')),
 )
 
     ('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)
 
     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
+
 
 
index 4cdb2e1d35636fa27a5061539d83095db69a067c..1dd55ab99266c406483351143b5b6c859b3f5afd 100644 (file)
@@ -92,7 +92,7 @@ class Command(NoArgsCommand):
 
         EMAIL_DIGEST_CONTROL.set_value(digest_control)
 
 
         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()
         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()
index 8dd5ff9b829a954836aa69f4c2093c481ef0a081..f3a038993deba9762ce454313bb24cc89c4b5c4e 100644 (file)
@@ -425,7 +425,7 @@ class SubscriptionSettings(models.Model):
 
     #notify if
     member_joins = models.CharField(max_length=1, default='n')
 
     #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')
 
     new_question_watched_tags = models.CharField(max_length=1, default='i')
     subscribed_questions = models.CharField(max_length=1, default='i')
 
index 3b583ad7f3b9a79bdc0cc20251d69d2918e62365..a27c0feec6a71db7a5028b530e587953079fa0db 100644 (file)
                     {{ 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
                     {{ 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
         </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
             <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
     </form>\r
     </div>\r
 {% endblock %}\r
index 885dc9106ef1238aedbf024f54a9025a47a7b491..bf105c964cb50c5a390bb5b2d30353d8cc13ff50 100644 (file)
@@ -287,26 +287,28 @@ def user_favorites(request, user):
 \r
 @user_view('users/subscriptions.html', 'subscriptions', _('subscription settings'), _('subscriptions'), True, tabbed=False)\r
 def user_subscriptions(request, user):\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
 \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
 \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
 \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
 \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
     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
 \r
     notificatons_on = user.subscription_settings.enable_notifications\r
 \r