Source code for beat.web.experiments.views

#!/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/.           #
#                                                                             #
###############################################################################

from django.conf import settings
from django.contrib.auth.models import User
from django.db.models.functions import Coalesce
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.shortcuts import render

from ..team.models import Team
from .models import Experiment


[docs]def view( request, author_name, toolchain_author_name, toolchain_name, toolchain_version, name ): """Views an experiment no matter its present state""" # Retrieve the experiment experiment = get_object_or_404( Experiment, author__username=author_name, toolchain__author__username=toolchain_author_name, toolchain__name=toolchain_name, toolchain__version=toolchain_version, name=name, ) # Check that the user can access it (has_access, accessibility) = experiment.accessibility_for(request.user) if not (has_access): raise Http404() # Users the object can be shared with users = User.objects.exclude( username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS ).order_by("username") # The experiment was already done, show results return render( request, "experiments/view.html", { "experiment": experiment, "owner": experiment.author == request.user, "users": users, "teams": Team.objects.for_user(request.user, True), }, )
# ----------------------------------------------------------
[docs]def ls(request, author_name): """List all accessible experiments to the request user""" if not author_name: return public_ls(request) # check that the user exists on the system author = get_object_or_404(User, username=author_name) # orders so that experiments that the latest information is displayed first objects = ( Experiment.objects.from_author_and_public(request.user, author_name) .annotate(updated=Coalesce("end_date", "start_date", "creation_date")) .order_by("-updated") ) if request.user.is_anonymous: objects = objects.exclude(status=Experiment.PENDING) owner = request.user == author return render( request, "experiments/list.html", dict(objects=objects, author=author, owner=owner,), )
# ----------------------------------------------------------
[docs]def public_ls(request): """List all publicly accessible experiments""" # orders so that recent objects are displayed first objects = ( Experiment.objects.public() .exclude(status=Experiment.PENDING) .annotate(updated=Coalesce("end_date", "start_date", "creation_date")) .order_by("-updated") ) return render( request, "experiments/list.html", dict(objects=objects, author=request.user, owner=False,), # anonymous )