Commit a2905619 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST

[toolchains][views] Remove all edition related views

parent 8c63a8d2
......@@ -25,147 +25,17 @@
# #
###############################################################################
import simplejson as json
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.shortcuts import get_object_or_404
from django.shortcuts import render
from beat.core import prototypes
from ..common.texts import Messages
from ..common.utils import ensure_string
from ..reports.models import Report
from ..team.models import Team
from ..ui.templatetags.markup import restructuredtext
from .models import Toolchain
@login_required
def create(request, name=None):
"""Creates a new toolchain or a new version of an existing toolchain
The user must be authenticated before it can add a new toolchain
"""
parameters = {
"toolchain_author": request.user.username,
"toolchain_name": name,
"toolchain_version": 1,
"short_description": "",
"description": "",
"errors": "",
"edition": False,
"messages": Messages,
}
# Retrieves the existing toolchain (if necessary)
if name is not None:
previous_versions = Toolchain.objects.filter(
author=request.user, name__iexact=name,
).order_by("-version")
if len(previous_versions) == 0:
raise Http404()
previous_version = previous_versions[0]
description = ensure_string(previous_version.description)
parameters["toolchain_version"] = previous_version.version + 1
parameters["declaration"] = previous_version.declaration_string.replace(
"\n", ""
)
parameters["short_description"] = previous_version.short_description
parameters["description"] = description.replace("\n", "\\n")
parameters["html_description"] = restructuredtext(description).replace("\n", "")
parameters["errors"] = (
previous_version.errors.replace("\n", "\\n")
if previous_version.errors is not None
else ""
)
else:
declaration, errors = prototypes.load("toolchain")
parameters["declaration"] = json.dumps(declaration)
return render(request, "toolchains/edition.html", parameters)
@login_required
def fork(request, author, name, version):
"""Creates a new toolchain by forking an existing toolchain
The user must be authenticated before it can add a new toolchain
"""
# Retrieves the forked toolchain
fork_of = get_object_or_404(
Toolchain.objects.for_user(request.user, True),
author__username__iexact=author,
name__iexact=name,
version=int(version),
)
description = ensure_string(fork_of.description)
errors = ensure_string(fork_of.errors)
parameters = {
"toolchain_author": request.user.username,
"toolchain_name": name,
"toolchain_version": 1,
"fork_of": fork_of,
"declaration": fork_of.declaration_string.replace("\n", ""),
"short_description": fork_of.short_description,
"description": description.replace("\n", "\\n"),
"errors": errors.replace("\n", "\\n"),
"edition": False,
"messages": Messages,
}
return render(request, "toolchains/edition.html", parameters)
@login_required
def edit(request, author, name, version):
"""Allows the modification of the toolchain. The Web API is used to retrieve the
details about the toolchain and check the accessibility.
"""
if author != request.user.username:
raise Http404()
# Retrieves the toolchain
toolchain = get_object_or_404(
Toolchain,
author__username__iexact=author,
name__iexact=name,
version=int(version),
)
description = ensure_string(toolchain.description)
errors = ensure_string(toolchain.errors)
# Render the page
return render(
request,
"toolchains/edition.html",
{
"toolchain_author": request.user.username,
"toolchain_name": name,
"toolchain_version": toolchain.version,
"declaration": toolchain.declaration_string.replace("\n", ""),
"short_description": toolchain.short_description,
"description": description.replace("\n", "\\n"),
"html_description": restructuredtext(description).replace("\n", ""),
"errors": errors.replace("\n", "\\n"),
"edition": True,
"messages": Messages,
},
)
def view(request, author, name, version=None):
"""Shows the toolchain. The Web API is used to retrieve the details about
the toolchain and check the accessibility.
......
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