From d22f4296d7e0c48743883c4686e02cb13afe16d4 Mon Sep 17 00:00:00 2001
From: Samuel Gaist <samuel.gaist@idiap.ch>
Date: Fri, 11 Sep 2020 11:53:21 +0200
Subject: [PATCH] [toolchains][templatetags] Pre-commit cleanup

---
 .../toolchains/templatetags/toolchain_tags.py | 88 +++++++++----------
 1 file changed, 40 insertions(+), 48 deletions(-)

diff --git a/beat/web/toolchains/templatetags/toolchain_tags.py b/beat/web/toolchains/templatetags/toolchain_tags.py
index 8aa1ad4df..0eda1314b 100644
--- a/beat/web/toolchains/templatetags/toolchain_tags.py
+++ b/beat/web/toolchains/templatetags/toolchain_tags.py
@@ -36,9 +36,9 @@ from ..models import Toolchain
 register = template.Library()
 
 
-@register.inclusion_tag('toolchains/panels/table.html', takes_context=True)
+@register.inclusion_tag("toolchains/panels/table.html", takes_context=True)
 def toolchain_table(context, objects, owner, id):
-    '''Composes a toolchain list table
+    """Composes a toolchain list table
 
     This panel primarily exists for user's toolchain list page.
 
@@ -50,19 +50,14 @@ def toolchain_table(context, objects, owner, id):
         id: The HTML id to set on the generated table. This is handy for the
           filter functionality normally available on list pages.
 
-    '''
+    """
 
-    return dict(
-        request=context['request'],
-        objects=objects,
-        owner=owner,
-        panel_id=id,
-    )
+    return dict(request=context["request"], objects=objects, owner=owner, panel_id=id,)
 
 
-@register.inclusion_tag('toolchains/panels/actions.html', takes_context=True)
+@register.inclusion_tag("toolchains/panels/actions.html", takes_context=True)
 def toolchain_actions(context, object, display_count):
-    '''Composes the action buttons for a particular toolchain
+    """Composes the action buttons for a particular toolchain
 
     This panel primarily exists for showing action buttons for a given
     toolchain taking into consideration it is being displayed for a given user.
@@ -74,36 +69,32 @@ def toolchain_actions(context, object, display_count):
         display_count (bool): If the set of buttons should include one with the
           number of experiments using this toolchain.
 
-    '''
-    return dict(
-        request=context['request'],
-        object=object,
-        display_count=display_count,
-    )
+    """
+    return dict(request=context["request"], object=object, display_count=display_count,)
 
 
-@register.inclusion_tag('toolchains/panels/sharing.html', takes_context=True)
+@register.inclusion_tag("toolchains/panels/sharing.html", takes_context=True)
 def toolchain_sharing(context, obj):
-    '''Composes the current sharing properties and a form to change them
+    """Composes the current sharing properties and a form to change them
 
     Parameters:
 
         obj (Toolchain): The toolchain object concerned for which the
           sharing panel will be drawn
 
-    '''
+    """
     return {
-        'request': context['request'],
-            'object': obj,
-            'owner': context['request'].user == obj.author,
-            'users': context['users'],
-            'teams': context['teams'],
+        "request": context["request"],
+        "object": obj,
+        "owner": context["request"].user == obj.author,
+        "users": context["users"],
+        "teams": context["teams"],
     }
 
 
-@register.inclusion_tag('toolchains/panels/viewer.html', takes_context=True)
+@register.inclusion_tag("toolchains/panels/viewer.html", takes_context=True)
 def toolchain_viewer(context, obj, xp, id):
-    '''Composes a canvas with the toolchain (no further JS setup is
+    """Composes a canvas with the toolchain (no further JS setup is
     required)
 
     Parameters:
@@ -114,49 +105,50 @@ def toolchain_viewer(context, obj, xp, id):
           components. If not given, just draw the toolchain.
         id (str): The id of the canvas element that will be created
 
-    '''
+    """
     return {
-        'request': context['request'],
-            'object': obj,
-            'xp': xp,
-            'panel_id': id,
-            'URL_PREFIX': settings.URL_PREFIX,
+        "request": context["request"],
+        "object": obj,
+        "xp": xp,
+        "panel_id": id,
+        "URL_PREFIX": settings.URL_PREFIX,
     }
 
 
 @register.simple_tag(takes_context=True)
 def random_toolchain(context):
-    '''Returns a random toolchain that is visible to the current user'''
-
-    candidates = Toolchain.objects.for_user(context['request'].user, True)
-    return candidates[random.randint(0, candidates.count()-1)]
+    """Returns a random toolchain that is visible to the current user"""
 
+    candidates = Toolchain.objects.for_user(context["request"].user, True)
+    return candidates[random.randint(0, candidates.count() - 1)]  # nosec: B311
 
 
 @register.simple_tag(takes_context=True)
 def visible_toolchains(context):
-    '''Calculates the visible toolchains for a given user'''
+    """Calculates the visible toolchains for a given user"""
 
-    return Toolchain.objects.for_user(context['request'].user, True)
+    return Toolchain.objects.for_user(context["request"].user, True)
 
 
 @register.simple_tag(takes_context=True)
 def visible_experiments(context, object):
-    '''Calculates the visible experiments for a given toolchain and requestor'''
+    """Calculates the visible experiments for a given toolchain and requestor"""
 
-    return object.experiments.for_user(context['request'].user, True)
+    return object.experiments.for_user(context["request"].user, True)
 
 
-#----------------------------------------------------------------
+# ----------------------------------------------------------------
 
 
-@register.inclusion_tag('toolchains/panels/editor.html')
+@register.inclusion_tag("toolchains/panels/editor.html")
 def toolchain_editor(id):
-    return { 'editor_id': id,
-           }
+    return {
+        "editor_id": id,
+    }
 
 
-@register.inclusion_tag('toolchains/dialogs/import_settings.html')
+@register.inclusion_tag("toolchains/dialogs/import_settings.html")
 def toolchain_import_settings(id):
-    return { 'dialog_id': id,
-           }
+    return {
+        "dialog_id": id,
+    }
-- 
GitLab