# HG changeset patch # User durandn # Date 1470315687 -7200 # Node ID 2b738b88d483b1415506a3c0f866b0ff84afe27c # Parent f747c112e8f411cc49876b08ef99f7aab5c03d8b workon on notifications: user home, user notifications page, triggers in signals diff -r f747c112e8f4 -r 2b738b88d483 src/iconolab/models.py --- a/src/iconolab/models.py Wed Aug 03 15:47:03 2016 +0200 +++ b/src/iconolab/models.py Thu Aug 04 15:01:27 2016 +0200 @@ -230,7 +230,8 @@ if revision_to_reject.state == AnnotationRevision.AWAITING: revision_to_reject.state = AnnotationRevision.REJECTED revision_to_reject.save() - + iconolab_signals.revision_rejected.send(sender=AnnotationRevision, instance=revision_to_reject) + # Call when we're validating an awaiting revision whose parent isn't the current revision OR IF IT WAS CHANGED BY THE ANNOTATION AUTHOR @transaction.atomic def merge_existing_revision(self, title, description, fragment, tags, revision_to_merge): @@ -313,13 +314,16 @@ sparql_template = 'select distinct * where { <<%uri%>> rdfs:label ?l FILTER( langMatches( lang(?l), "<%lang%>" ) ) }' sparql_query = re.sub("<%uri%>", uri, re.sub("<%lang%>", lang, sparql_template)) sparql_query_url = source+'sparql' - dbpedia_resp = requests.get( - sparql_query_url, - params={ - "query": sparql_query, - "format": "json" - } - ) + try: + dbpedia_resp = requests.get( + sparql_query_url, + params={ + "query": sparql_query, + "format": "json" + } + ) + except: + pass try: results = json.loads(dbpedia_resp.text).get("results", {}) except: diff -r f747c112e8f4 -r 2b738b88d483 src/iconolab/signals/handlers.py --- a/src/iconolab/signals/handlers.py Wed Aug 03 15:47:03 2016 +0200 +++ b/src/iconolab/signals/handlers.py Thu Aug 04 15:01:27 2016 +0200 @@ -2,10 +2,10 @@ from django.db.models.signals import post_save from django.dispatch import Signal, receiver from notifications.signals import notify -from django_comments.signals import comment_was_posted # Signal sent during method Annotation.validate_existing_revision to update stats revision_accepted = Signal(providing_args=['instance']) +revision_rejected = Signal(providing_args=['instance']) revision_created = Signal(providing_args=['instance']) @@ -17,6 +17,8 @@ annotation.stats.submitted_revisions_count += 1 if instance.state in [AnnotationRevision.ACCEPTED, AnnotationRevision.STUDIED]: annotation.stats.accepted_revisions_count += 1 + if instance.state == AnnotationRevision.ACCEPTED and instance.merge_parent_revision.state == AnnotationRevision.STUDIED: + annotation.stats.awaiting_revisions_count -= 1 if instance.state in [AnnotationRevision.AWAITING]: annotation.stats.awaiting_revisions_count += 1 annotation.stats.set_tags_stats() @@ -28,7 +30,7 @@ image.stats.save() -def increment_stats_on_new_comments(sender, instance, created, **kwargs): +def increment_stats_on_new_comment(sender, instance, created, **kwargs): from iconolab.models import IconolabComment if created and sender == IconolabComment: model = apps.get_model(instance.content_type.app_label,instance.content_type.model) @@ -40,11 +42,19 @@ annotation.image.stats.save() -def increment_accepted_revisions(sender, instance, **kwargs): +def increment_stats_on_accepted_revision(sender, instance, **kwargs): from iconolab.models import AnnotationRevision if sender == AnnotationRevision: annotation = instance.annotation annotation.stats.accepted_revisions_count += 1 + annotation.stats.awaiting_revisions_count -= 1 + annotation.stats.save() + +def increment_stats_on_rejected_revision(sender, instance, **kwargs): + from iconolab.models import AnnotationRevision + if sender == AnnotationRevision: + annotation = instance.annotation + annotation.stats.awaiting_revisions_count -= 1 annotation.stats.save() def increment_annotations_count(sender, instance, created, **kwargs): @@ -57,18 +67,18 @@ image.stats.save() -def notify_users_on_new_comment(sender, comment, **kwargs): +def notify_users_on_new_comment(sender, instance, **kwargs): from iconolab.models import IconolabComment, Annotation, MetaCategory + print(sender) 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) - print(instance.parent_id) - print(instance.id) - if instance.level > 0: + 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) + 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(): @@ -95,11 +105,12 @@ # Stats handlers connect post_save.connect(increment_annotations_count) -post_save.connect(increment_stats_on_new_comments) +post_save.connect(increment_stats_on_new_comment) revision_created.connect(increment_stats_on_new_revision) -revision_accepted.connect(increment_accepted_revisions) +revision_accepted.connect(increment_stats_on_accepted_revision) +revision_rejected.connect(increment_stats_on_rejected_revision) # Notifications handlers connect -comment_was_posted.connect(notify_users_on_new_comment) +post_save.connect(notify_users_on_new_comment) revision_created.connect(notify_users_on_new_revision) revision_accepted.connect(notify_users_on_accepted_revision) \ No newline at end of file diff -r f747c112e8f4 -r 2b738b88d483 src/iconolab/static/iconolab/css/iconolab.css --- a/src/iconolab/static/iconolab/css/iconolab.css Wed Aug 03 15:47:03 2016 +0200 +++ b/src/iconolab/static/iconolab/css/iconolab.css Thu Aug 04 15:01:27 2016 +0200 @@ -103,4 +103,7 @@ .notif-badge{ margin-bottom: 5px; +} +.show-all-notifications{ + cursor: pointer; } \ No newline at end of file diff -r f747c112e8f4 -r 2b738b88d483 src/iconolab/templates/iconolab/user_home.html --- a/src/iconolab/templates/iconolab/user_home.html Wed Aug 03 15:47:03 2016 +0200 +++ b/src/iconolab/templates/iconolab/user_home.html Thu Aug 04 15:01:27 2016 +0200 @@ -5,6 +5,7 @@ {% load thumbnail %} {% load iconolab_tags %} + {% load notifications_tags %} {% block content %} @@ -14,8 +15,9 @@

{% if profile_user == request.user %}Mon espace:{% else %}Profil: {% endif %} {{profile_user.username}}

{% if profile_user == request.user %} -

{{notifications.unread.count}} Notifications non lues - Voir toutes mes notifications + {% notifications_unread as unread_count %} +

{{unread_count}} Notifications non lues + Voir toutes mes notifications Tout marquer comme lu

@@ -26,7 +28,7 @@ {{notification.actor.username}} {{notification.verb}} - {{notification.timesince}} + {% if forloop.counter == 5 %} + ... + {% endif %} {% endfor %} {% endif %} @@ -70,7 +75,7 @@
Commentaires:
{{annotation.stats.comments_count}}
Révisions en attente:
-
{{annotation.awaiting_revisions_count}}
+
{{annotation.stats.awaiting_revisions_count}}
@@ -103,4 +108,14 @@ +{% endblock %} + +{% block footer_js %} + {% endblock %} \ No newline at end of file diff -r f747c112e8f4 -r 2b738b88d483 src/iconolab/templates/iconolab/user_notifications.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/iconolab/templates/iconolab/user_notifications.html Thu Aug 04 15:01:27 2016 +0200 @@ -0,0 +1,40 @@ +{% extends 'iconolab_base.html' %} + +{% load staticfiles %} + +{% load thumbnail %} + +{% load iconolab_tags %} + +{% load notifications_tags %} + +{% block content %} +
+
+
+

Mes notifications:

+ {% if notifications %} + + {% endif %} +
+
+
+{% endblock %} \ No newline at end of file diff -r f747c112e8f4 -r 2b738b88d483 src/iconolab/templates/iconolab_base.html --- a/src/iconolab/templates/iconolab_base.html Wed Aug 03 15:47:03 2016 +0200 +++ b/src/iconolab/templates/iconolab_base.html Thu Aug 04 15:01:27 2016 +0200 @@ -1,4 +1,7 @@ {% load staticfiles %} + +{% load notifications_tags %} + diff -r f747c112e8f4 -r 2b738b88d483 src/iconolab/templates/partials/header.html --- a/src/iconolab/templates/partials/header.html Wed Aug 03 15:47:03 2016 +0200 +++ b/src/iconolab/templates/partials/header.html Thu Aug 04 15:01:27 2016 +0200 @@ -1,3 +1,4 @@ +{% load notifications_tags %}