Added view to display properties of catalog indexes
authorThierry Florac <thierry.florac@onf.fr>
Tue, 27 Dec 2016 15:43:09 +0100
changeset 18 2760efac78bc
parent 17 5a04bf80d3d9
child 19 f3f2a1e1f3bb
Added view to display properties of catalog indexes
src/pyams_catalog/locales/fr/LC_MESSAGES/pyams_catalog.mo
src/pyams_catalog/locales/fr/LC_MESSAGES/pyams_catalog.po
src/pyams_catalog/locales/pyams_catalog.pot
src/pyams_catalog/zmi/__init__.py
src/pyams_catalog/zmi/catalog.py
src/pyams_catalog/zmi/templates/catalog-indexes.pt
Binary file src/pyams_catalog/locales/fr/LC_MESSAGES/pyams_catalog.mo has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_catalog/locales/fr/LC_MESSAGES/pyams_catalog.po	Tue Dec 27 15:43:09 2016 +0100
@@ -0,0 +1,69 @@
+#
+# French translations for PACKAGE package
+# This file is distributed under the same license as the PACKAGE package.
+# Thierry Florac <tflorac@ulthar.net>, 2016.
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE 1.0\n"
+"POT-Creation-Date: 2016-12-27 15:31+0100\n"
+"PO-Revision-Date: 2016-12-27 15:32+0100\n"
+"Last-Translator: Thierry Florac <tflorac@ulthar.net>\n"
+"Language-Team: French\n"
+"Language: fr\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Lingua 3.8\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#: src/pyams_catalog/zmi/catalog.py:54
+msgid "Display catalog indexes"
+msgstr "Liste des index du catalogue"
+
+#: src/pyams_catalog/zmi/catalog.py:63
+msgid "Catalog indexes"
+msgstr "Index du catalogue"
+
+#: src/pyams_catalog/zmi/catalog.py:88
+msgid "Name"
+msgstr "Nom"
+
+#: src/pyams_catalog/zmi/catalog.py:98
+msgid "Index type"
+msgstr "Type d'index"
+
+#: src/pyams_catalog/zmi/catalog.py:109
+msgid "Interface"
+msgstr "Interface"
+
+#: src/pyams_catalog/zmi/catalog.py:123
+msgid "Discriminator"
+msgstr "Discriminant"
+
+#: src/pyams_catalog/zmi/catalog.py:134
+msgid "#docs"
+msgstr "# docs"
+
+#: src/pyams_catalog/zmi/catalog.py:150
+msgid "#indexed"
+msgstr "# indexés"
+
+#: src/pyams_catalog/zmi/catalog.py:166
+msgid "#unindexed"
+msgstr "# non indexés"
+
+#: src/pyams_catalog/zmi/catalog.py:182
+msgid "#values"
+msgstr "# valeurs"
+
+#: src/pyams_catalog/zmi/catalog.py:198
+msgid "Delete index"
+msgstr "Supprimer l'index"
+
+#: src/pyams_catalog/zmi/catalog.py:240
+msgid "No provided object_name argument!"
+msgstr "Argument 'object_name' non fourni !"
+
+#: src/pyams_catalog/zmi/catalog.py:244
+msgid "Given index doesn't exist!"
+msgstr "L'index indiqué n'existe pas !"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_catalog/locales/pyams_catalog.pot	Tue Dec 27 15:43:09 2016 +0100
@@ -0,0 +1,69 @@
+# 
+# SOME DESCRIPTIVE TITLE
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE 1.0\n"
+"POT-Creation-Date: 2016-12-27 15:31+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Lingua 3.8\n"
+
+#: ./src/pyams_catalog/zmi/catalog.py:54
+msgid "Display catalog indexes"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:63
+msgid "Catalog indexes"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:88
+msgid "Name"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:98
+msgid "Index type"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:109
+msgid "Interface"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:123
+msgid "Discriminator"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:134
+msgid "#docs"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:150
+msgid "#indexed"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:166
+msgid "#unindexed"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:182
+msgid "#values"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:198
+msgid "Delete index"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:240
+msgid "No provided object_name argument!"
+msgstr ""
+
+#: ./src/pyams_catalog/zmi/catalog.py:244
+msgid "Given index doesn't exist!"
+msgstr ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_catalog/zmi/__init__.py	Tue Dec 27 15:43:09 2016 +0100
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+
+# import packages
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_catalog/zmi/catalog.py	Tue Dec 27 15:43:09 2016 +0100
@@ -0,0 +1,246 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+from pyramid.view import view_config
+
+from pyams_utils.url import absolute_url
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from hypatia.interfaces import ICatalog, IIndexStatistics, IIndexEnumeration
+from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
+from pyams_zmi.layer import IAdminLayer
+from z3c.table.interfaces import IColumn, IValues
+
+# import packages
+from pyams_catalog.index import InterfaceSupportIndexMixin
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.table import BaseTable, I18nColumn, TrashColumn
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from pyams_utils.text import text_to_html
+from pyams_viewlet.viewlet import viewlet_config, Viewlet
+from pyams_zmi.form import AdminDialogDisplayForm
+from z3c.form import field
+from z3c.table.column import GetAttrColumn
+from zope.interface import Interface
+
+from pyams_catalog import _
+
+
+@pagelet_config(name='properties.html', context=ICatalog, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
+class CatalogPropertiesDisplayForm(AdminDialogDisplayForm):
+    """Catalog properties display form"""
+
+    @property
+    def title(self):
+        return self.context.__name__
+
+    dialog_class = 'modal-max'
+    legend = _("Display catalog indexes")
+
+    fields = field.Fields(Interface)
+
+
+class CatalogIndexesTable(BaseTable):
+    """Catalog indexes table"""
+
+    id = 'CatalogIndexes'
+    title = _("Catalog indexes")
+    cssClasses = {'table': 'table table-bordered table-striped table-hover table-tight datatable'}
+    sortOn = None
+
+    @property
+    def data_attributes(self):
+        attributes = super(CatalogIndexesTable, self).data_attributes
+        table_attrs = {'data-ams-location': absolute_url(self.context, self.request),
+                       'data-ams-delete-target': 'delete-index.json',
+                       'data-ams-datatable-global-filter': 'false',
+                       'data-ams-datatable-info': 'false',
+                       'data-ams-datatable-sdom': "t<'dt-row dt-bottom-row'<'text-right'p>>",
+                       'data-ams-datatable-display-length': '20',
+                       'data-ams-datatable-pagination-type': 'bootstrap_prevnext'}
+        if 'table' in attributes:
+            attributes['table'].update(table_attrs)
+        else:
+            attributes['table'] = table_attrs
+        return attributes
+
+
+@adapter_config(name='name', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexNameColumn(I18nColumn, GetAttrColumn):
+    """Catalog index name column"""
+
+    _header = _("Name")
+    weight = 1
+
+    attrName = '__name__'
+
+
+@adapter_config(name='class', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexClassColumn(I18nColumn, GetAttrColumn):
+    """Catalog index class column"""
+
+    _header = _("Index type")
+    weight = 2
+
+    def getValue(self, obj):
+        return text_to_html(str(obj.__class__))
+
+
+@adapter_config(name='interface', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexInterfaceColumn(I18nColumn, GetAttrColumn):
+    """Catalog index interface column"""
+
+    _header = _("Interface")
+    weight = 3
+
+    def getValue(self, obj):
+        if isinstance(obj, InterfaceSupportIndexMixin):
+            return text_to_html(str(obj.interface))
+        else:
+            return '--'
+
+
+@adapter_config(name='discriminator', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexDiscriminatorColumn(I18nColumn, GetAttrColumn):
+    """Catalog index discriminator column"""
+
+    _header = _("Discriminator")
+    weight = 4
+
+    def getValue(self, obj):
+        return obj.discriminator
+
+
+@adapter_config(name='nb_docs', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexNbDocsColumn(I18nColumn, GetAttrColumn):
+    """Catalog index documents count column"""
+
+    _header = _("#docs")
+    weight = 5
+
+    cssClasses = {'td': 'center'}
+
+    def getValue(self, obj):
+        if IIndexEnumeration.providedBy(obj):
+            return obj.docids_count()
+        else:
+            return '--'
+
+
+@adapter_config(name='nb_indexed', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexNbIndexedColumn(I18nColumn, GetAttrColumn):
+    """Catalog index documents indexed column"""
+
+    _header = _("#indexed")
+    weight = 6
+
+    cssClasses = {'td': 'center'}
+
+    def getValue(self, obj):
+        if IIndexEnumeration.providedBy(obj):
+            return obj.indexed_count()
+        else:
+            return '--'
+
+
+@adapter_config(name='nb_unindexed', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexNbUnindexedColumn(I18nColumn, GetAttrColumn):
+    """Catalog index documents not-indexed column"""
+
+    _header = _("#unindexed")
+    weight = 7
+
+    cssClasses = {'td': 'center'}
+
+    def getValue(self, obj):
+        if IIndexEnumeration.providedBy(obj):
+            return obj.not_indexed_count()
+        else:
+            return '--'
+
+
+@adapter_config(name='nb_words', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexNbWordsColumn(I18nColumn, GetAttrColumn):
+    """Catalog index documents count column"""
+
+    _header = _("#values")
+    weight = 10
+
+    cssClasses = {'td': 'center'}
+
+    def getValue(self, obj):
+        if IIndexStatistics.providedBy(obj):
+            return obj.word_count()
+        else:
+            return '--'
+
+
+@adapter_config(name='trash', context=(Interface, IAdminLayer, CatalogIndexesTable), provides=IColumn)
+class CatalogIndexTrashColumn(TrashColumn):
+    """Catalog index trash column"""
+
+    icon_hint = _("Delete index")
+    permission = MANAGE_SYSTEM_PERMISSION
+
+    def has_permission(self, item):
+        return super(CatalogIndexTrashColumn, self).has_permission(self.context)
+
+
+@adapter_config(context=(ICatalog, IAdminLayer, CatalogIndexesTable), provides=IValues)
+class CatalogIndexesValuesAdapter(ContextRequestViewAdapter):
+    """Catalog indexes values adapter"""
+
+    @property
+    def values(self):
+        return self.context.values()
+
+
+@viewlet_config(name='catalog-indexes', view=CatalogPropertiesDisplayForm, layer=IAdminLayer,
+                manager=IWidgetsSuffixViewletsManager)
+@template_config(template='templates/catalog-indexes.pt')
+class CatalogIndexesViewlet(Viewlet):
+    """Catalog indexes viewlet"""
+
+    table = None
+
+    def __init__(self, context, request, view, manager):
+        super(CatalogIndexesViewlet, self).__init__(context, request, view, manager)
+        self.table = CatalogIndexesTable(context, request)
+
+    def update(self):
+        super(CatalogIndexesViewlet, self).update()
+        self.table.update()
+
+
+@view_config(name='delete-index.json', context=ICatalog, request_type=IPyAMSLayer,
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
+def delete_catalog_index(request):
+    """Delete index from catalog"""
+    translate = request.localizer.translate
+    name = request.params.get('object_name')
+    if not name:
+        return {'status': 'message',
+                'messagebox': {'status': 'error',
+                               'content': translate(_("No provided object_name argument!"))}}
+    if name not in request.context:
+        return {'status': 'message',
+                'messagebox': {'status': 'error',
+                               'content': translate(_("Given index doesn't exist!"))}}
+    del request.context[name]
+    return {'status': 'success'}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_catalog/zmi/templates/catalog-indexes.pt	Tue Dec 27 15:43:09 2016 +0100
@@ -0,0 +1,3 @@
+<div class="no-widget-toolbar">
+	<tal:var replace="structure view.table.render()" />
+</div>