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 ...@@ -29,16 +29,20 @@ from .models import Library
from .serializers import LibrarySerializer from .serializers import LibrarySerializer
from .serializers import FullLibrarySerializer from .serializers import FullLibrarySerializer
from .serializers import LibraryCreationSerializer from .serializers import LibraryCreationSerializer
from .serializers import LibraryModSerializer
from ..code.api import ShareCodeView, RetrieveUpdateDestroyCodeView from ..code.api import ShareCodeView, RetrieveUpdateDestroyCodeView
from ..code.serializers import CodeDiffSerializer from ..code.serializers import CodeDiffSerializer
from ..common.api import (CheckContributionNameView, ListContributionView, from ..common.api import (
ListCreateContributionView) CheckContributionNameView,
ListContributionView,
ListCreateContributionView,
)
from ..code.api import DiffView from ..code.api import DiffView
#---------------------------------------------------------- # ----------------------------------------------------------
class CheckLibraryNameView(CheckContributionNameView): class CheckLibraryNameView(CheckContributionNameView):
...@@ -46,10 +50,11 @@ class CheckLibraryNameView(CheckContributionNameView): ...@@ -46,10 +50,11 @@ class CheckLibraryNameView(CheckContributionNameView):
This view sanitizes a library name and This view sanitizes a library name and
checks whether it is already used. checks whether it is already used.
""" """
model = Library model = Library
#---------------------------------------------------------- # ----------------------------------------------------------
class ShareLibraryView(ShareCodeView): class ShareLibraryView(ShareCodeView):
...@@ -57,21 +62,23 @@ class ShareLibraryView(ShareCodeView): ...@@ -57,21 +62,23 @@ class ShareLibraryView(ShareCodeView):
This view allows to share a library with This view allows to share a library with
other users and/or teams other users and/or teams
""" """
model = Library model = Library
#---------------------------------------------------------- # ----------------------------------------------------------
class ListLibrariesView(ListContributionView): class ListLibrariesView(ListContributionView):
""" """
List all available libraries List all available libraries
""" """
model = Library model = Library
serializer_class = LibrarySerializer serializer_class = LibrarySerializer
#---------------------------------------------------------- # ----------------------------------------------------------
class ListCreateLibrariesView(ListCreateContributionView): class ListCreateLibrariesView(ListCreateContributionView):
...@@ -79,44 +86,33 @@ class ListCreateLibrariesView(ListCreateContributionView): ...@@ -79,44 +86,33 @@ class ListCreateLibrariesView(ListCreateContributionView):
Read/Write end point that list the libraries available Read/Write end point that list the libraries available
from a given author and allows the creation of new libraries from a given author and allows the creation of new libraries
""" """
model = Library model = Library
serializer_class = LibrarySerializer serializer_class = LibrarySerializer
writing_serializer_class = LibraryCreationSerializer writing_serializer_class = LibraryCreationSerializer
namespace = 'api_libraries' namespace = "api_libraries"
#---------------------------------------------------------- # ----------------------------------------------------------
class RetrieveUpdateDestroyLibrariesView(RetrieveUpdateDestroyCodeView): class RetrieveUpdateDestroyLibrariesView(RetrieveUpdateDestroyCodeView):
""" """
Read/Write/Delete endpoint for a given library Read/Write/Delete endpoint for a given library
""" """
model = Library model = Library
serializer_class = FullLibrarySerializer 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): class DiffLibraryView(DiffView):
""" """
This view shows the differences between two libraries This view shows the differences between two libraries
""" """
model = Library model = Library
serializer_class = CodeDiffSerializer 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