descriptions in catalogue
[redakcja.git] / src / wlxml / views.py
index b951b3c..edf8a92 100644 (file)
@@ -6,6 +6,9 @@ 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.wluri import WLURI
+from librarian.meta.types.text import LegimiCategory, Epoch, Kind, Genre, Audience
+from depot.legimi import legimi
 
 
 class XslView(TemplateView):
 
 
 class XslView(TemplateView):
@@ -42,21 +45,109 @@ 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/',
+        }
+    },
+    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):
 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,
+                    VALUE_TYPES.get(
+                        f.name,
+                        {}
+                    )
+                )
+            )
+            fields.append(d)
+
+        return HttpResponse(
+            'let META_FIELDS = ' + json.dumps(fields),
             content_type='text/javascript')
     
             content_type='text/javascript')