src/pyams_content/shared/view/interfaces.py
changeset 1059 34e6d07ea2e9
parent 956 a8723fffbaf6
child 1060 29b1aaf9e080
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/view/interfaces.py	Tue Nov 06 14:40:22 2018 +0100
@@ -0,0 +1,261 @@
+#
+# 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
+from pyams_content.shared.common.interfaces import ISharedContent, IWfSharedContent, ISharedTool, \
+    CONTENT_TYPES_VOCABULARY
+from pyams_content.shared.common.interfaces.types import ALL_DATA_TYPES_VOCABULARY
+from pyams_sequence.interfaces import IInternalReferencesList
+
+# import packages
+from pyams_thesaurus.schema import ThesaurusTermsListField
+from zope.interface import Interface, Attribute
+from zope.schema import Set, Choice, Bool, Int
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+
+from pyams_content import _
+
+
+VIEW_CONTENT_TYPE = 'view'
+VIEW_CONTENT_NAME = _('View')
+
+
+CREATION_DATE_ORDER = 'created_date'
+UPDATE_DATE_ORDER = 'modified_date'
+PUBLICATION_DATE_ORDER = 'publication_date'
+FIRSTPUBLICATION_DATE_ORDER = 'first_publication_date'
+
+VIEW_ORDERS = (
+    {'id': CREATION_DATE_ORDER, 'title': _("Creation date")},
+    {'id': UPDATE_DATE_ORDER, 'title': _("Last update date")},
+    {'id': PUBLICATION_DATE_ORDER, 'title': _("Current publication date")},
+    {'id': FIRSTPUBLICATION_DATE_ORDER, 'title': _("First publication date")}
+)
+
+VIEW_ORDER_VOCABULARY = SimpleVocabulary([SimpleTerm(item['id'], title=item['title'])
+                                          for item in VIEW_ORDERS])
+
+
+class IViewsManager(ISharedTool):
+    """Views manager interface"""
+
+
+class IViewsManagerFactory(Interface):
+    """Views manager factory interface"""
+
+
+class IWfView(IWfSharedContent):
+    """View interface"""
+
+    select_context_type = Bool(title=_("Select context type?"),
+                               description=_("If 'yes', content type will be extracted from context"),
+                               required=True,
+                               default=False)
+
+    selected_content_types = Set(title=_("Other content types"),
+                                 description=_("Selected content types; leave empty for all"),
+                                 value_type=Choice(vocabulary=CONTENT_TYPES_VOCABULARY),
+                                 required=False)
+
+    def get_content_types(self, context):
+        """Get content types for given context"""
+
+    select_context_datatype = Bool(title=_("Select context data type?"),
+                                   description=_("If 'yes', content data type (if available) will be extracted from "
+                                                 "context"),
+                                   required=True,
+                                   default=False)
+
+    selected_datatypes = Set(title=_("Other data types"),
+                             description=_("Selected data types; leave empty for all"),
+                             value_type=Choice(vocabulary=ALL_DATA_TYPES_VOCABULARY),
+                             required=False)
+
+    def get_data_types(self, context):
+        """Get data types for given context"""
+
+    order_by = Choice(title=_("Order by"),
+                      description=_("Property to use to sort results"),
+                      vocabulary=VIEW_ORDER_VOCABULARY,
+                      required=True,
+                      default=FIRSTPUBLICATION_DATE_ORDER)
+
+    reversed_order = Bool(title=_("Reversed order?"),
+                          description=_("If 'yes', items order will be reversed"),
+                          required=True,
+                          default=True)
+
+    limit = Int(title=_("Results count limit"),
+                description=_("Maximum number of results that the view may retrieve"),
+                required=False)
+
+    is_using_context = Attribute("Check if view is using context settings")
+
+    def get_results(self, context, sort_index=None, reverse=True, limit=None, ignore_cache=False):
+        """Get results of catalog query"""
+
+
+class IWfViewFactory(Interface):
+    """View factory interface"""
+
+
+class IView(ISharedContent):
+    """Workflow managed view interface"""
+
+
+class IViewSettings(Interface):
+    """Base interface for view settings adapters"""
+
+    is_using_context = Attribute("Check if view settings are using context")
+
+
+class IViewQuery(Interface):
+    """View query interface"""
+
+    def get_results(self, context, sort_index, reverse, limit):
+        """Get results of catalog query"""
+
+
+class IViewQueryExtension(Interface):
+    """Base view query extension"""
+
+    weight = Attribute("Extension weight")
+
+
+class IViewQueryParamsExtension(IViewQueryExtension):
+    """View query extension interface"""
+
+    def get_params(self, context):
+        """Add params to catalog query"""
+
+
+class IViewQueryEsParamsExtension(IViewQueryExtension):
+    """View query parameters extension for Elasticsearch"""
+
+    def get_es_params(self, context):
+        """Add params to Elasticsearch query"""
+
+
+class IViewQueryFilterExtension(IViewQueryExtension):
+    """View query filter extension"""
+
+    def filter(self, context, items):
+        """Filter items after catalog query"""
+
+
+VIEW_REFERENCES_SETTINGS_KEY = 'pyams_content.view.references'
+
+
+ALWAYS_REFERENCE_MODE = 'always'
+IFEMPTY_REFERENCE_MODE = 'if_empty'
+
+REFERENCES_MODES = {ALWAYS_REFERENCE_MODE: _("Always include selected internal references"),
+                    IFEMPTY_REFERENCE_MODE: _("Include selected internal references only if empty")}
+
+REFERENCES_MODES_VOCABULARY = SimpleVocabulary([SimpleTerm(v, title=t)
+                                                for v, t in REFERENCES_MODES.items()])
+
+
+class IViewInternalReferencesSettings(IViewSettings, IInternalReferencesList):
+    """View internal references settings"""
+
+    references_mode = Choice(title=_("Internal references usage"),
+                             description=_("Specify how selected references are included into view results"),
+                             vocabulary=REFERENCES_MODES_VOCABULARY,
+                             required=True,
+                             default=ALWAYS_REFERENCE_MODE)
+
+    exclude_context = Bool(title=_("Exclude context?"),
+                           description=_("If 'yes', context will be excluded from results list"),
+                           required=True,
+                           default=True)
+
+
+VIEW_TAGS_SETTINGS_KEY = 'pyams_content.view.tags'
+
+
+class IViewTagsSettings(IViewSettings):
+    """View tags settings"""
+
+    select_context_tags = Bool(title=_("Select context tags?"),
+                               description=_("If 'yes', tags will be extracted from context"),
+                               required=False,
+                               default=False)
+
+    tags = ThesaurusTermsListField(title=_("Other tags"),
+                                   required=False)
+
+    def get_tags(self, context):
+        """Get all tags for given context"""
+
+    def get_tags_index(self, context):
+        """Get all tags index values for given context"""
+
+
+VIEW_THEMES_SETTINGS_KEY = 'pyams_content.view.themes'
+
+
+class IViewThemesSettings(IViewSettings):
+    """View themes settings"""
+
+    select_context_themes = Bool(title=_("Select context themes?"),
+                                 description=_("If 'yes', themes will be extracted from context"),
+                                 required=False,
+                                 default=False)
+
+    themes = ThesaurusTermsListField(title=_("Other themes"),
+                                     required=False)
+
+    def get_themes(self, context):
+        """Get all themes for given context"""
+
+    def get_themes_index(self, context):
+        """Get all themes index values for given context"""
+
+
+VIEW_COLLECTIONS_SETTINGS_KEY = 'pyams_content.view.collections'
+
+
+class IViewCollectionsSettings(IViewSettings):
+    """View collections settings"""
+
+    select_context_collections = Bool(title=_("Select context collections?"),
+                                      description=_("If 'yes', collections will be extracted from context"),
+                                      required=False,
+                                      default=False)
+
+    collections = ThesaurusTermsListField(title=_("Other collections"),
+                                          required=False)
+
+    def get_collections(self, context):
+        """Get all collections for given context"""
+
+    def get_collections_index(self, context):
+        """Get all collections index values for given context"""
+
+
+VIEWS_MERGERS_VOCABULARY = 'pyams_content.views.mergers'
+
+
+class IViewsMerger(Interface):
+    """Interface used to define views mergers
+
+    Mergers are used to merge results of several views.
+    """
+
+    def get_results(self, views, context, ignore_cache=False):
+        """Merge results of several views together"""