# HG changeset patch # User reno # Date 1259585177 -3600 # Node ID f69ff46d324099ff299afa6dce2177a8f6fddd5d # Parent 7b8167c4aa6f457d695feb66fd35d04dc3518a79 various notification changes diff -r 7b8167c4aa6f -r f69ff46d3240 src/cm/client.py --- a/src/cm/client.py Thu Nov 26 12:03:53 2009 +0100 +++ b/src/cm/client.py Mon Nov 30 13:46:17 2009 +0100 @@ -208,6 +208,21 @@ ret['msg'] = _(u'comment saved') return ret +# DIRTY : this function has no error check but anyway errors are not listened to client side +@has_perm_on_text("can_create_comment") +def own_notify(request, key): + email_or_user = None if request.user.is_anonymous() else request.user + if not email_or_user : + email_or_user = request.POST.get('email', None) + if email_or_user : + email_or_user = email_or_user.lower().strip() + + text = Text.objects.get(key=key) + Notification.objects.set_notification(text=None, type='own', active=True, email_or_user=email_or_user) + ret = HttpResponse() + ret.status_code = 200 + return ret + @has_perm_on_text("can_create_comment") def add_comment(request, key): # if edit_comment_id : # @@ -240,6 +255,18 @@ comment_state = 'approved' if text_version.mod_posteriori else 'pending' comment = Comment.objects.create(state=comment_state, text_version=text_version, user=user, name=name, email=email, title=title, content=content, content_html=content_html, tags = tags, start_wrapper = start_wrapper, end_wrapper = end_wrapper, start_offset = start_offset, end_offset = end_offset, reply_to=reply_to) + ask_for_notification = True + if user : + workspace_notify_count = Notification.objects.filter(text=None,type='workspace',user=user, active=True).count() + text_notify_count = Notification.objects.filter(text=text,type='text',user=user, active=True).count() + if workspace_notify_count > 0 or text_notify_count > 0 : + ask_for_notification = False + + if ask_for_notification : + ask_for_notification = ( None == Notification.objects.get_notifications(text=None, type='own', email_or_user=(user if user else email))) + ret['ask_for_notification'] = ask_for_notification + ret['email'] = '' if user else email + if text_version.mod_posteriori or has_perm(request, 'can_view_unapproved_comment', text=text) : ret['comment'] = comment ret['msg'] = _(u"comment saved") @@ -247,7 +274,7 @@ ret['msg'] = _(u"comment saved, it is being held for moderation") if AUTO_CONTRIB_REGISTER: - Notification.objects.set_notification_to_own_discussions(text=text, email_or_user=user or email) + Notification.objects.set_notification(text=text, type='own', active=True, email_or_user=user or email) register_activity(request, "comment_created", text, comment) return ret diff -r 7b8167c4aa6f -r f69ff46d3240 src/cm/media/js/client/c_sync.js --- a/src/cm/media/js/client/c_sync.js Thu Nov 26 12:03:53 2009 +0100 +++ b/src/cm/media/js/client/c_sync.js Mon Nov 30 13:46:17 2009 +0100 @@ -124,6 +124,21 @@ else if (isReply()) this._hideNewReplyForm() ; + if ("ask_for_notification" in ret) { + if (ret['ask_for_notification']) { + // TODO ask for notification ...or use AUTO_CONTRIB ? + parent.f_yesNoDialog(gettext("Do you wan to subscribe to all replies notifications in discussions where you have participated?"), gettext("Warning"), null, null, null, + function() { // special case : no waiting for the return, no error check, nothing ! + var cfg = { + method: "POST", + data: urlEncode({'fun':'ownNotify', 'key':sv_key, 'email':ret['email']}) + } ; + CY.io(sv_client_url, cfg); + }, this, null) ; + } + } + + if ("comment" in ret) { // won't be when add with a priori moderation var comment = ret['comment'] ; diff -r 7b8167c4aa6f -r f69ff46d3240 src/cm/models.py --- a/src/cm/models.py Thu Nov 26 12:03:53 2009 +0100 +++ b/src/cm/models.py Mon Nov 30 13:46:17 2009 +0100 @@ -382,39 +382,30 @@ objects = AttachmentManager() class NotificationManager(KeyManager): - def create_notification(self, text, type, email_or_user): - prev_notification = self.get_notification_to_own_discussions(text, type, email_or_user) - if not prev_notification: - notification = self.create(text=text, type=type) - notification.set_email_or_user(email_or_user) - return notification - else: - return prev_notification + def create_notification(self, text, type, active, email_or_user): + notification = self.create(text=text, type=type, active=active) + notification.set_email_or_user(email_or_user) + return notification - def get_notification_to_own_discussions(self, text, type, email_or_user): + def get_notifications(self, text, type, email_or_user): if isinstance(email_or_user,unicode): prev_notifications = Notification.objects.filter(text=text, type=type, email=email_or_user) else: prev_notifications = Notification.objects.filter(text=text, type=type, user=email_or_user) + if prev_notifications: return prev_notifications[0] else: return None - def set_notification_to_own_discussions(self, text, email_or_user, active=True): - if active: - notification = self.create_notification(text, 'own', email_or_user) - if not notification.active: - notification.active = True - notification.save() - else: - notification = self.create_notification(text, 'own', email_or_user) - notification.active = False + def set_notification(self, text, type, active, email_or_user): + notification = self.get_notifications(text, type, email_or_user) + if notification == None : + self.create_notification(text, type, active, email_or_user) + else : + notification.active = active notification.save() - def subscribe_to_own_text(self, text, user): - return self.create_notification(text, None, user) - class Notification(KeyModel, AuthorModel): text = models.ForeignKey(Text, null=True, blank=True) type = models.CharField(max_length=30, null=True, blank=True) diff -r 7b8167c4aa6f -r f69ff46d3240 src/cm/templates/site/notifications.html --- a/src/cm/templates/site/notifications.html Thu Nov 26 12:03:53 2009 +0100 +++ b/src/cm/templates/site/notifications.html Mon Nov 30 13:46:17 2009 +0100 @@ -52,32 +52,35 @@ {% endif %}

{% blocktrans %}Email notifications{% endblocktrans %}

- -   +
+   {% blocktrans %}Subscribe to workspace notifications{% endblocktrans %} -
-   - {% blocktrans %}Subscribe to all comments/replies notifications in discussions where you have participated{% endblocktrans %} - +
+
+   + {% blocktrans %}Subscribe to all replies notifications in discussions where you have participated{% endblocktrans %} +
diff -r 7b8167c4aa6f -r f69ff46d3240 src/cm/templates/site/text_notifications.html --- a/src/cm/templates/site/text_notifications.html Thu Nov 26 12:03:53 2009 +0100 +++ b/src/cm/templates/site/text_notifications.html Mon Nov 30 13:46:17 2009 +0100 @@ -55,18 +55,26 @@ {% endif %}

{% blocktrans %}Email notifications{% endblocktrans %}

- -   - {% blocktrans %}Subscribe to all text notifications{% endblocktrans %} - +
+ {% if workspace_notify_check %} + {% blocktrans %}You will receive text notifications because you subscribed to notifications at the workspace level{% endblocktrans %} + {% else %} +   + {% blocktrans %}Subscribe to all text notifications{% endblocktrans %} + {% endif %} +
diff -r 7b8167c4aa6f -r f69ff46d3240 src/cm/views/notifications.py --- a/src/cm/views/notifications.py Thu Nov 26 12:03:53 2009 +0100 +++ b/src/cm/views/notifications.py Mon Nov 30 13:46:17 2009 +0100 @@ -19,8 +19,9 @@ @login_required def notifications(request): - notify_check = Notification.objects.filter(text=None,type=None,user=request.user, active=True).count() - own_check = Notification.objects.filter(text=None,type='own',user=request.user, active=True).count() + workspace_notify_check = Notification.objects.filter(text=None,type='workspace',user=request.user, active=True).count() + own_notify_check = Notification.objects.filter(text=None,type='own',user=request.user, active=True).count() + if request.method == 'POST': if 'activate' in request.POST: Configuration.objects.set_key('private_feed_key', generate_key()) @@ -28,22 +29,15 @@ if 'reset' in request.POST: Configuration.objects.set_key('private_feed_key', generate_key()) display_message(request, _(u"Private feed reseted.")) - if request.POST.get('notify_check',None) == u'true': - if not notify_check: - notification = Notification.objects.create_notification(text=None, type=None, email_or_user=request.user) - # ajax display_message(request, _(u"Notifications activated.")) - elif request.POST.get('notify_check',None) == u'false': - Notification.objects.filter(text=None,type=None,user=request.user).delete() - notify_check = False - - if request.POST.get('own_check',None) == u'true': - Notification.objects.set_notification_to_own_discussions(text=None,email_or_user=request.user, active=True) - elif request.POST.get('own_check',None) == u'false': - Notification.objects.set_notification_to_own_discussions(text=None,email_or_user=request.user, active=False) - own_check = False + if request.POST.get('notif_id',None): + notif_id = request.POST.get('notif_id') + notif_type = 'own' if notif_id == 'own_notify_check' else 'workspace' + notif_val = request.POST.get(notif_id,None) + if notif_val != None : + Notification.objects.set_notification(text=None, type=notif_type, active=(notif_val == 'true'), email_or_user=request.user) - return render_to_response('site/notifications.html', {'notify_check':notify_check, - 'own_check' :own_check, + return render_to_response('site/notifications.html', {'workspace_notify_check':workspace_notify_check, + 'own_notify_check' :own_notify_check, }, context_instance=RequestContext(request)) @@ -73,9 +67,8 @@ from cm.security import user_has_perm # import here! anonymous_can_view_text = user_has_perm(None, 'can_view_text', text=text) - own_check = Notification.objects.filter(text=text,type='own',user=user).count() - all_check = Notification.objects.filter(text=text,type=None,user=user).count() - + text_notify_check = Notification.objects.filter(text=text,type='text',user=user, active=True).count() + workspace_notify_check = Notification.objects.filter(text=None,type='workspace',user=user, active=True).count() embed_code = '