206 |
206 |
207 ret['comment'] = comment |
207 ret['comment'] = comment |
208 ret['msg'] = _(u'comment saved') |
208 ret['msg'] = _(u'comment saved') |
209 return ret |
209 return ret |
210 |
210 |
|
211 # DIRTY : this function has no error check but anyway errors are not listened to client side |
|
212 @has_perm_on_text("can_create_comment") |
|
213 def own_notify(request, key): |
|
214 email_or_user = None if request.user.is_anonymous() else request.user |
|
215 if not email_or_user : |
|
216 email_or_user = request.POST.get('email', None) |
|
217 if email_or_user : |
|
218 email_or_user = email_or_user.lower().strip() |
|
219 |
|
220 text = Text.objects.get(key=key) |
|
221 Notification.objects.set_notification(text=None, type='own', active=True, email_or_user=email_or_user) |
|
222 ret = HttpResponse() |
|
223 ret.status_code = 200 |
|
224 return ret |
|
225 |
211 @has_perm_on_text("can_create_comment") |
226 @has_perm_on_text("can_create_comment") |
212 def add_comment(request, key): |
227 def add_comment(request, key): |
213 # if edit_comment_id : # |
228 # if edit_comment_id : # |
214 # if self.request.user.is_anonymous() : # accessing via an admin url ? |
229 # if self.request.user.is_anonymous() : # accessing via an admin url ? |
215 # and comment.user == self.request.user |
230 # and comment.user == self.request.user |
238 text_version = text.get_latest_version() |
253 text_version = text.get_latest_version() |
239 |
254 |
240 comment_state = 'approved' if text_version.mod_posteriori else 'pending' |
255 comment_state = 'approved' if text_version.mod_posteriori else 'pending' |
241 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) |
256 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) |
242 |
257 |
|
258 ask_for_notification = True |
|
259 if user : |
|
260 workspace_notify_count = Notification.objects.filter(text=None,type='workspace',user=user, active=True).count() |
|
261 text_notify_count = Notification.objects.filter(text=text,type='text',user=user, active=True).count() |
|
262 if workspace_notify_count > 0 or text_notify_count > 0 : |
|
263 ask_for_notification = False |
|
264 |
|
265 if ask_for_notification : |
|
266 ask_for_notification = ( None == Notification.objects.get_notifications(text=None, type='own', email_or_user=(user if user else email))) |
|
267 ret['ask_for_notification'] = ask_for_notification |
|
268 ret['email'] = '' if user else email |
|
269 |
243 if text_version.mod_posteriori or has_perm(request, 'can_view_unapproved_comment', text=text) : |
270 if text_version.mod_posteriori or has_perm(request, 'can_view_unapproved_comment', text=text) : |
244 ret['comment'] = comment |
271 ret['comment'] = comment |
245 ret['msg'] = _(u"comment saved") |
272 ret['msg'] = _(u"comment saved") |
246 else : |
273 else : |
247 ret['msg'] = _(u"comment saved, it is being held for moderation") |
274 ret['msg'] = _(u"comment saved, it is being held for moderation") |
248 |
275 |
249 if AUTO_CONTRIB_REGISTER: |
276 if AUTO_CONTRIB_REGISTER: |
250 Notification.objects.set_notification_to_own_discussions(text=text, email_or_user=user or email) |
277 Notification.objects.set_notification(text=text, type='own', active=True, email_or_user=user or email) |
251 register_activity(request, "comment_created", text, comment) |
278 register_activity(request, "comment_created", text, comment) |
252 return ret |
279 return ret |
253 |
280 |
254 #we need to call comments_thread from here this function will be very expensive |
281 #we need to call comments_thread from here this function will be very expensive |
255 # TODO: stupid get rid of text argument |
282 # TODO: stupid get rid of text argument |