src/pyams_content/features/search/interfaces.py
changeset 1389 1485db1e2b5e
parent 1282 498f90fe8d7b
--- a/src/pyams_content/features/search/interfaces.py	Wed Jun 24 12:07:40 2020 +0200
+++ b/src/pyams_content/features/search/interfaces.py	Fri Jun 26 12:54:13 2020 +0200
@@ -10,12 +10,9 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
-
-from zope.interface import Interface
+from zope.interface import Attribute, Interface, Invalid, invariant
 from zope.schema import Bool, Choice, Set
 
-from pyams_content import _
 from pyams_content.interfaces import GUEST_ROLE, IBaseContent, MANAGER_ROLE
 from pyams_content.shared.common.interfaces import SHARED_CONTENT_TYPES_VOCABULARY
 from pyams_content.shared.common.interfaces.types import ALL_DATA_TYPES_VOCABULARY
@@ -25,19 +22,27 @@
 from pyams_i18n.schema import I18nTextLineField
 from pyams_portal.interfaces import DESIGNER_ROLE
 from pyams_security.schema import PrincipalsSet
-from pyams_sequence.interfaces import IInternalReference, ISequentialIdTarget
+from pyams_sequence.interfaces import IInternalReferencesList, ISequentialIdTarget
 from pyams_sequence.schema import InternalReferenceField
 
 
-class ISearchManagerInfo(IInternalReference):
+__docformat__ = 'restructuredtext'
+
+from pyams_content import _
+
+
+class ISearchManagerInfo(IInternalReferencesList):
     """Search manager interface"""
 
     reference = InternalReferenceField(title=_("Main search engine"),
-                                       description=_("Search folder handling main site search. You can search a "
-                                                     "reference using '+' followed by internal number, of by "
+                                       description=_("Search folder handling main site search. "
+                                                     "You can search a reference using '+' "
+                                                     "followed by internal number, of by "
                                                      "entering text matching content title."),
                                        required=False)
 
+    search_target = Attribute("Search target object")
+
     name = I18nTextLineField(title=_("Search engine name"),
                              description=_("Name given to the search engine"),
                              required=False)
@@ -46,23 +51,64 @@
                                     description=_("Description given to the search engine"),
                                     required=False)
 
+    enable_tags_search = Bool(title=_("Enable search by tag?"),
+                              description=_("If 'yes', displayed tags will lead to a search "
+                                            "engine displaying contents matching given tag"),
+                              required=True,
+                              default=False)
+
+    tags_search_target = InternalReferenceField(title=_("Tags search target"),
+                                                description=_("Site or folder where tags search "
+                                                              "is displayed"),
+                                                required=False)
+
+    tags_target = Attribute("Tags search target object reference")
+
+    @invariant
+    def check_tags_search_target(self):
+        if self.enable_tags_search and not self.tags_search_target:
+            raise Invalid(_("You must specify search target when activating search by tags!"))
+
+    enable_collections_search = Bool(title=_("Enable search by collection?"),
+                                     description=_("If 'yes', displayed collections will lead to "
+                                                   "a search engine displaying contents matching "
+                                                   "given collection"),
+                                     required=True,
+                                     default=False)
+
+    collections_search_target = InternalReferenceField(title=_("Collections search target"),
+                                                       description=_("Site or folder where "
+                                                                     "collections search is "
+                                                                     "displayed"),
+                                                       required=False)
+
+    collections_target = Attribute("Collections search target object reference")
+
+    @invariant
+    def check_collections_search_target(self):
+        if self.enable_collections_search and not self.collections_search_target:
+            raise Invalid(_("You must specify search target when activating search by "
+                            "collections!"))
+
 
 class ISearchFolderRoles(Interface):
     """Search folder roles"""
 
     managers = PrincipalsSet(title=_("Managers"),
-                             description=_("Managers can handle main operations in tool's workflow, like publish "
-                                           "or retire contents"),
+                             description=_("Managers can handle main operations in tool's "
+                                           "workflow, like publish or retire contents"),
                              role_id=MANAGER_ROLE,
                              required=False)
 
     designers = PrincipalsSet(title=_("Designers"),
-                              description=_("Designers are users which are allowed to manage presentation templates"),
+                              description=_("Designers are users which are allowed to manage "
+                                            "presentation templates"),
                               role_id=DESIGNER_ROLE,
                               required=False)
 
     guests = PrincipalsSet(title=_("Guests"),
-                           description=_("Guests are users which are allowed to view contents with restricted access"),
+                           description=_("Guests are users which are allowed to view contents "
+                                         "with restricted access"),
                            role_id=GUEST_ROLE,
                            required=False)
 
@@ -71,21 +117,24 @@
     """Search folder interface"""
 
     order_by = Choice(title=_("Order by"),
-                      description=_("Property to use to sort results; publication date can be different from first "
-                                    "publication date for contents which have been retired and re-published with a "
-                                    "different publication date"),
+                      description=_("Property to use to sort results; publication date can be "
+                                    "different from first publication date for contents which "
+                                    "have been retired and re-published with a different "
+                                    "publication date"),
                       vocabulary=USER_VIEW_ORDER_VOCABULARY,
                       required=False,
                       default=RELEVANCE_ORDER)
 
     visible_in_list = Bool(title=_("Visible in folders list"),
-                           description=_("If 'no', folder will not be displayed into folders list"),
+                           description=_("If 'no', folder will not be displayed into folders "
+                                         "list"),
                            required=True,
                            default=True)
 
     navigation_title = I18nTextLineField(title=_("Navigation title"),
-                                         description=_("Folder's title displayed in navigation pages; "
-                                                       "original title will be used if none is specified"),
+                                         description=_("Folder's title displayed in navigation "
+                                                       "pages; original title will be used if "
+                                                       "none is specified"),
                                          required=False)
 
     selected_content_types = Set(title=_("Selected content types"),