Commit 93554f1e authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST

[libraries][views] Remove all edition related views

parent 43300dd4
......@@ -27,155 +27,15 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import Http404
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.views.decorators.csrf import csrf_protect
from ..common.texts import Messages
from ..team.models import Team
from .models import Library
@csrf_protect
@login_required
def create(request):
"""Creates a new library.
The user must be authenticated before it can add a new library
"""
visible_libraries = Library.objects.from_author_and_public(
request.user, request.user.username
).order_by("-creation_date")
return render(
request,
"libraries/edition.html",
dict(op="new", texts=Messages, visible_libraries=visible_libraries,),
)
@csrf_protect
@login_required
def new_version(request, name):
"""Creates a new version of a library.
The user must be authenticated before it can add a new library
"""
previous_version = Library.objects.filter(
author=request.user, name__iexact=name
).order_by("-version")
if not previous_version:
raise Http404()
visible_libraries = Library.objects.from_author_and_public(
request.user, request.user.username
).order_by("-creation_date")
return render(
request,
"libraries/edition.html",
dict(
op="new-version",
texts=Messages,
library=previous_version[0],
visible_libraries=visible_libraries,
),
)
@csrf_protect
@login_required
def fork(request, author_name, name, version):
"""Creates a new library by forking an existing library
Answers to the following URLs:
<libraries>/fork/<author>/<name>/<version>/
The user must be authenticated before it can fork a library
"""
# Retrieves the forked library based on user accessible libraries
fork_of = get_object_or_404(
Library.objects.for_user(request.user, True),
author__username__iexact=author_name,
name__iexact=name,
version=int(version),
)
# The only case a user can't fork an library is if it's usable rather
# than shared
if fork_of.sharing == Library.USABLE and fork_of.author != request.user:
raise Http404()
visible_libraries = Library.objects.from_author_and_public(
request.user, request.user.username
).order_by("-creation_date")
return render(
request,
"libraries/edition.html",
dict(
op="fork",
texts=Messages,
library=fork_of,
visible_libraries=visible_libraries,
),
)
# ----------------------------------------------------------
@login_required
def edit(request, author_name, name, version):
"""Allows the modification of the library
The user must be authenticated before it can edit a library
"""
# Retrieves the library
library = get_object_or_404(
Library, author__username=author_name, name__iexact=name, version=int(version)
)
# only author can edit it
if library.author != request.user:
raise Http404()
if not library.modifiable():
return HttpResponseForbidden(
"Library %s is not modifiable" % library.fullname()
)
visible_libraries = (
Library.objects.from_author_and_public(request.user, request.user.username)
.exclude(id=library.id)
.order_by("-creation_date")
)
return render(
request,
"libraries/edition.html",
dict(
op="edit",
texts=Messages,
library=library,
visible_libraries=visible_libraries,
),
)
# ----------------------------------------------------------
def view(request, author_name, name, version=None):
"""Shows the library"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment