--- a/src/iconolab/fixtures/demo_data.json Thu Aug 04 15:01:27 2016 +0200
+++ b/src/iconolab/fixtures/demo_data.json Thu Aug 04 15:36:32 2016 +0200
@@ -215,14 +215,16 @@
"pk": 1,
"fields": {
"collection": 1,
- "label": "Appel à contribution"
+ "label": "Appel à contribution",
+ "triggers_notifications": 1
}
},{
"model": "iconolab.MetaCategory",
"pk": 2,
"fields": {
"collection": 1,
- "label": "Appel à expertise"
+ "label": "Appel à expertise",
+ "triggers_notifications": 3
}
},{
"model": "iconolab.MetaCategory",
--- a/src/iconolab/signals/handlers.py Thu Aug 04 15:01:27 2016 +0200
+++ b/src/iconolab/signals/handlers.py Thu Aug 04 15:36:32 2016 +0200
@@ -68,25 +68,32 @@
def notify_users_on_new_comment(sender, instance, **kwargs):
- from iconolab.models import IconolabComment, Annotation, MetaCategory
- print(sender)
+ from iconolab.models import IconolabComment, Annotation, MetaCategory, MetaCategoryInfo
if sender == IconolabComment and instance.content_type.app_label == 'iconolab' and instance.content_type.model == 'annotation':
comment_annotation = Annotation.objects.get(id=instance.object_pk)
# Notifying new user comment
- if instance.user != comment_annotation.author:
- notify.send(instance.user, recipient=comment_annotation.author, verb='a écrit un commentaire sur votre annotation', action_object=instance, target=comment_annotation)
- if instance.parent_id and instance.level > 0: # We check parent_id as django comment xtd saves comments in two steps and only set the information we need in the second step
- parent_comment = IconolabComment.objects.get(id=instance.parent_id)
- notify.send(instance.user, recipient=parent_comment.user, verb='a répondu à votre commentaire', action_object=instance, target=comment_annotation)
+ if instance.parent_id:
+ if instance.user != comment_annotation.author:
+ notify.send(instance.user, recipient=comment_annotation.author, verb='a écrit un commentaire sur votre annotation', action_object=instance, target=comment_annotation)
+ if instance.level > 0: # We check parent_id as django comment xtd saves comments in two steps and only set the information we need in the second step
+ parent_comment = IconolabComment.objects.get(id=instance.parent_id)
+ notify.send(instance.user, recipient=parent_comment.user, verb='a répondu à votre commentaire', action_object=instance, target=comment_annotation)
+
- for metacategory in instance.metacategories.all():
- if metacategory.triggers_notifications == MetaCategory.COMMENTERS:
- for commenter in comment_annotation.stats.commenters.exclude(id=instance.user.id).all():
- notify.send(instance.user, recipient=commenter, verb='a fait un appel à contribution', action_object=instance, target=comment_annotation)
- elif metacategory.triggers_notifications == MetaCategory.CONTRIBUTORS:
- for contributor in comment_annotation.stats.contributors.exclude(id=instance.user.id).all():
- notify.send(instance.user, recipient=contributor, verb='a fait un appel à contribution', action_object=instance, target=comment_annotation)
- if metacategory.triggers_notifications == MetaCategory.COLLECTION_ADMINS:
+def notify_users_on_metacategory(sender, instance, created, **kwargs):
+ from iconolab.models import MetaCategory, MetaCategoryInfo, Annotation
+ if sender == MetaCategoryInfo and created:
+ related_metacategory = instance.metacategory
+ related_comment = instance.comment
+ if related_comment.content_type.app_label == "iconolab" and related_comment.content_type.model == "annotation":
+ comment_annotation = Annotation.objects.get(id=related_comment.object_pk)
+ if related_metacategory.triggers_notifications == MetaCategory.COMMENTERS:
+ for commenter in comment_annotation.stats.commenters.exclude(id=related_comment.user.id).all():
+ notify.send(related_comment.user, recipient=commenter, verb='a fait un appel à contribution', action_object=related_comment, target=comment_annotation)
+ elif related_metacategory.triggers_notifications == MetaCategory.CONTRIBUTORS:
+ for contributor in comment_annotation.stats.contributors.exclude(id=related_comment.user.id).all():
+ notify.send(related_comment.user, recipient=contributor, verb='a fait un appel à contribution', action_object=related_comment, target=comment_annotation)
+ if related_metacategory.triggers_notifications == MetaCategory.COLLECTION_ADMINS:
pass
def notify_users_on_new_revision(sender, instance, **kwargs):
@@ -111,6 +118,7 @@
revision_rejected.connect(increment_stats_on_rejected_revision)
# Notifications handlers connect
post_save.connect(notify_users_on_new_comment)
+post_save.connect(notify_users_on_metacategory)
revision_created.connect(notify_users_on_new_revision)
revision_accepted.connect(notify_users_on_accepted_revision)
\ No newline at end of file
--- a/src/iconolab/views/iconolab.py Thu Aug 04 15:01:27 2016 +0200
+++ b/src/iconolab/views/iconolab.py Thu Aug 04 15:36:32 2016 +0200
@@ -59,11 +59,10 @@
class UserNotificationsView(View):
def get(self, request, *args, **kwargs):
- print("WHATTHEFUCK")
context = {}
notifications = Notification.objects.filter(recipient=request.user)
context["notifications_unread_ids"] = notifications.unread().values_list("id", flat=True)
- #notifications.mark_all_as_read()
+ notifications.mark_all_as_read()
context["notifications"] = notifications
return render(request, 'iconolab/user_notifications.html', context)