diff --git a/beat/web/dataformats/templatetags/dataformat_tags.py b/beat/web/dataformats/templatetags/dataformat_tags.py index e040e15e1549655ecd2ff4d933a603520408989c..a938ded6d42366cc57cb19be43f3df66aaaaa0d5 100644 --- a/beat/web/dataformats/templatetags/dataformat_tags.py +++ b/beat/web/dataformats/templatetags/dataformat_tags.py @@ -27,18 +27,20 @@ from django import template -from django.conf import settings -from ...common.texts import Messages as Texts -from ...algorithms.models import Algorithm -from ...databases.models import Database, DatabaseProtocol, DatabaseSet, DatabaseSetTemplate +from ...algorithms.models import Algorithm +from ...common.texts import Messages as Texts +from ...databases.models import Database +from ...databases.models import DatabaseProtocol +from ...databases.models import DatabaseSet +from ...databases.models import DatabaseSetTemplate register = template.Library() -@register.inclusion_tag('dataformats/panels/table.html', takes_context=True) +@register.inclusion_tag("dataformats/panels/table.html", takes_context=True) def dataformat_table(context, objects, owner, id): - '''Composes a dataformat list table + """Composes a dataformat list table This panel primarily exists for user's dataformat list page. @@ -50,19 +52,14 @@ def dataformat_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('dataformats/panels/actions.html', takes_context=True) +@register.inclusion_tag("dataformats/panels/actions.html", takes_context=True) def dataformat_actions(context, object, display_count): - '''Composes the action buttons for a particular dataformat + """Composes the action buttons for a particular dataformat This panel primarily exists for showing action buttons for a given dataformat taking into consideration it is being displayed for a given user. @@ -74,75 +71,101 @@ def dataformat_actions(context, object, display_count): display_count (bool): If the set of buttons should include one with the number of experiments using this dataformat. - ''' - 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('dataformats/panels/sharing.html', takes_context=True) +@register.inclusion_tag("dataformats/panels/sharing.html", takes_context=True) def dataformat_sharing(context, object): - '''Composes the current sharing properties and a form to change them + """Composes the current sharing properties and a form to change them Parameters: object (DataFormat): The dataformat object concerned for which the buttons will be drawn. - ''' + """ return dict( - request=context['request'], + request=context["request"], object=object, - users=context['users'], - teams=context['teams'], + users=context["users"], + teams=context["teams"], ) -@register.inclusion_tag('dataformats/panels/editor.html', takes_context=True) +@register.inclusion_tag("dataformats/panels/editor.html", takes_context=True) def dataformat_editor(context, obj): return { - 'owner': context['request'].user == obj.author, - 'object': obj, - 'texts': Texts, + "owner": context["request"].user == obj.author, + "object": obj, + "texts": Texts, } @register.simple_tag(takes_context=True) def visible_referrer_dataformats(context, obj): - '''Calculates the visible usage for a given dataformat and requestor''' + """Calculates the visible usage for a given dataformat and requestor""" - return obj.referencing.for_user(context['request'].user, True).order_by('-creation_date').distinct() + return ( + obj.referencing.for_user(context["request"].user, True) + .order_by("-creation_date") + .distinct() + ) @register.simple_tag(takes_context=True) def visible_referrer_algorithms(context, obj): - '''Calculates the visible usage for a given dataformat and requestor''' + """Calculates the visible usage for a given dataformat and requestor""" - algorithms = Algorithm.objects.for_user(context['request'].user, True).filter(endpoints__in=obj.algorithm_endpoints.all()).order_by('-creation_date').distinct() + algorithms = ( + Algorithm.objects.for_user(context["request"].user, True) + .filter(endpoints__in=obj.algorithm_endpoints.all()) + .order_by("-creation_date") + .distinct() + ) # analysis algorithms - potential_analyzers = Algorithm.objects.for_user(context['request'].user, True).exclude(result_dataformat=None).order_by('-creation_date').distinct() + potential_analyzers = ( + Algorithm.objects.for_user(context["request"].user, True) + .exclude(result_dataformat=None) + .order_by("-creation_date") + .distinct() + ) analyzers = set() for k in potential_analyzers: - if obj in k.all_referenced_result_dataformats(): analyzers.add(k) + if obj in k.all_referenced_result_dataformats(): + analyzers.add(k) - return sorted(set(algorithms) | analyzers, - key=lambda x: x.creation_date, reverse=True) + return sorted( + set(algorithms) | analyzers, key=lambda x: x.creation_date, reverse=True + ) @register.simple_tag(takes_context=True) def visible_referrer_databases(context, obj): - '''Calculates the visible usage for a given dataformat and requestor''' - - return Database.objects.filter(protocols__in=DatabaseProtocol.objects.filter(sets__in=DatabaseSet.objects.filter(template__in=DatabaseSetTemplate.objects.filter(outputs__in=obj.database_outputs.all())))).order_by('-creation_date').distinct() + """Calculates the visible usage for a given dataformat and requestor""" + + return ( + Database.objects.filter( + protocols__in=DatabaseProtocol.objects.filter( + sets__in=DatabaseSet.objects.filter( + template__in=DatabaseSetTemplate.objects.filter( + outputs__in=obj.database_outputs.all() + ) + ) + ) + ) + .order_by("-creation_date") + .distinct() + ) @register.simple_tag(takes_context=True) def visible_referrers_count(context, obj): - '''Calculates the visible usage for a given dataformat and requestor''' + """Calculates the visible usage for a given dataformat and requestor""" - return visible_referrer_dataformats(context, obj).count() + \ - len(visible_referrer_algorithms(context, obj)) + \ - visible_referrer_databases(context, obj).count() + return ( + visible_referrer_dataformats(context, obj).count() + + len(visible_referrer_algorithms(context, obj)) + + visible_referrer_databases(context, obj).count() + )