From 2ffcaa1f9b2bba79a1641b5dfeb2149c02c44e7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Anjos?= <andre.anjos@idiap.ch>
Date: Thu, 9 Jun 2016 15:46:15 +0200
Subject: [PATCH] Merge branch 'plotters_patch' into 'master'

[plotters] patched urls and various user/anonymous issues for plotters

patched urls and various user/anonymous issues for plotters

See merge request !192
---
 beat/web/plotters/templates/plotters/list.html    |  2 +-
 .../plotters/templates/plotters/panels/table.html |  2 +-
 beat/web/plotters/urls.py                         | 12 ------------
 beat/web/plotters/views.py                        | 15 +++++++++------
 .../templates/statistics/panels/status.html       |  2 +-
 beat/web/ui/templates/ui/activity_stream.html     |  1 -
 .../ui/contribution_breadcrumb_plotter.html       |  6 +++---
 beat/web/ui/templatetags/ui_tags.py               | 10 +++++-----
 8 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/beat/web/plotters/templates/plotters/list.html b/beat/web/plotters/templates/plotters/list.html
index f067b5484..9bc877465 100644
--- a/beat/web/plotters/templates/plotters/list.html
+++ b/beat/web/plotters/templates/plotters/list.html
@@ -30,6 +30,6 @@
 
 {% list_tabs author "plotters" %}
 
-{% plotter_table objects owner "plotter-list" %}
+{% plotter_table objects owner "list" %}
 
 {% endblock %}
diff --git a/beat/web/plotters/templates/plotters/panels/table.html b/beat/web/plotters/templates/plotters/panels/table.html
index 24a99db88..78432f46a 100644
--- a/beat/web/plotters/templates/plotters/panels/table.html
+++ b/beat/web/plotters/templates/plotters/panels/table.html
@@ -62,7 +62,7 @@
 
     {% if objects %}
     <div class="scrollable table-responsive">
-      <table id="{{ panel_id }}" class="table table-hover table-condensed object-list plotter-list">
+      <table id="{{ panel_id }}" class="table table-hover table-condensed object-list list">
         <thead>
           <tr>
             <th class="privacy"></th>
diff --git a/beat/web/plotters/urls.py b/beat/web/plotters/urls.py
index 83e352c15..ffb9b1809 100644
--- a/beat/web/plotters/urls.py
+++ b/beat/web/plotters/urls.py
@@ -48,18 +48,6 @@ urlpatterns = [
         name='view',
     ),
 
-    url(
-        r'^(?P<author_name>\w+)/$',
-        views.list_plotters,
-        name='plotter-list',
-    ),
-
-    url(
-        r'^$',
-        views.list_plotters_public,
-        name='plotter-public-list',
-    ),
-
     url(
         r'^(?P<author>\w+)/(?P<name>[-\w]+)/$',
         views.view,
diff --git a/beat/web/plotters/views.py b/beat/web/plotters/views.py
index 28a68cc20..eab4599a7 100644
--- a/beat/web/plotters/views.py
+++ b/beat/web/plotters/views.py
@@ -344,14 +344,17 @@ def view(request, author, name, version=None):
 #----------------------------------------------------------
 
 
-def list_plotters(request, author_name):
+def list_plotters(request):
     '''List all accessible plotters to the request user'''
     # check that the user exists on the system
-    author = get_object_or_404(User, username=author_name)
-
-    objects=Plotter.objects.from_author_and_public(request.user,author_name)
-
-    owner=(request.user==author)
+    if request.user.is_anonymous():
+        author = request.user #anonymous
+        objects=Plotter.objects.public().order_by('-creation_date')
+        owner = False
+    else:
+        author = get_object_or_404(User, username=request.user.username)
+        objects=Plotter.objects.from_author_and_public(request.user,request.user.username)
+        owner=(request.user==author)
 
     return render_to_response('plotters/list.html',
             dict(
diff --git a/beat/web/statistics/templates/statistics/panels/status.html b/beat/web/statistics/templates/statistics/panels/status.html
index d6689e388..c99850e84 100644
--- a/beat/web/statistics/templates/statistics/panels/status.html
+++ b/beat/web/statistics/templates/statistics/panels/status.html
@@ -30,7 +30,7 @@
       <a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'attestations:public-list' %}{% else %}{% url 'attestations:list' request.user.username %}{% endif %}" title="Show attestations" data-toggle="tooltip" data-placement="left">Attestations <span class="badge">{{ totals.attestations }}</span></a>
       <a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'search:public-list' %}{% else %}{% url 'search:list' request.user.username %}{% endif %}" title="Show searches" data-toggle="tooltip" data-placement="left">Searches <span class="badge">{{ totals.searches }}</span></a>
       <a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'reports:public-list' %}{% else %}{% url 'reports:list' request.user.username %}{% endif %}" title="Show reports" data-toggle="tooltip" data-placement="left">Reports <span class="badge">{{ totals.reports }}</span></a>
-      <a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'plotters:plotter-public-list' %}{% else %}{% url 'plotters:plotter-list' request.user.username %}{% endif %}" title="Show plotters" data-toggle="tooltip" data-placement="left">Plotters <span class="badge">{{ totals.plotters}}</span></a>
+      <a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'plotters:list' %}{% else %}{% url 'plotters:list' %}{% endif %}" title="Show plotters" data-toggle="tooltip" data-placement="left">Plotters <span class="badge">{{ totals.plotters}}</span></a>
       <a class="list-group-item" href="{% url 'databases:list' %}" title="Show databases" data-toggle="tooltip" data-placement="left">Databases <span class="badge">{{ totals.databases }}</span></a>
       <div class="list-group-item">Users <span class="badge">{{ totals.users }}</span></div>
     </div>
diff --git a/beat/web/ui/templates/ui/activity_stream.html b/beat/web/ui/templates/ui/activity_stream.html
index 0fa7d5c0b..579d1d270 100644
--- a/beat/web/ui/templates/ui/activity_stream.html
+++ b/beat/web/ui/templates/ui/activity_stream.html
@@ -168,7 +168,6 @@
           <a href="{% url 'teams:list' author.username %}" class="list-group-item">Teams <span class="badge">{{ statistics.teams.count }}</span></a>
           <a href="{% url 'attestations:list' author.username %}" class="list-group-item">Attestations <span class="badge">{{ statistics.attestations.count }}</span></a>
           <a href="{% url 'reports:list' author.username %}" class="list-group-item">Reports <span class="badge">{{ statistics.reports.count }}</span></a>
-          <a href="{% url 'plotters:plotter-list' author.username %}" class="list-group-item">Plotters<span class="badge">{{ statistics.plotters.count }}</span></a>
           <a href="{% url 'search:list' author.username %}" class="list-group-item">Searches <span class="badge">{{ statistics.searches.count }}</span></a>
         </ul>
       </div>
diff --git a/beat/web/ui/templates/ui/contribution_breadcrumb_plotter.html b/beat/web/ui/templates/ui/contribution_breadcrumb_plotter.html
index 0463a4795..8de01f924 100644
--- a/beat/web/ui/templates/ui/contribution_breadcrumb_plotter.html
+++ b/beat/web/ui/templates/ui/contribution_breadcrumb_plotter.html
@@ -35,12 +35,12 @@
     {% endwith %}
 
     {% if not request.user.is_anonymous %}
-    <a data-toggle="tooltip" data-placement="bottom" title="View all your {{ name_plural }}" href="{% url listurl request.user.username %}">{{ name_plural }}</a>
+    <a data-toggle="tooltip" data-placement="bottom" title="View all your {{ name_plural }}" href="{% url listurl %}">{{ name_plural }}</a>
     {% else %}
-    <a data-toggle="tooltip" data-placement="bottom" title="View all public {{ name_plural }}" href="{% url public_listurl %}">{{ name_plural }}</a>
+    <a data-toggle="tooltip" data-placement="bottom" title="View all public {{ name_plural }}" href="{% url listurl %}">{{ name_plural }}</a>
     {% endif %}
   </li>
-  <li><a data-toggle="tooltip" data-placement="bottom" title="View all {{ object.author.username }}'s {{ name_plural }}" href="{% url listurl object.author.username %}">{{ object.author.username }}</a></li>
+  <li><a data-toggle="tooltip" data-placement="bottom" title="View all {{ object.author.username }}'s {{ name_plural }}" href="{% url listurl %}">{{ object.author.username }}</a></li>
   <li><a title="View the latest version" data-toggle="tooltip" data-placement="bottom" href="{% url viewurl object.author.username object.name %}">{{ object.name }}</a></li>
   <li>{{ object.version }}</li>
 </ol>
diff --git a/beat/web/ui/templatetags/ui_tags.py b/beat/web/ui/templatetags/ui_tags.py
index 318b2788a..1f953f2e1 100644
--- a/beat/web/ui/templatetags/ui_tags.py
+++ b/beat/web/ui/templatetags/ui_tags.py
@@ -58,7 +58,7 @@ def navbar(context):
           (False, ''),
           ('databases', 'databases:list'),
           ('environments', 'backend:list-environments'),
-          ('plotters', 'plotters:plotter-public-list'),
+          ('plotters', 'plotters:list'),
           #('plotterparameters', 'plotters:plotterparameter-public-list'),
           ],
         'user_urls': [
@@ -76,7 +76,7 @@ def navbar(context):
           (False, '', False),
           ('databases', 'databases:list', False),
           ('environments', 'backend:list-environments', False),
-          ('plotters', 'plotters:plotter-list', True),
+          ('plotters', 'plotters:list', False),
           #('plotterparameters', 'plotters:plotterparameter-list', True),
           ],
         }
@@ -108,8 +108,8 @@ def contribution_breadcrumb_plotter(context, obj):
             'request': context['request'],
             'object': obj,
             'name_plural': name_plural,
-            'listurl': name_plural + ':plotter-list',
-            'public_listurl': name_plural + ':plotter-public-list',
+            'listurl': name_plural + ':list',
+            'public_listurl': name_plural + ':list',
             'viewurl': name_plural + ':plotter-view-latest',
            }
 
@@ -163,7 +163,7 @@ def list_tabs(context, user, tab):
             system_tabs=OrderedDict([
               ('databases', 'databases:list'),
               ('environments', 'backend:list-environments'),
-              ('plotters', 'plotters:plotter-public-list'),
+              ('plotters', 'plotters:list'),
               ]),
             )
 
-- 
GitLab