--- 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
--- 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'] ;
--- 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)
--- 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 %}
<h2>{% blocktrans %}Email notifications{% endblocktrans %}</h2>
-
- <input type="checkbox" id="notify_check" class="check" name="notify-check" {% if notify_check %}checked="checked"{% endif %}/>
+ <div>
+ <input type="checkbox" id="workspace_notify_check" class="check" {% if workspace_notify_check %}checked="checked"{% endif %}/>
{% blocktrans %}Subscribe to workspace notifications{% endblocktrans %}
- <br />
- <input type="checkbox" id="own_check" class="check" name="commentsown-check" {% if own_check %}checked="checked"{% endif %}/>
- {% blocktrans %}Subscribe to all comments/replies notifications in discussions where you have participated{% endblocktrans %}
-
+ </div>
+ <div id="own_notify_check_container">
+ <input type="checkbox" id="own_notify_check" class="check" {% if own_notify_check %}checked="checked"{% endif %}/>
+ {% blocktrans %}Subscribe to all replies notifications in discussions where you have participated{% endblocktrans %}
+ </div>
<script type="text/javascript">
<!--
- $(function() {
- $(".check").click(function(){
- notify_check = $("#notify_check").attr('checked');
- own_check = $("#own_check").attr('checked');
-
- $.post('.',
- {
- 'notify_check':notify_check,
- 'own_check':own_check
- },
- function(data){
- // window.location = window.location;
- });
-
- });
-
- }) ;
+
+ $(function() {
+ adapt_own_check_visibility = function() {
+ if ($("#workspace_notify_check").attr('checked'))
+ $("#own_notify_check_container").hide() ;
+ else
+ $("#own_notify_check_container").show() ;
+ } ;
+ $(".check").click(function(){
+ checked = $(this).attr('checked');
+ id = $(this).attr('id') ;
+ post_data = {'notif_id': id} ;
+ post_data[id] = checked ;
+ $.post('.', post_data, function(data){});
+
+ adapt_own_check_visibility();
+ });
+ adapt_own_check_visibility() ;
+ }) ;
-->
</script>
--- 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 %}
<h2>{% blocktrans %}Email notifications{% endblocktrans %}</h2>
-
- <input type="checkbox" id="all_check" class="check" name="all-check" {% if all_check %}checked="checked"{% endif %}/>
- {% blocktrans %}Subscribe to all text notifications{% endblocktrans %}
-
+ <div>
+ {% if workspace_notify_check %}
+ {% blocktrans %}You will receive text notifications because you subscribed to notifications at the workspace level{% endblocktrans %}
+ {% else %}
+ <input type="checkbox" id="text_notify_check" class="check" {% if text_notify_check %}checked="checked"{% endif %}/>
+ {% blocktrans %}Subscribe to all text notifications{% endblocktrans %}
+ {% endif %}
+ </div>
<script type="text/javascript">
<!--
- $(function() {
- $(".check").click(function(){
- var all_check = $("#all_check").attr('checked');
- $.post('.',{'all_check':all_check},function(data){/* window.location = window.location;*/});
- });
-}) ;
+ $(function() {
+ $(".check").click(function(){
+ checked = $(this).attr('checked');
+ id = $(this).attr('id') ;
+ post_data = {'notif_id': id} ;
+ post_data[id] = checked ;
+ $.post('.', post_data, function(data){});
+ });
+
+ }) ;
-->
</script>
--- 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 = '<iframe frameborder="0" src="%s%s" style="height: 166px; width: 99.9%%; position: relative; top: 0px;">'%(settings.SITE_URL, reverse('text-view-comments-frame', args=[text.key]))
@@ -89,16 +82,16 @@
text.save()
display_message(request, _(u"Private notifications feed reseted."))
- if request.POST.get('all_check',None) == u'true':
- if not all_check:
- notification = Notification.objects.create_notification(text=text, type=None, email_or_user=user)
-
- if request.POST.get('all_check',None) == u'false':
- notification = Notification.objects.filter(text=text, type=None, user=user).delete()
+ if request.POST.get('notif_id',None):
+ notif_id = request.POST.get('notif_id')
+ notif_val = request.POST.get(notif_id,None)
+ if notif_val != None :
+ Notification.objects.set_notification(text=text, type='text', active=(notif_val == 'true'), email_or_user=request.user)
template_dict = {
'text' : text,
- 'all_check' : all_check,
+ 'workspace_notify_check' : workspace_notify_check,
+ 'text_notify_check' : text_notify_check,
'anonymous_can_view_text' : anonymous_can_view_text,
'embed_code': embed_code
}
--- a/src/cm/views/texts.py Thu Nov 26 12:03:53 2009 +0100
+++ b/src/cm/views/texts.py Mon Nov 30 13:46:17 2009 +0100
@@ -1,6 +1,6 @@
from cm.activity import register_activity
from cm.client import jsonize, get_filter_datas, edit_comment, remove_comment, \
- add_comment, RequestComplexEncoder, comments_thread
+ add_comment, RequestComplexEncoder, comments_thread, own_notify
from cm.cm_settings import NEW_TEXT_VERSION_ON_EDIT
from cm.diff import text_diff as _text_diff, text_history as inner_text_history, \
get_colors
@@ -228,6 +228,8 @@
text_version = text.get_latest_version()
if (text != None) :
+ if function_name == 'ownNotify' :
+ ret = own_notify(request=request, key=key)
if function_name in ('editComment', 'addComment', 'removeComment',) :
if function_name == 'editComment' :
ret = edit_comment(request=request, key=key, comment_key=request.POST['comment_key'])
@@ -239,12 +241,11 @@
ret['filterData'] = get_filter_datas(request, text_version, text)
#ret['tagCloud'] = get_tagcloud(key)
if ret :
- if type(ret) != HttpResponseRedirect :
+ if type(ret) != HttpResponseRedirect and type(ret) != HttpResponse:
ret = HttpResponse(simplejson.dumps(ret, cls=RequestComplexEncoder, request=request))
else :
- ret = HttpResponse(simplejson.dumps({}))
- ret.status_code = 403
-
+ ret = HttpResponse()
+ ret.status_code = 403
return ret