Skip to content
Snippets Groups Projects
Commit 2b450f9b authored by Samuel GAIST's avatar Samuel GAIST Committed by Flavio TARSETTI
Browse files

[dataformats][templatetags] Pre-commit cleanup

parent 2cfd8b58
No related branches found
No related tags found
2 merge requests!352Cleanup dataformats,!342Django 3 migration
...@@ -27,18 +27,20 @@ ...@@ -27,18 +27,20 @@
from django import template 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 = 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): 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. This panel primarily exists for user's dataformat list page.
...@@ -50,19 +52,14 @@ def dataformat_table(context, objects, owner, id): ...@@ -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 id: The HTML id to set on the generated table. This is handy for the
filter functionality normally available on list pages. filter functionality normally available on list pages.
''' """
return dict( return dict(request=context["request"], objects=objects, owner=owner, panel_id=id,)
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): 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 This panel primarily exists for showing action buttons for a given
dataformat taking into consideration it is being displayed for a given user. dataformat taking into consideration it is being displayed for a given user.
...@@ -74,75 +71,101 @@ def dataformat_actions(context, object, display_count): ...@@ -74,75 +71,101 @@ def dataformat_actions(context, object, display_count):
display_count (bool): If the set of buttons should include one with the display_count (bool): If the set of buttons should include one with the
number of experiments using this dataformat. number of experiments using this dataformat.
''' """
return dict( return dict(request=context["request"], object=object, display_count=display_count,)
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): 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: Parameters:
object (DataFormat): The dataformat object concerned for which the object (DataFormat): The dataformat object concerned for which the
buttons will be drawn. buttons will be drawn.
''' """
return dict( return dict(
request=context['request'], request=context["request"],
object=object, object=object,
users=context['users'], users=context["users"],
teams=context['teams'], 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): def dataformat_editor(context, obj):
return { return {
'owner': context['request'].user == obj.author, "owner": context["request"].user == obj.author,
'object': obj, "object": obj,
'texts': Texts, "texts": Texts,
} }
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def visible_referrer_dataformats(context, obj): 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) @register.simple_tag(takes_context=True)
def visible_referrer_algorithms(context, obj): 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 # 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() analyzers = set()
for k in potential_analyzers: 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, return sorted(
key=lambda x: x.creation_date, reverse=True) set(algorithms) | analyzers, key=lambda x: x.creation_date, reverse=True
)
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def visible_referrer_databases(context, obj): def visible_referrer_databases(context, obj):
'''Calculates the visible usage for a given dataformat and requestor''' """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() 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) @register.simple_tag(takes_context=True)
def visible_referrers_count(context, obj): 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() + \ return (
len(visible_referrer_algorithms(context, obj)) + \ visible_referrer_dataformats(context, obj).count()
visible_referrer_databases(context, obj).count() + len(visible_referrer_algorithms(context, obj))
+ visible_referrer_databases(context, obj).count()
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment