From: Radek Czajka Date: Fri, 22 Jul 2022 10:56:13 +0000 (+0200) Subject: Metadata editing: auto-add record and more suggestions. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/360d9d37f72b1c6e2edb83c3a0218e55578134f3?ds=sidebyside;hp=ed7cd4d7271acd67bf366e4d320f9c49f07a50ea Metadata editing: auto-add record and more suggestions. --- diff --git a/src/catalogue/models.py b/src/catalogue/models.py index 75726a47..b0d3697b 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -63,6 +63,10 @@ class Author(WikidataMixin, models.Model): def get_absolute_url(self): return reverse("catalogue_author", args=[self.slug]) + @property + def name(self): + return f"{self.last_name}, {self.first_name}" + @property def pd_year(self): if self.year_of_death: @@ -160,6 +164,10 @@ class Book(WikidataMixin, models.Model): def get_absolute_url(self): return reverse("catalogue_book", args=[self.slug]) + + @property + def wluri(self): + return f'https://wolnelektury.pl/katalog/lektura/{self.slug}/' def authors_str(self): return ", ".join(str(author) for author in self.authors.all()) diff --git a/src/catalogue/urls.py b/src/catalogue/urls.py index 51bb6601..2b4301bf 100644 --- a/src/catalogue/urls.py +++ b/src/catalogue/urls.py @@ -13,4 +13,9 @@ urlpatterns = [ path('terms/epoch/', views.EpochTerms.as_view()), path('terms/kind/', views.KindTerms.as_view()), path('terms/genre/', views.GenreTerms.as_view()), + path('terms/wluri/', views.WLURITerms.as_view()), + path('terms/book_title/', views.BookTitleTerms.as_view()), + path('terms/author/', views.AuthorTerms.as_view()), + + path('terms/editor/', views.EditorTerms.as_view()), ] diff --git a/src/catalogue/views.py b/src/catalogue/views.py index e68c4a28..6d4a2249 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -2,6 +2,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.db.models import Prefetch +from django.contrib.auth.models import User from django.views.generic import DetailView, TemplateView from . import models import documents.models @@ -56,3 +57,32 @@ class KindTerms(Terms): queryset = models.Kind.objects.all() class GenreTerms(Terms): queryset = models.Genre.objects.all() + +class AuthorTerms(Terms): + search_fields = ['first_name', 'last_name'] + queryset = models.Author.objects.all() + +class EditorTerms(Terms): + search_fields = ['first_name', 'last_name', 'username'] + queryset = User.objects.all() + + class serializer_class(serializers.Serializer): + label = serializers.SerializerMethodField() + + def get_label(self, obj): + return f'{obj.last_name}, {obj.first_name}' + +class BookTitleTerms(Terms): + queryset = models.Book.objects.all() + search_fields = ['title', 'slug'] + + class serializer_class(serializers.Serializer): + label = serializers.CharField(source='title') + +class WLURITerms(Terms): + queryset = models.Book.objects.all() + search_fields = ['title', 'slug'] + + class serializer_class(serializers.Serializer): + label = serializers.CharField(source='wluri') + diff --git a/src/redakcja/static/js/wiki/view_properties.js b/src/redakcja/static/js/wiki/view_properties.js index 3495197c..1fff64fe 100644 --- a/src/redakcja/static/js/wiki/view_properties.js +++ b/src/redakcja/static/js/wiki/view_properties.js @@ -119,9 +119,24 @@ if (field.value_type.hasLanguage) { span.attr('x-a-xml-lang', 'pl'); } - span.appendTo( - $("> [x-node='RDF'] > [x-node='Description']", self.$edited) - ); + + rdf = $("> [x-node='RDF']", self.$edited); + if (!rdf.length) { + rdf = $(""); + self.$edited.prepend(rdf); + self.$edited.prepend('\n '); + + } + rdfdesc = $("> [x-node='Description']", rdf); + if (!rdfdesc.length) { + rdfdesc = $(""); + rdf.prepend(rdfdesc); + rdf.prepend('\n '); + rdfdesc.append('\n '); + rdf.append('\n '); + } + span.appendTo(rdfdesc); + rdfdesc.append('\n '); self.displayMetaProperty($fg); diff --git a/src/redakcja/static/js/wiki/wikiapi.js b/src/redakcja/static/js/wiki/wikiapi.js index 4e3cd2c6..b9d36bea 100644 --- a/src/redakcja/static/js/wiki/wikiapi.js +++ b/src/redakcja/static/js/wiki/wikiapi.js @@ -69,6 +69,7 @@ this.galleryLink = $("*[data-key='gallery']", meta).text(); this.galleryStart = parseInt($("*[data-key='gallery-start']", meta).text()); + this.fullUri = $("*[data-key='full-uri']", meta).text(); var diff = $("*[data-key='diff']", meta).text(); if (diff) { diff --git a/src/wiki/templates/wiki/document_details.html b/src/wiki/templates/wiki/document_details.html index 4455e4d6..f3efc62e 100644 --- a/src/wiki/templates/wiki/document_details.html +++ b/src/wiki/templates/wiki/document_details.html @@ -49,9 +49,14 @@ {% endblock %} {% block dialogs %} - {% include "wiki/save_dialog.html" %} - {% include "wiki/revert_dialog.html" %} - {% if can_pubmark %} - {% include "wiki/pubmark_dialog.html" %} - {% endif %} + {% include "wiki/save_dialog.html" %} + {% include "wiki/revert_dialog.html" %} + {% if can_pubmark %} + {% include "wiki/pubmark_dialog.html" %} + {% endif %} +{% endblock %} + + +{% block meta-extra %} + {{ chunk.book.correct_about }} {% endblock %} diff --git a/src/wlxml/views.py b/src/wlxml/views.py index 87780b79..281ced5d 100644 --- a/src/wlxml/views.py +++ b/src/wlxml/views.py @@ -6,6 +6,7 @@ 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 from depot.legimi import legimi @@ -64,9 +65,62 @@ VALUE_TYPES = { '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 = [] @@ -81,7 +135,15 @@ class MetaTagsView(View): 'name': f.value_type.__name__, } } - d['value_type'].update(VALUE_TYPES.get(f.value_type, {})) + d['value_type'].update( + VALUE_TYPES.get( + f.value_type, + VALUE_TYPES.get( + f.name, + {} + ) + ) + ) fields.append(d) return HttpResponse(