python-docx==0.8.10
Wikidata==0.6.1
-librarian==2.4.6
+librarian==2.4.7
## Django
Django==3.2.14
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()),
]
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 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()
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()
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):
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')