src/pyams_content/shared/view/interfaces/__init__.py
changeset 92 3facc843c06f
parent 81 3e37d4dd8e3b
child 96 120f7842a8cb
--- a/src/pyams_content/shared/view/interfaces/__init__.py	Tue Jun 27 11:47:34 2017 +0200
+++ b/src/pyams_content/shared/view/interfaces/__init__.py	Tue Jun 27 11:49:01 2017 +0200
@@ -16,10 +16,12 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.links.interfaces import IInternalReferencesList
 from pyams_content.shared.common.interfaces import ISharedContent, IWfSharedContent, ISharedTool
 
 # import packages
 from pyams_sequence.schema import InternalReferencesList
+from pyams_thesaurus.schema import ThesaurusTermsListField
 from zope.interface import Interface, Attribute
 from zope.schema import List, Choice, Bool
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
@@ -31,10 +33,10 @@
 VIEW_CONTENT_NAME = _('View')
 
 
-CREATION_DATE_ORDER = 'creation_datetime'
-UPDATE_DATE_ORDER = 'update_datetime'
-PUBLICATION_DATE_ORDER = 'publication_datetime'
-FIRSTPUBLICATION_DATE_ORDER = 'first_publication_datetime'
+CREATION_DATE_ORDER = 'created_date'
+UPDATE_DATE_ORDER = 'modified_date'
+PUBLICATION_DATE_ORDER = 'publication_date'
+FIRSTPUBLICATION_DATE_ORDER = 'first_publication_date'
 
 VIEW_ORDER = {CREATION_DATE_ORDER: _("Creation date"),
               UPDATE_DATE_ORDER: _("Last update date"),
@@ -59,8 +61,8 @@
 
     order_by = Choice(title=_("Order by"),
                       description=_("Property to use to sort results"),
+                      vocabulary=VIEW_ORDER_VOCABULARY,
                       required=True,
-                      vocabulary=VIEW_ORDER_VOCABULARY,
                       default=FIRSTPUBLICATION_DATE_ORDER)
 
     reversed_order = Bool(title=_("Reversed order?"),
@@ -68,21 +70,43 @@
                           required=True,
                           default=True)
 
+    def get_results(self, context):
+        """Get results of catalog query"""
+
 
 class IView(ISharedContent):
     """Workflow managed view interface"""
 
 
-class IViewExtension(Interface):
-    """View query extension interface
+class IViewQuery(Interface):
+    """View query interface"""
+
+    def get_results(self, context):
+        """Get results of catalog query"""
+
 
-    This interface is used to add features to views from external packages
-    """
+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"""
 
-    weight = Attribute("Extension weight")
+
+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"""
@@ -91,9 +115,42 @@
 VIEW_REFERENCES_SETTINGS_KEY = 'pyams_content.view.references'
 
 
-class IViewInternalReferencesSettings(Interface):
+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(IInternalReferencesList):
     """View internal references settings"""
 
-    references = InternalReferencesList(title=_("Internal references"),
-                                        description=_("List of internal references"),
-                                        required=False)
+    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)
+
+
+VIEW_THEMES_SETTINGS_KEY = 'pyams_content.view.themes'
+
+
+class IViewThemesSettings(Interface):
+    """View themess ettings"""
+
+    select_context_themes = Bool(title=_("Select context themes?"),
+                                 description=_("If 'yes', themes will be extracted from context"),
+                                 required=True,
+                                 default=False)
+
+    themes = ThesaurusTermsListField(title=_("Other terms"),
+                                     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"""