X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b9166b62220208f49bfd3521e547d60d377ab7c1..17ed87c493556adae66975e6cee1454b74e0c904:/src/wlxml/views.py?ds=sidebyside diff --git a/src/wlxml/views.py b/src/wlxml/views.py index 9a2a046b..ebc837dc 100644 --- a/src/wlxml/views.py +++ b/src/wlxml/views.py @@ -1,8 +1,14 @@ from io import BytesIO -from django.views.generic import TemplateView, ListView, DetailView +import json +from django.http import HttpResponse +from django.views.generic import TemplateView, ListView, DetailView, View from . import models +from librarian.dcparser import BookInfo from librarian.document import WLDocument from librarian.builders import StandaloneHtmlBuilder +from librarian.meta.types.wluri import WLURI +from librarian.meta.types.text import LegimiCategory, Epoch, Kind, Genre, Audience, ThemaCategory +from depot.legimi import legimi class XslView(TemplateView): @@ -15,6 +21,12 @@ class XslView(TemplateView): for t in models.Tag.objects.all(): tags.setdefault(t.type, []).append(t.name) ctx['tags'] = tags + ctx['namespaces'] = { + "http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf", + "http://purl.org/dc/elements/1.1/": "dc", + "http://www.w3.org/XML/1998/namespace": "xml", + "": "wl", + } return ctx @@ -32,3 +44,115 @@ class TagView(DetailView): queryset = models.Tag.objects.all() slug_field = 'name' + +VALUE_TYPES = { + LegimiCategory: { + 'widget': 'select', + 'options': [''] + list(legimi.CATEGORIES.keys()), + }, + ThemaCategory: { + 'autocomplete': { + 'source': '/catalogue/terms/thema/', + } + }, + Epoch: { + 'autocomplete': { + 'source': '/catalogue/terms/epoch/', + } + }, + Kind: { + 'autocomplete': { + 'source': '/catalogue/terms/kind/', + } + }, + Genre: { + 'autocomplete': { + 'source': '/catalogue/terms/genre/', + } + }, + WLURI: { + "autocomplete": { + "source": "/catalogue/terms/wluri/", + } + }, + "authors": { + "autocomplete": { + "source": "/catalogue/terms/author/", + } + }, + "translators": { + "autocomplete": { + "source": "/catalogue/terms/author/", + } + }, + "editors": { + "autocomplete": { + "source": "/catalogue/terms/editor/", + } + }, + "technical_editors": { + "autocomplete": { + "source": "/catalogue/terms/editor/", + } + }, + "type": { + "autocomplete": { + "source": ["text"] + } + }, + "title": { + "autocomplete": { + "source": "/catalogue/terms/book_title/", + } + }, + + "language": { + 'widget': 'select', + 'options': [ + '', + 'pol', + 'eng', + 'fre', + 'ger', + 'lit', + ], + }, + "publisher": { + "autocomplete": { + "source": ["Fundacja Nowoczesna Polska"] + } + }, + +} + + + +class MetaTagsView(View): + def get(self, request): + 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__, + } + } + d['value_type'].update( + VALUE_TYPES.get( + f.value_type, + VALUE_TYPES.get( + f.name, + {} + ) + ) + ) + fields.append(d) + + return HttpResponse( + 'let META_FIELDS = ' + json.dumps(fields), + content_type='text/javascript') +