Skip to content
Snippets Groups Projects
Commit 921b1e45 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[libraries][api] Replace put with serializer

parent 54200d2f
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !327. Comments created here will be created in the context of that merge request.
......@@ -29,16 +29,20 @@ from .models import Library
from .serializers import LibrarySerializer
from .serializers import FullLibrarySerializer
from .serializers import LibraryCreationSerializer
from .serializers import LibraryModSerializer
from ..code.api import ShareCodeView, RetrieveUpdateDestroyCodeView
from ..code.serializers import CodeDiffSerializer
from ..common.api import (CheckContributionNameView, ListContributionView,
ListCreateContributionView)
from ..common.api import (
CheckContributionNameView,
ListContributionView,
ListCreateContributionView,
)
from ..code.api import DiffView
#----------------------------------------------------------
# ----------------------------------------------------------
class CheckLibraryNameView(CheckContributionNameView):
......@@ -46,10 +50,11 @@ class CheckLibraryNameView(CheckContributionNameView):
This view sanitizes a library name and
checks whether it is already used.
"""
model = Library
#----------------------------------------------------------
# ----------------------------------------------------------
class ShareLibraryView(ShareCodeView):
......@@ -57,21 +62,23 @@ class ShareLibraryView(ShareCodeView):
This view allows to share a library with
other users and/or teams
"""
model = Library
#----------------------------------------------------------
# ----------------------------------------------------------
class ListLibrariesView(ListContributionView):
"""
List all available libraries
"""
model = Library
serializer_class = LibrarySerializer
#----------------------------------------------------------
# ----------------------------------------------------------
class ListCreateLibrariesView(ListCreateContributionView):
......@@ -79,44 +86,33 @@ class ListCreateLibrariesView(ListCreateContributionView):
Read/Write end point that list the libraries available
from a given author and allows the creation of new libraries
"""
model = Library
serializer_class = LibrarySerializer
writing_serializer_class = LibraryCreationSerializer
namespace = 'api_libraries'
namespace = "api_libraries"
#----------------------------------------------------------
# ----------------------------------------------------------
class RetrieveUpdateDestroyLibrariesView(RetrieveUpdateDestroyCodeView):
"""
Read/Write/Delete endpoint for a given library
"""
model = Library
serializer_class = FullLibrarySerializer
writing_serializer_class = LibraryModSerializer
def do_update(self, request, author_name, object_name, version=None):
modified, library = super(RetrieveUpdateDestroyLibrariesView, self).do_update(request, author_name, object_name, version)
if modified:
# Delete existing experiments using the library (code changed)
experiments = []
for item in library.referencing.all():
for algorithm in item.used_by_algorithms.all():
experiments.append(list(set(map(lambda x: x.experiment,
algorithm.blocks.iterator()))))
for experiment in set(experiments): experiment.delete()
return modified, library
#----------------------------------------------------------
# ----------------------------------------------------------
class DiffLibraryView(DiffView):
"""
This view shows the differences between two libraries
"""
model = Library
serializer_class = CodeDiffSerializer
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment