From: Radek Czajka Date: Mon, 26 Sep 2022 10:48:04 +0000 (+0200) Subject: Tag description update API X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/1610eb2c8c981232e53cbc58039fd3c00736a652?ds=inline Tag description update API --- 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