From 4bacdff72c8044d25066ff95719543a763844e11 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 27 Jan 2023 16:47:20 +0100 Subject: [PATCH] Publishing tags, and fixes. --- src/catalogue/api/serializers.py | 15 ++++++++++++++- src/catalogue/api/views.py | 16 ++++++++++++---- src/catalogue/templatetags/catalogue_tags.py | 4 ++-- src/catalogue/views.py | 3 ++- src/oai/handlers.py | 2 +- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/catalogue/api/serializers.py b/src/catalogue/api/serializers.py index 02a98a154..9baba3461 100644 --- a/src/catalogue/api/serializers.py +++ b/src/catalogue/api/serializers.py @@ -24,7 +24,20 @@ class TagDetailSerializer(serializers.ModelSerializer): class Meta: model = Tag - fields = ['name', 'url', 'sort_key', 'description'] + fields = [ + 'name', 'url', 'sort_key', + 'description', + 'description_pl', + 'plural', 'genre_epoch_specific', + 'adjective_feminine_singular', 'adjective_nonmasculine_plural', + 'genitive', 'collective_noun', + ] + write_only_fields = [ + 'description_pl', + 'plural', 'genre_epoch_specific', + 'adjective_feminine_singular', 'adjective_nonmasculine_plural', + 'genitive', 'collective_noun', + ] class TranslatorSerializer(serializers.Serializer): diff --git a/src/catalogue/api/views.py b/src/catalogue/api/views.py index 5512501c6..c69c246ad 100644 --- a/src/catalogue/api/views.py +++ b/src/catalogue/api/views.py @@ -320,7 +320,7 @@ class TagView(RetrieveAPIView): slug=self.kwargs['slug'] ) except Http404: - if self.request.method == 'PUT': + if self.request.method == 'POST': return Tag( category=self.kwargs['category'], slug=self.kwargs['slug'] @@ -330,10 +330,18 @@ class TagView(RetrieveAPIView): def post(self, request, **kwargs): data = json.loads(request.POST.get('data')) - desc = data['description_pl'] + fields = { + "description_pl": "description_pl", + "plural": "plural", + "is_epoch_specific": "genre_epoch_specific", + "collective_noun": "collective_noun", + "adjective_feminine_singular": "adjective_feminine_singular", + "adjective_nonmasculine_plural": "adjective_nonmasculine_plural", + } obj = self.get_object() - obj.description_pl = desc - obj.save(update_fields=['description_pl'], quick=True) + for data_field, model_field in fields.items(): + setattr(obj, model_field, data.get(data_field, getattr(obj, model_field))) + obj.save(update_fields=fields.values(), quick=True) return Response({}) diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py index 1d5cee0db..b45fc50cf 100644 --- a/src/catalogue/templatetags/catalogue_tags.py +++ b/src/catalogue/templatetags/catalogue_tags.py @@ -131,9 +131,9 @@ def nice_title_from_tags(tags, related_tags): p = [] for sublist in pieces: for item in sublist[:-2]: - p.append(item) + ',' + p.append(item + ',') for item in sublist[-2:-1]: - p.append(item) + ' i' + p.append(item + ' i') p.append(sublist[-1]) return ' '.join(p) diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 8c66af717..9d6598b0d 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -154,13 +154,14 @@ def object_list(request, objects, fragments=None, related_tags=None, tags=None, is_set = len(tags) == 1 and tags[0].category == 'set' is_theme = len(tags) == 1 and tags[0].category == 'theme' + has_theme = any((x.category == 'theme' for x in tags)) new_layout = request.EXPERIMENTS['layout'] if is_set and new_layout.value: template = 'catalogue/2022/set_detail.html' elif is_theme and new_layout.value: template = 'catalogue/2022/theme_detail.html' - elif new_layout.value: + elif new_layout.value and not has_theme: template = 'catalogue/2022/author_detail.html' else: template = 'catalogue/tagged_object_list.html' diff --git a/src/oai/handlers.py b/src/oai/handlers.py index 54a0a20bc..d90a560b7 100644 --- a/src/oai/handlers.py +++ b/src/oai/handlers.py @@ -89,7 +89,7 @@ class Catalogue(common.ResumptionOAIPMH): md = wl_dc_reader(xml) m = md.getMap() if book.parent: - m['isPartOf'] = [str(WLURI.from_slug(book.parent.slug))] + m['isPartOf'] = [str(WLURI(book.parent.slug))] return m def record_for_book(self, book, headers_only=False): -- 2.20.1