From 1610eb2c8c981232e53cbc58039fd3c00736a652 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 26 Sep 2022 12:48:04 +0200 Subject: [PATCH] Tag description update API --- src/catalogue/api/views.py | 12 +++++++++++- src/catalogue/models/tag.py | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/catalogue/api/views.py b/src/catalogue/api/views.py index 885df24aa..8b9dcd8ae 100644 --- a/src/catalogue/api/views.py +++ b/src/catalogue/api/views.py @@ -289,8 +289,10 @@ class TagCategoryView(ListAPIView): class TagView(RetrieveAPIView): + permission_classes = [DjangoModelPermissionsOrAnonReadOnly] serializer_class = serializers.TagDetailSerializer - + queryset = Tag.objects.all() + def get_object(self): return get_object_or_404( Tag, @@ -298,6 +300,14 @@ class TagView(RetrieveAPIView): slug=self.kwargs['slug'] ) + def post(self, request, **kwargs): + data = json.loads(request.POST.get('data')) + desc = data['description_pl'] + obj = self.get_object() + obj.description_pl = desc + obj.save(update_fields=['description_pl'], quick=True) + return Response({}) + @vary_on_auth # Because of 'liked'. class FragmentList(ListAPIView): diff --git a/src/catalogue/models/tag.py b/src/catalogue/models/tag.py index 5442213c6..acf02529e 100644 --- a/src/catalogue/models/tag.py +++ b/src/catalogue/models/tag.py @@ -101,10 +101,10 @@ class Tag(models.Model): unique_together = (("slug", "category"),) app_label = 'catalogue' - def save(self, *args, **kwargs): + def save(self, *args, quick=False, **kwargs): existing = self.pk and self.category != 'set' ret = super(Tag, self).save(*args, **kwargs) - if existing: + if existing and not quick: self.after_change.send(sender=type(self), instance=self) return ret -- 2.20.1