Metadata editing: auto-add record and more suggestions.
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 22 Jul 2022 10:56:13 +0000 (12:56 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 22 Jul 2022 10:56:13 +0000 (12:56 +0200)
src/catalogue/models.py
src/catalogue/urls.py
src/catalogue/views.py
src/redakcja/static/js/wiki/view_properties.js
src/redakcja/static/js/wiki/wikiapi.js
src/wiki/templates/wiki/document_details.html
src/wlxml/views.py

index 75726a4..b0d3697 100644 (file)
@@ -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())
index 51bb660..2b4301b 100644 (file)
@@ -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()),
 ]
index e68c4a2..6d4a224 100644 (file)
@@ -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')
+
index 3495197..1fff64f 100644 (file)
                 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 = $("<span x-node='RDF' x-ns='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>");
+                    self.$edited.prepend(rdf); 
+                    self.$edited.prepend('\n  ');
+                   
+                }
+                rdfdesc = $("> [x-node='Description']", rdf);
+                if (!rdfdesc.length) {
+                    rdfdesc = $("<span x-node='Description' x-ns='http://www.w3.org/1999/02/22-rdf-syntax-ns#' x-a-rdf-about='" + self.doc.fullUri + "'>");
+                    rdf.prepend(rdfdesc);
+                    rdf.prepend('\n    ');
+                    rdfdesc.append('\n    ');
+                    rdf.append('\n  ');
+                }
+                span.appendTo(rdfdesc);
+                rdfdesc.append('\n    ');
 
                 self.displayMetaProperty($fg);
                 
index 4e3cd2c..b9d36be 100644 (file)
@@ -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) {
index 4455e4d..f3efc62 100644 (file)
 {% 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 %}
+  <span data-key="full-uri">{{ chunk.book.correct_about }}</span>
 {% endblock %}
index 87780b7..281ced5 100644 (file)
@@ -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(