From f70fc000ec055d8a49d13bad151022bfce3b1914 Mon Sep 17 00:00:00 2001 From: TalatCikikci Date: Sun, 28 May 2017 16:42:10 +0300 Subject: [PATCH 1/5] Hotfix for #211 An issue was introduced to the "get_file" method of MultimediaFileView class. This was fixed by reverting the changes. --- heritago/heritages/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/heritago/heritages/views.py b/heritago/heritages/views.py index 3ce23ab..19ba3d2 100644 --- a/heritago/heritages/views.py +++ b/heritago/heritages/views.py @@ -69,8 +69,7 @@ class MultimediaView(generics.RetrieveDestroyAPIView): class MultimediaFileView(ViewSet): - @staticmethod - def get_file(request, multimedia_id): + def get_file(self, request, heritage_id, multimedia_id): try: m = Multimedia.objects.get(pk=multimedia_id) except ObjectDoesNotExist: From 12ee8582b93c452081393880cd62dd39322102d5 Mon Sep 17 00:00:00 2001 From: TalatCikikci Date: Sun, 28 May 2017 18:33:32 +0300 Subject: [PATCH 2/5] Revert "Hotfix for #211" This reverts commit f70fc000ec055d8a49d13bad151022bfce3b1914. --- heritago/heritages/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/heritago/heritages/views.py b/heritago/heritages/views.py index e0a9a99..be9e5a0 100644 --- a/heritago/heritages/views.py +++ b/heritago/heritages/views.py @@ -61,7 +61,8 @@ class MultimediaView(generics.RetrieveDestroyAPIView): class MultimediaFileView(ViewSet): - def get_file(self, request, heritage_id, multimedia_id): + @staticmethod + def get_file(request, multimedia_id): try: m = Multimedia.objects.get(pk=multimedia_id) except ObjectDoesNotExist: From b525268ff614fa1773ea1b85d2c89f05f04f93be Mon Sep 17 00:00:00 2001 From: TalatCikikci Date: Sun, 28 May 2017 20:49:38 +0300 Subject: [PATCH 3/5] target_id is taken directly from the request Target_id is changed so that is stored as it is received in the request. --- heritago/heritages/serializers.py | 2 +- heritago/heritages/views.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/heritago/heritages/serializers.py b/heritago/heritages/serializers.py index 4e64391..2e177f2 100644 --- a/heritago/heritages/serializers.py +++ b/heritago/heritages/serializers.py @@ -169,7 +169,7 @@ def create(self, validated_data): for entry in validated_target: target = AnnotationTarget.objects.create(annotation=annotation, - target_id=self.context["target_id"], + target_id=entry["target_id"], type=entry["type"], format=entry["format"]) selector_data = entry.pop("selector") diff --git a/heritago/heritages/views.py b/heritago/heritages/views.py index be9e5a0..ee45ade 100644 --- a/heritago/heritages/views.py +++ b/heritago/heritages/views.py @@ -78,14 +78,13 @@ def get_queryset(self): queryset = Annotation.objects.all() heritage_id = self.kwargs["heritage_id"] if heritage_id is not None: - queryset = queryset.filter(target__target_id__contains=heritage_id) + queryset = queryset.filter(target__target_id__contains="api/v1/heritages/{}".format(heritage_id)) return queryset else: return NotFound() def get_serializer_context(self): - return {"target_id": self.request.build_absolute_uri(), - "heritage_id": self.kwargs["heritage_id"]} + return {"heritage_id": self.kwargs["heritage_id"]} def list(self, request, *args, **kwargs): keyword = self.request.query_params.get("keyword", None) From 9e4278d5db3b8568da05af0dac5a8e78ec7afdfa Mon Sep 17 00:00:00 2001 From: Talat Cikikci Date: Mon, 29 May 2017 01:01:02 +0300 Subject: [PATCH 4/5] Update views.py --- heritago/heritages/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/heritago/heritages/views.py b/heritago/heritages/views.py index e1e1299..c42878a 100644 --- a/heritago/heritages/views.py +++ b/heritago/heritages/views.py @@ -91,7 +91,8 @@ def get_serializer_context(self): return {"target_id": target_id, "heritage_id": self.kwargs["heritage_id"]} except KeyError: - return {"heritage_id": self.kwargs["heritage_id"]} + pass + return {"heritage_id": self.kwargs["heritage_id"]} def list(self, request, *args, **kwargs): keyword = self.request.query_params.get("keyword", None) From 746e7f9b52bb1fc3dda395de65d6048710c3c6d1 Mon Sep 17 00:00:00 2001 From: TalatCikikci Date: Mon, 29 May 2017 01:43:19 +0300 Subject: [PATCH 5/5] Fixed The Target_id Issue Target_id could not be received from the frontend as "id" due to a framework limitation. Implemented a workaround to be able to parse the "id" sent from frontend. --- heritago/heritages/serializers.py | 4 ++-- heritago/heritages/views.py | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/heritago/heritages/serializers.py b/heritago/heritages/serializers.py index 908095d..543f8e2 100644 --- a/heritago/heritages/serializers.py +++ b/heritago/heritages/serializers.py @@ -173,9 +173,9 @@ def create(self, validated_data): for entry in validated_body: AnnotationBody.objects.create(annotation=annotation, **entry) - for entry in validated_target: + for index, entry in enumerate(validated_target): target = AnnotationTarget.objects.create(annotation=annotation, - target_id=entry["target_id"], + target_id=self.context["target_id"][index], type=entry["type"], format=entry["format"]) selector_data = entry.pop("selector") diff --git a/heritago/heritages/views.py b/heritago/heritages/views.py index ee45ade..e1e1299 100644 --- a/heritago/heritages/views.py +++ b/heritago/heritages/views.py @@ -84,7 +84,14 @@ def get_queryset(self): return NotFound() def get_serializer_context(self): - return {"heritage_id": self.kwargs["heritage_id"]} + try: + target_id = [] + for target in self.request.data["target"]: + target_id.append(target["id"]) + return {"target_id": target_id, + "heritage_id": self.kwargs["heritage_id"]} + except KeyError: + return {"heritage_id": self.kwargs["heritage_id"]} def list(self, request, *args, **kwargs): keyword = self.request.query_params.get("keyword", None)