From cd664c6399bc0374ef619bc445a79c6e7387199c Mon Sep 17 00:00:00 2001
From: Philip ABBET <philip.abbet@idiap.ch>
Date: Thu, 24 Nov 2016 12:20:20 +0100
Subject: [PATCH] [website] Display the binary algorithms separately from the
 others when sharing an experiment

---
 .../templates/experiments/panels/sharing.html | 36 ++++++++++++++-----
 .../templatetags/experiment_tags.py           | 18 +++++++++-
 2 files changed, 44 insertions(+), 10 deletions(-)
 mode change 100644 => 100755 beat/web/experiments/templatetags/experiment_tags.py

diff --git a/beat/web/experiments/templates/experiments/panels/sharing.html b/beat/web/experiments/templates/experiments/panels/sharing.html
index 7a5a6a898..a9eca7ca4 100644
--- a/beat/web/experiments/templates/experiments/panels/sharing.html
+++ b/beat/web/experiments/templates/experiments/panels/sharing.html
@@ -109,14 +109,14 @@
                 <input id="public-radio" type="radio" name="sharing" value="public" checked="checked" onClick="$('#sharing-options').disable()"/>
                 Public
                 <p class="help">All users will be able to see, use and fork this
-                dataformat</p>
+                experiment</p>
               </label>
             </div>
             <div class="radio">
               <label class="control-label">
                 <input id="shared-radio" type="radio" name="sharing" value="shared" onClick="$('#sharing-options').enable()"/> Shared
                 <p class="help">The users and teams indicated below will be
-                able to see, use and fork this dataformat.</p>
+                able to see, use and fork this experiment.</p>
               </label>
             </div>
           </div>
@@ -163,20 +163,24 @@
           not use any data formats that belong to you.</p>
           {% endif %}
 
-          {% owner_algorithms object as algorithms %}
-          {% if algorithms %}
+          {% owner_source_algorithms object as source_algorithms %}
+          {% owner_binary_algorithms object as binary_algorithms %}
+
+          {% if not source_algorithms and not binary_algorithms %}
+          <p class="help"><i class="fa fa-info-circle"></i> This experiment does
+          not use any algorithms that belong to you.</p>
+          {% endif %}
+
+          {% if source_algorithms %}
           <p>The following algorithms and associated libraries will get the
           same sharing permissions as well (i.e. <strong>readable</strong> and
           executable by third-parties). Unselect those that will remain
           closed-source:</p>
-          {% else %}
-          <p class="help"><i class="fa fa-info-circle"></i> This experiment does
-          not use any algorithms that belong to you.</p>
           {% endif %}
 
           <div class="form-group">
-            {% if algorithms %}
-            {% for algo in algorithms %}
+            {% if source_algorithms %}
+            {% for algo in source_algorithms %}
             <div id="visible-algorithms" class="checkbox{% if algo.get_sharing_display == 'Public' %} disabled{% endif %}" style="left-margin:1em">
               <label>
                 <input type="checkbox" value="{{ algo.fullname }}" checked></input><a target="_blank" href="{{ algo.get_absolute_url }}">{{ algo.fullname }}</a> ({{ algo.get_sharing_display }})
@@ -185,6 +189,20 @@
             {% endfor %}
             {% endif %}
           </div>
+
+          {% if binary_algorithms %}
+          <p>The following binary algorithms will get the
+          same sharing permissions as well (i.e. <strong>readable</strong> and
+          executable by third-parties).</p>
+          {% endif %}
+
+          <div class="form-group">
+            {% if binary_algorithms %}
+            {% for algo in binary_algorithms %}
+            <li><a target="_blank" href="{{ algo.get_absolute_url }}">{{ algo.fullname }}</a> ({{ algo.get_sharing_display }})</li>
+            {% endfor %}
+            {% endif %}
+          </div>
         </div><!-- callout -->
       </form>
     </div><!-- edition -->
diff --git a/beat/web/experiments/templatetags/experiment_tags.py b/beat/web/experiments/templatetags/experiment_tags.py
old mode 100644
new mode 100755
index dd353a412..23444f352
--- a/beat/web/experiments/templatetags/experiment_tags.py
+++ b/beat/web/experiments/templatetags/experiment_tags.py
@@ -277,8 +277,24 @@ def owner_algorithms(obj):
     return obj.referenced_algorithms.filter(author=obj.author)
 
 
+@register.assignment_tag
+def owner_source_algorithms(obj):
+    '''Calculates the user algorithms in source code form for a given experiment'''
+
+    return [ x for x in obj.referenced_algorithms.filter(author=obj.author)
+                     if not x.is_binary() ]
+
+
+@register.assignment_tag
+def owner_binary_algorithms(obj):
+    '''Calculates the user algorithms in binary form for a given experiment'''
+
+    return [ x for x in obj.referenced_algorithms.filter(author=obj.author)
+                     if x.is_binary() ]
+
+
 @register.assignment_tag
 def owner_dataformats(obj):
-    '''Calculates the user dataformats and algorithms for a given attestation'''
+    '''Calculates the user dataformats and algorithms for a given experiment'''
 
     return [k for k in obj.all_needed_dataformats() if k.author == obj.author]
-- 
GitLab