src/iconolab/signals/handlers.py
author durandn
Fri, 09 Dec 2016 14:40:56 +0100
changeset 272 c838f9ee207a
parent 238 ad770589f0fe
child 283 d8fcfac848ed
permissions -rw-r--r--
Fixed error with admin notifications on relevant metacategories
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
     1
from django.apps import apps
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
     2
from django.db.models.signals import post_save
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
     3
from django.dispatch import Signal, receiver
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
     4
from notifications.signals import notify
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
     5
import logging
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
     6
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
     7
logger = logging.getLogger(__name__)
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
     8
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
     9
# Signal sent during method Annotation.validate_existing_revision to update stats
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
    10
revision_accepted = Signal(providing_args=['instance'])
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    11
revision_rejected = Signal(providing_args=['instance'])
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
    12
revision_created = Signal(providing_args=['instance'])
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    13
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    14
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    15
def increment_stats_on_new_revision(sender, instance, **kwargs):
94
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    16
    from iconolab.models import AnnotationRevision
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    17
    if sender == AnnotationRevision:
134
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    18
        if instance.parent_revision:
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    19
            # Annotation stats
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    20
            annotation = instance.annotation
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    21
            annotation.stats.submitted_revisions_count += 1
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    22
            if instance.state in [AnnotationRevision.ACCEPTED, AnnotationRevision.STUDIED]:
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    23
                annotation.stats.accepted_revisions_count += 1
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    24
            if instance.state == AnnotationRevision.ACCEPTED and instance.merge_parent_revision is not None and instance.merge_parent_revision.state == AnnotationRevision.STUDIED:
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    25
                annotation.stats.awaiting_revisions_count -= 1
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    26
            if instance.state in [AnnotationRevision.AWAITING]:
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    27
                annotation.stats.awaiting_revisions_count += 1
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    28
            annotation.stats.set_tags_stats()
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    29
            annotation.stats.save()
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    30
            # Image stats
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    31
            image = instance.annotation.image
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    32
            image.stats.submitted_revisions_count += 1
350bdfe7c289 sending revision_created signal when creating an annotation
durandn
parents: 132
diff changeset
    33
            image.stats.set_tags_stats()
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    34
            image.stats.save()  
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    35
    
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    36
def increment_stats_on_new_comment(sender, instance, created, **kwargs):
94
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    37
    from iconolab.models import IconolabComment
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    38
    if created and sender == IconolabComment:
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    39
        model = apps.get_model(instance.content_type.app_label,instance.content_type.model)
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    40
        object_pk = instance.object_pk
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    41
        annotation = model.objects.get(pk=object_pk)
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    42
        annotation.stats.comments_count +=1
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    43
        annotation.stats.save()
89
23679a6def77 fixed error on stats (comments count not updating correctly for images)
durandn
parents: 85
diff changeset
    44
        annotation.image.stats.comments_count +=1
23679a6def77 fixed error on stats (comments count not updating correctly for images)
durandn
parents: 85
diff changeset
    45
        annotation.image.stats.save()
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    46
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    47
def increment_stats_on_new_metacategory(sender, instance, created, **kwargs):
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    48
    from iconolab.models import MetaCategoryInfo, MetaCategoriesCountInfo
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    49
    if created and sender == MetaCategoryInfo:
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    50
        metacategory = instance.metacategory
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    51
        comment = instance.comment
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    52
        annotation = comment.annotation
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    53
        if metacategory not in annotation.stats.metacategories.all():
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    54
            MetaCategoriesCountInfo.objects.create(annotation_stats_obj=annotation.stats, metacategory=metacategory, count=1)
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    55
        else:
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    56
            m2m_object = MetaCategoriesCountInfo.objects.get(annotation_stats_obj=annotation.stats, metacategory=metacategory)
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    57
            m2m_object.count += 1
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    58
            m2m_object.save()
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
    59
        logger.debug("NEW METACATEGORY %r on comment %r on annotation %r", metacategory, comment, annotation)
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    60
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    61
def increment_stats_on_accepted_revision(sender, instance, **kwargs):
94
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    62
    from iconolab.models import AnnotationRevision
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    63
    if sender == AnnotationRevision:
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    64
        annotation = instance.annotation
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    65
        annotation.stats.accepted_revisions_count += 1
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    66
        annotation.stats.awaiting_revisions_count -= 1
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    67
        annotation.stats.save()
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    68
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    69
def increment_stats_on_rejected_revision(sender, instance, **kwargs):
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    70
    from iconolab.models import AnnotationRevision
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    71
    if sender == AnnotationRevision:
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    72
        annotation = instance.annotation
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    73
        annotation.stats.awaiting_revisions_count -= 1
94
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    74
        annotation.stats.save()
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    75
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    76
def increment_annotations_count(sender, instance, created, **kwargs):
94
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    77
    from iconolab.models import Annotation
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
    78
    if created and sender == Annotation:
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    79
        image = instance.image
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    80
        image.stats.annotations_count += 1
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    81
        image.stats.submitted_revisions_count += 1
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    82
        image.stats.set_tags_stats()
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    83
        image.stats.save()
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
    84
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
    85
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
    86
def notify_users_on_new_comment(sender, instance, **kwargs):
99
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
    87
    from iconolab.models import IconolabComment, Annotation, MetaCategory, MetaCategoryInfo
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
    88
    if sender == IconolabComment and instance.content_type.app_label == 'iconolab' and instance.content_type.model == 'annotation':
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
    89
        comment_annotation = Annotation.objects.get(id=instance.object_pk)
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
    90
        # Notifying new user comment
103
7a7f44c3b124 *properly* fix sending two notifications to annotation author when creating comment
durandn
parents: 102
diff changeset
    91
        if instance.thread_id:
102
4a63b6ac7a96 fixed problem with duplicate notifications for annotation author
durandn
parents: 99
diff changeset
    92
            notified_author = False
99
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
    93
            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
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
    94
                parent_comment = IconolabComment.objects.get(id=instance.parent_id)
103
7a7f44c3b124 *properly* fix sending two notifications to annotation author when creating comment
durandn
parents: 102
diff changeset
    95
                if parent_comment.user != instance.user:
7a7f44c3b124 *properly* fix sending two notifications to annotation author when creating comment
durandn
parents: 102
diff changeset
    96
                    notify.send(instance.user, recipient=parent_comment.user, verb='a répondu à votre commentaire', action_object=instance, target=comment_annotation)
7a7f44c3b124 *properly* fix sending two notifications to annotation author when creating comment
durandn
parents: 102
diff changeset
    97
                    if parent_comment.user == comment_annotation.author:
7a7f44c3b124 *properly* fix sending two notifications to annotation author when creating comment
durandn
parents: 102
diff changeset
    98
                        notified_author = True
7a7f44c3b124 *properly* fix sending two notifications to annotation author when creating comment
durandn
parents: 102
diff changeset
    99
            if instance.user != comment_annotation.author and not notified_author:
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
   100
                notify.send(instance.user, recipient=comment_annotation.author, verb='a écrit un commentaire sur votre annotation', action_object=instance, target=comment_annotation)         
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
   101
99
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   102
def notify_users_on_metacategory(sender, instance, created, **kwargs):
132
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   103
    from iconolab.models import MetaCategory, MetaCategoryInfo, Annotation, UserProfile
99
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   104
    if sender == MetaCategoryInfo and created:
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   105
        related_metacategory = instance.metacategory
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   106
        related_comment = instance.comment
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   107
        if related_comment.content_type.app_label == "iconolab" and related_comment.content_type.model == "annotation":
132
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   108
            comment_annotation = Annotation.objects.prefetch_related("image__item__collection").get(id=related_comment.object_pk)
99
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   109
            if related_metacategory.triggers_notifications == MetaCategory.COMMENTERS:
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   110
                for commenter in comment_annotation.stats.commenters.exclude(id=related_comment.user.id).all():
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   111
                    notify.send(related_comment.user, recipient=commenter, verb='a fait un appel à contribution', action_object=related_comment, target=comment_annotation)
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   112
            elif related_metacategory.triggers_notifications == MetaCategory.CONTRIBUTORS:
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   113
                for contributor in comment_annotation.stats.contributors.exclude(id=related_comment.user.id).all():
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   114
                    notify.send(related_comment.user, recipient=contributor, verb='a fait un appel à contribution', action_object=related_comment, target=comment_annotation)
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   115
            if related_metacategory.triggers_notifications == MetaCategory.COLLECTION_ADMINS:
272
c838f9ee207a Fixed error with admin notifications on relevant metacategories
durandn
parents: 238
diff changeset
   116
                for collection_admin in comment_annotation.image.item.collection.admins.all():
132
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   117
                    notify.send(related_comment.user, recipient=collection_admin.user, verb='a fait un appel à expertise', action_object=related_comment, target=comment_annotation)
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   118
        
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   119
def notify_users_on_new_revision(sender, instance, **kwargs):
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   120
    from iconolab.models import AnnotationRevision
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   121
    if sender == AnnotationRevision:
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   122
        if instance.author != instance.annotation.author:
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
   123
            notify.send(instance.author, recipient=instance.annotation.author, verb='a proposé une révision sur votre annotation', action_object=instance, target=instance.annotation)       
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   124
        
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   125
def notify_users_on_accepted_revision(sender, instance, **kwargs):
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   126
    from iconolab.models import AnnotationRevision
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   127
    if sender == AnnotationRevision:
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   128
        if instance.author != instance.annotation.author and instance.state in [AnnotationRevision.ACCEPTED, AnnotationRevision.STUDIED]:
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
   129
            notify.send(instance.annotation.author, recipient=instance.author, verb='a étudié votre révision', action_object=instance, target=instance.annotation)       
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   130
132
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   131
def create_user_profile(sender, instance, created, **kwargs):
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   132
    from iconolab.models import UserProfile
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   133
    from django.contrib.auth.models import User
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   134
    if sender == User and created:
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   135
        UserProfile.objects.create(user=instance)
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   136
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   137
# User profile connect
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   138
post_save.connect(create_user_profile)
4728f6c0102e Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
durandn
parents: 123
diff changeset
   139
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   140
# Stats handlers connect
94
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
   141
post_save.connect(increment_annotations_count)
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
   142
post_save.connect(increment_stats_on_new_comment)
238
ad770589f0fe Work on admin interface and user pages + added stat metacategories count for annotations + refactored views module #41
durandn
parents: 134
diff changeset
   143
post_save.connect(increment_stats_on_new_metacategory)
94
a47934ff37ec signals refactoring followup: fixed circular import + added a profile view and template and link in header + refactored views into a views module
durandn
parents: 90
diff changeset
   144
revision_created.connect(increment_stats_on_new_revision)
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
   145
revision_accepted.connect(increment_stats_on_accepted_revision)
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
   146
revision_rejected.connect(increment_stats_on_rejected_revision)
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   147
# Notifications handlers connect
98
2b738b88d483 workon on notifications: user home, user notifications page, triggers in signals
durandn
parents: 97
diff changeset
   148
post_save.connect(notify_users_on_new_comment)
99
21ed0482625b cleaning up prints + notifications on metacategories
durandn
parents: 98
diff changeset
   149
post_save.connect(notify_users_on_metacategory)
97
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   150
revision_created.connect(notify_users_on_new_revision)
f747c112e8f4 Started work on notification and user homepage + method for a comment to find back its page in his annotation's comments
durandn
parents: 94
diff changeset
   151
revision_accepted.connect(notify_users_on_accepted_revision)
85
49b3f22948d5 work on stats: calculatestats command for manage.py, stats in item page, stats in annotations list, stats in annotation page, actions increment stats (view count, annotations count, comment count etc)
durandn
parents: 24
diff changeset
   152