From: Radek Czajka Date: Mon, 18 Jul 2022 11:39:39 +0000 (+0200) Subject: Use meta types in editor. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/ed7cd4d7271acd67bf366e4d320f9c49f07a50ea?ds=inline Use meta types in editor. --- diff --git a/requirements/requirements.txt b/requirements/requirements.txt index cf952650..5341b624 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -10,7 +10,7 @@ python-slugify python-docx==0.8.10 Wikidata==0.6.1 -librarian==2.4.6 +librarian==2.4.7 ## Django Django==3.2.14 diff --git a/src/catalogue/urls.py b/src/catalogue/urls.py index 10ef6d00..51bb6601 100644 --- a/src/catalogue/urls.py +++ b/src/catalogue/urls.py @@ -9,4 +9,8 @@ urlpatterns = [ path("", views.CatalogueView.as_view(), name="catalogue"), path("author//", views.AuthorView.as_view(), name="catalogue_author"), path("book//", views.BookView.as_view(), name="catalogue_book"), + + path('terms/epoch/', views.EpochTerms.as_view()), + path('terms/kind/', views.KindTerms.as_view()), + path('terms/genre/', views.GenreTerms.as_view()), ] diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 792ea700..e68c4a28 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -5,6 +5,9 @@ from django.db.models import Prefetch from django.views.generic import DetailView, TemplateView from . import models import documents.models +from rest_framework.generics import ListAPIView +from rest_framework.filters import SearchFilter +from rest_framework import serializers class CatalogueView(TemplateView): @@ -33,3 +36,23 @@ class AuthorView(TemplateView): class BookView(DetailView): model = models.Book + + +class TermSearchFilter(SearchFilter): + search_param = 'term' + + +class Terms(ListAPIView): + filter_backends = [TermSearchFilter] + search_fields = ['name'] + + class serializer_class(serializers.Serializer): + label = serializers.CharField(source='name') + + +class EpochTerms(Terms): + queryset = models.Epoch.objects.all() +class KindTerms(Terms): + queryset = models.Kind.objects.all() +class GenreTerms(Terms): + queryset = models.Genre.objects.all() diff --git a/src/redakcja/static/js/wiki/view_properties.js b/src/redakcja/static/js/wiki/view_properties.js index a7caf10a..3495197c 100644 --- a/src/redakcja/static/js/wiki/view_properties.js +++ b/src/redakcja/static/js/wiki/view_properties.js @@ -243,7 +243,18 @@ pp.appendTo(ig); } - let $aninput = $(""); + let $aninput; + if (field.value_type.widget == 'select') { + $aninput = $(""); + if (field.value_type.autocomplete) { + $aninput.autocomplete(field.value_type.autocomplete); + } + } $aninput.data('edited', $(element)) $aninput.val( $(element).text() diff --git a/src/wlxml/views.py b/src/wlxml/views.py index b951b3c6..87780b79 100644 --- a/src/wlxml/views.py +++ b/src/wlxml/views.py @@ -6,6 +6,8 @@ from . import models from librarian.dcparser import BookInfo from librarian.document import WLDocument from librarian.builders import StandaloneHtmlBuilder +from librarian.meta.types.text import LegimiCategory, Epoch, Kind, Genre, Audience +from depot.legimi import legimi class XslView(TemplateView): @@ -42,21 +44,47 @@ class TagView(DetailView): slug_field = 'name' +VALUE_TYPES = { + LegimiCategory: { + 'widget': 'select', + 'options': list(legimi.CATEGORIES.keys()), + }, + Epoch: { + 'autocomplete': { + 'source': '/catalogue/terms/epoch/', + } + }, + Kind: { + 'autocomplete': { + 'source': '/catalogue/terms/kind/', + } + }, + Genre: { + 'autocomplete': { + 'source': '/catalogue/terms/genre/', + } + }, +} + + class MetaTagsView(View): def get(self, request): - return HttpResponse( - 'let META_FIELDS = ' + json.dumps([ - { - 'name': f.name, - 'required': f.required, - 'multiple': f.multiple, - 'uri': f.uri, - 'value_type': { - 'hasLanguage': f.value_type.has_language, - 'name': f.value_type.__name__, - } + fields = [] + for f in BookInfo.FIELDS: + d = { + 'name': f.name, + 'required': f.required, + 'multiple': f.multiple, + 'uri': f.uri, + 'value_type': { + 'hasLanguage': f.value_type.has_language, + 'name': f.value_type.__name__, } - for f in BookInfo.FIELDS - ]), + } + d['value_type'].update(VALUE_TYPES.get(f.value_type, {})) + fields.append(d) + + return HttpResponse( + 'let META_FIELDS = ' + json.dumps(fields), content_type='text/javascript')