Added option to assign multiple managed collections on one account + small correction on stats template #41
authordurandn
Tue, 15 Nov 2016 12:11:18 +0100
changeset 242 430188380ba8
parent 241 06c88bfd5c8d
child 243 5d52c22fc45c
Added option to assign multiple managed collections on one account + small correction on stats template #41
src/iconolab/migrations/0015_auto_20161115_1031.py
src/iconolab/models.py
src/iconolab/templates/iconolab/user_home.html
src/iconolab/templates/partials/annotation_stats_panel.html
src/iconolab/templates/partials/image_annotations_list.html
src/iconolab/urls.py
src/iconolab/views/userpages.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/iconolab/migrations/0015_auto_20161115_1031.py	Tue Nov 15 12:11:18 2016 +0100
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10 on 2016-11-15 10:31
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('iconolab', '0014_auto_20161108_1458'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='userprofile',
+            name='administers_collection',
+        ),
+        migrations.AddField(
+            model_name='userprofile',
+            name='managed_collections',
+            field=models.ManyToManyField(blank=True, related_name='admins', to='iconolab.Collection'),
+        ),
+    ]
--- a/src/iconolab/models.py	Mon Nov 14 16:15:26 2016 +0100
+++ b/src/iconolab/models.py	Tue Nov 15 12:11:18 2016 +0100
@@ -688,7 +688,7 @@
     
 class UserProfile(models.Model):
     user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE)
-    administers_collection = models.ForeignKey('Collection', related_name='collection', blank=True, null=True)
+    managed_collections = models.ManyToManyField('Collection', related_name='admins', blank=True)
     
     def __str__(self):
         return "profile:"+self.user.username
\ No newline at end of file
--- a/src/iconolab/templates/iconolab/user_home.html	Mon Nov 14 16:15:26 2016 +0100
+++ b/src/iconolab/templates/iconolab/user_home.html	Tue Nov 15 12:11:18 2016 +0100
@@ -117,17 +117,15 @@
         </div>
       </div>
     </div>
-    {% if profile_user == request.user and profile_user.profile.administers_collection %}
+    {% if profile_user.profile.managed_collections %}
     <div class="col-md-12">
-      <div class="panel panel-default" style="padding: 10px;">
-      
-        <div class="alert alert-warning">
-          L'accès à ces fonctionnalités n'est pas encore disponible.
+      <div class="panel panel-default text-center" style="padding: 10px;">
+        {% for collection in profile_user.profile.managed_collections.all %}
+        <h3><small>Administration du Fonds</small> {{collection.verbose_name}}</h3>
+        <div>
+          <a href="{% url 'user_admin_panel' profile_user.id collection.name %}" class="btn btn-default text-center">Tableau de bord</a>
         </div>
-        <h3><small>Administration du Fonds</small> {{user.profile.administers_collection.verbose_name}}</h3>
-        <div class="text-center">
-          <a href="{% url 'user_admin_panel' profile_user.id %}" class="btn btn-default text-center">Tableau de bord</a>
-        </div>
+        {% endfor %}
       </div>
     </div>
     {% endif %}
--- a/src/iconolab/templates/partials/annotation_stats_panel.html	Mon Nov 14 16:15:26 2016 +0100
+++ b/src/iconolab/templates/partials/annotation_stats_panel.html	Tue Nov 15 12:11:18 2016 +0100
@@ -8,7 +8,7 @@
       <dd><span class="badge">{{ annotation.stats.comments_count }}</span></dd>
       {% with annotation.stats.metacategoriescountinfo_set.all as annotation_metacategories_infos %}
         {% if annotation_metacategories_infos %}
-          <dt>.. Métacatégories :</dt>
+          <dt>... Métacatégories :</dt>
           <dd>
             {% for metacategory_info in annotation_metacategories_infos %}
               <span class="label label-info">{{metacategory_info.count}} {{metacategory_info.metacategory.label}}</span><br>
--- a/src/iconolab/templates/partials/image_annotations_list.html	Mon Nov 14 16:15:26 2016 +0100
+++ b/src/iconolab/templates/partials/image_annotations_list.html	Tue Nov 15 12:11:18 2016 +0100
@@ -56,7 +56,7 @@
               <b>Espace de travail</b><br>
               <a class="btn btn-primary btn-sm" href="{% url 'annotation_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid %}" target="_blank">Suivre le lien</a><br>
               <br><b>Etat courant<br>
-              <a class="btn btn-primary btn-sm" href= "{% url 'revision_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid annotation.current_revision.revision_guid %}" target="_blank">Suivre le lien</a><br>
+              <a class="btn btn-primary btn-sm" href="{% url 'revision_detail' annotation.image.item.collection.name annotation.image.image_guid annotation.annotation_guid annotation.current_revision.revision_guid %}" target="_blank">Suivre le lien</a><br>
             </td>
             {% endif %}
           </tr>
--- a/src/iconolab/urls.py	Mon Nov 14 16:15:26 2016 +0100
+++ b/src/iconolab/urls.py	Tue Nov 15 12:11:18 2016 +0100
@@ -47,7 +47,7 @@
     url(r'^user/(?P<slug>[a-z0-9\-]+)/commented/?$', views.userpages.UserCommentedView.as_view(), name="user_commented"),
     url(r'^user/(?P<slug>[a-z0-9\-]+)/contributed/?$', views.userpages.UserContributedView.as_view(), name="user_contributed"),
     url(r'^user/(?P<slug>[a-z0-9\-]+)/annotations/?$', views.userpages.UserAnnotationsView.as_view(), name="user_annotations"),
-    url(r'^user/(?P<slug>[a-z0-9\-]+)/adminpanel/$', views.userpages.UserCollectionAdminView.as_view(), name="user_admin_panel"),
+    url(r'^user/(?P<slug>[a-z0-9\-]+)/adminpanel/(?P<collection_name>[a-z0-9\-]+)/$', views.userpages.UserCollectionAdminView.as_view(), name="user_admin_panel"),
     url(r'^user/notifications/all/?$', login_required(views.userpages.UserNotificationsView.as_view()), name="user_notifications"),
     url(r'^user/notifications/', include(notifications.urls, namespace='notifications')),
     
--- a/src/iconolab/views/userpages.py	Mon Nov 14 16:15:26 2016 +0100
+++ b/src/iconolab/views/userpages.py	Tue Nov 15 12:11:18 2016 +0100
@@ -9,7 +9,7 @@
 from django.conf import settings
 from django.urls import reverse
 from notifications.models import Notification
-from iconolab.models import Annotation, IconolabComment, Image, MetaCategoriesCountInfo
+from iconolab.models import Collection, Annotation, IconolabComment, Image, MetaCategoriesCountInfo
 from uuid import UUID
 import logging
 
@@ -157,10 +157,13 @@
         self.object = self.get_object()
         profile_user = self.object
         context = self.get_context_data()
-        
-        if not request.user.is_staff and not request.user.is_authenticated or profile_user != request.user or not request.user.profile.administers_collection:
+        collection_name = kwargs.get("collection_name") 
+        collection_qs = Collection.objects.filter(name=collection_name)
+        if not request.user.is_staff and not request.user.is_authenticated or profile_user != request.user or not collection_qs.exists():
             return redirect(reverse_lazy('user_home', kwargs={'slug': profile_user.id}))
-        collection = request.user.profile.administers_collection
+        collection = collection_qs.first()
+        if collection not in profile_user.profile.managed_collections.all():
+            return redirect(reverse_lazy('user_home', kwargs={'slug': profile_user.id}))
         
         annotation_queryset = Annotation.objects.distinct().filter(image__item__collection=collection).prefetch_related('current_revision', 'stats', 'image', 'image__item')