Use meta types in editor.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 18 Jul 2022 11:39:39 +0000 (13:39 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 18 Jul 2022 11:39:39 +0000 (13:39 +0200)
requirements/requirements.txt
src/catalogue/urls.py
src/catalogue/views.py
src/redakcja/static/js/wiki/view_properties.js
src/wlxml/views.py

index cf95265..5341b62 100644 (file)
@@ -10,7 +10,7 @@ python-slugify
 python-docx==0.8.10
 Wikidata==0.6.1
 
 python-docx==0.8.10
 Wikidata==0.6.1
 
-librarian==2.4.6
+librarian==2.4.7
 
 ## Django
 Django==3.2.14
 
 ## Django
 Django==3.2.14
index 10ef6d0..51bb660 100644 (file)
@@ -9,4 +9,8 @@ urlpatterns = [
     path("", views.CatalogueView.as_view(), name="catalogue"),
     path("author/<slug:slug>/", views.AuthorView.as_view(), name="catalogue_author"),
     path("book/<slug:slug>/", views.BookView.as_view(), name="catalogue_book"),
     path("", views.CatalogueView.as_view(), name="catalogue"),
     path("author/<slug:slug>/", views.AuthorView.as_view(), name="catalogue_author"),
     path("book/<slug:slug>/", 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()),
 ]
 ]
index 792ea70..e68c4a2 100644 (file)
@@ -5,6 +5,9 @@ from django.db.models import Prefetch
 from django.views.generic import DetailView, TemplateView
 from . import models
 import documents.models
 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):
 
 
 class CatalogueView(TemplateView):
@@ -33,3 +36,23 @@ class AuthorView(TemplateView):
 
 class BookView(DetailView):
     model = models.Book
 
 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()
index a7caf10..3495197 100644 (file)
             pp.appendTo(ig);
         }
 
             pp.appendTo(ig);
         }
 
-        let $aninput = $("<input class='form-control'>");
+        let $aninput;
+        if (field.value_type.widget == 'select') {
+            $aninput = $("<select class='form-control'>");
+            $.each(field.value_type.options, function() {
+                $("<option>").text(this).appendTo($aninput);
+            })
+        } else {
+            $aninput = $("<input class='form-control'>");
+            if (field.value_type.autocomplete) {
+                $aninput.autocomplete(field.value_type.autocomplete);
+            }
+        }
         $aninput.data('edited', $(element))
         $aninput.val(
             $(element).text()
         $aninput.data('edited', $(element))
         $aninput.val(
             $(element).text()
index b951b3c..87780b7 100644 (file)
@@ -6,6 +6,8 @@ from . import models
 from librarian.dcparser import BookInfo
 from librarian.document import WLDocument
 from librarian.builders import StandaloneHtmlBuilder
 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):
 
 
 class XslView(TemplateView):
@@ -42,21 +44,47 @@ class TagView(DetailView):
     slug_field = 'name'
 
 
     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):
 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')
     
             content_type='text/javascript')