#!/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.shortcuts import get_object_or_404
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import Http404
from .models import Team
#----------------------------------------------------------
[docs]@login_required
def create(request):
"""Creates a new team
The user must be authenticated before it can add a new team
"""
return render(request,
'team/edition.html',
{
'users': User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username'),
})
#----------------------------------------------------------
[docs]@login_required
def edit(request, author_name, name):
"""Edit a team
The user must be authenticated before it can edit a team
"""
if author_name != request.user.username: raise Http404()
# Retrieves the team
team = get_object_or_404(Team,
owner__username__iexact=author_name,
name__iexact=name
)
return render(request,
'team/edition.html',
{
'team': team,
'users': User.objects.exclude(username__in=settings.ACCOUNTS_TO_EXCLUDE_FROM_TEAMS).order_by('username'),
})
#----------------------------------------------------------
[docs]def view(request, author_name, name):
"""displays a team
"""
team = get_object_or_404(Team, name=name, owner__username=author_name)
return render(request,
'team/team.html',
{'team': team})
#----------------------------------------------------------
[docs]def ls(request, author_name):
'''List all accessible teams to the request user'''
if not author_name: return public_ls(request)
author = get_object_or_404(User, username=author_name)
if request.user.is_anonymous():
objects = Team.objects.public().filter(owner=author)
elif request.user.username == author_name:
objects = Team.objects.for_user(author, True)
else:
objects = Team.objects.for_user(request.user, True).filter(owner=author)
return render(request,
'team/list.html',
dict(
objects=objects,
author=author,
owner=(request.user == author),
))
#----------------------------------------------------------
[docs]def public_ls(request):
'''List all accessible teams to the request user'''
return render(request,
'team/list.html',
dict(
objects=Team.objects.public(),
author=request.user, #anonymous
owner=False,
))