Added user profile to identify collection admins and extend user model + notification on collection_admins metacategories
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/migrations/0011_userprofile.py Tue Aug 16 17:02:57 2016 +0200
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-08-16 14:46
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('iconolab', '0010_auto_20160816_1242'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='UserProfile',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('administers_collection', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='collection', to='iconolab.Collection')),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user', to=settings.AUTH_USER_MODEL)),
+ ],
+ ),
+ ]
--- a/src/iconolab/models.py Tue Aug 16 16:05:06 2016 +0200
+++ b/src/iconolab/models.py Tue Aug 16 17:02:57 2016 +0200
@@ -491,4 +491,8 @@
comment = models.ForeignKey('IconolabComment', related_name='attachments', on_delete=models.CASCADE)
attachment_type = models.IntegerField(choices=COMMENT_CHOICES, default=0)
- data = models.TextField(blank=False)
\ No newline at end of file
+ data = models.TextField(blank=False)
+
+class UserProfile(models.Model):
+ user = models.ForeignKey(User, related_name='user', on_delete=models.CASCADE)
+ administers_collection = models.ForeignKey('Collection', related_name='collection', blank=True, null=True)
\ No newline at end of file
--- a/src/iconolab/signals/handlers.py Tue Aug 16 16:05:06 2016 +0200
+++ b/src/iconolab/signals/handlers.py Tue Aug 16 17:02:57 2016 +0200
@@ -85,12 +85,12 @@
def notify_users_on_metacategory(sender, instance, created, **kwargs):
- from iconolab.models import MetaCategory, MetaCategoryInfo, Annotation
+ from iconolab.models import MetaCategory, MetaCategoryInfo, Annotation, UserProfile
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)
+ comment_annotation = Annotation.objects.prefetch_related("image__item__collection").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)
@@ -98,7 +98,8 @@
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
+ for collection_admin in UserProfile.objects.filter(administers_collection=comment_annotation.image.item.collection).all():
+ notify.send(related_comment.user, recipient=collection_admin.user, verb='a fait un appel à expertise', action_object=related_comment, target=comment_annotation)
def notify_users_on_new_revision(sender, instance, **kwargs):
from iconolab.models import AnnotationRevision
@@ -114,6 +115,15 @@
notify.send(instance.annotation.author, recipient=instance.author, verb='a étudié votre révision', action_object=instance, target=instance.annotation)
+def create_user_profile(sender, instance, created, **kwargs):
+ from iconolab.models import UserProfile
+ from django.contrib.auth.models import User
+ if sender == User and created:
+ UserProfile.objects.create(user=instance)
+
+# User profile connect
+post_save.connect(create_user_profile)
+
# Stats handlers connect
post_save.connect(increment_annotations_count)
post_save.connect(increment_stats_on_new_comment)