Source code for beat.web.toolchains.templatetags.toolchain_tags

#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

###############################################################################
#                                                                             #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/           #
# Contact: beat.support@idiap.ch                                              #
#                                                                             #
# This file is part of the beat.web module of the BEAT platform.              #
#                                                                             #
# Commercial License Usage                                                    #
# Licensees holding valid commercial BEAT licenses may use this file in       #
# accordance with the terms contained in a written agreement between you      #
# and Idiap. For further information contact tto@idiap.ch                     #
#                                                                             #
# Alternatively, this file may be used under the terms of the GNU Affero      #
# Public License version 3 as published by the Free Software and appearing    #
# in the file LICENSE.AGPL included in the packaging of this file.            #
# The BEAT platform is distributed in the hope that it will be useful, but    #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  #
# or FITNESS FOR A PARTICULAR PURPOSE.                                        #
#                                                                             #
# You should have received a copy of the GNU Affero Public License along      #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/.           #
#                                                                             #
###############################################################################


import random

from django import template
from django.conf import settings

from ..models import Toolchain

register = template.Library()


[docs]@register.inclusion_tag("toolchains/panels/table.html", takes_context=True) def toolchain_table(context, objects, owner, id): """Composes a toolchain list table This panel primarily exists for user's toolchain list page. Parameters: objects (iterable): An iterable containing Toolchain objects owner (bool): A flag indicating if the list is being created for the owner of his personal list page on the user-microsite or not. 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,)
[docs]@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 This panel primarily exists for showing action buttons for a given toolchain taking into consideration it is being displayed for a given user. Parameters: object (Toolchain): The toolchain object concerned for which the buttons will be drawn. 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,)
[docs]@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 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"], }
[docs]@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 required) Parameters: obj (Toolchain): The toolchain object concerned for which the panel will be drawn. xp (Experiment): The experiment to project on the top of the toolchain 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, }
[docs]@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)] # nosec: B311
[docs]@register.simple_tag(takes_context=True) def visible_toolchains(context): """Calculates the visible toolchains for a given user""" return Toolchain.objects.for_user(context["request"].user, True)
[docs]@register.simple_tag(takes_context=True) def visible_experiments(context, object): """Calculates the visible experiments for a given toolchain and requestor""" return object.experiments.for_user(context["request"].user, True)
# ----------------------------------------------------------------
[docs]@register.inclusion_tag("toolchains/panels/editor.html") def toolchain_editor(id): return { "editor_id": id, }
[docs]@register.inclusion_tag("toolchains/dialogs/import_settings.html") def toolchain_import_settings(id): return { "dialog_id": id, }