src/pyams_content/shared/view/interfaces/__init__.py
changeset 92 3facc843c06f
parent 81 3e37d4dd8e3b
child 96 120f7842a8cb
equal deleted inserted replaced
91:87e08c0f3e3c 92:3facc843c06f
    14 
    14 
    15 
    15 
    16 # import standard library
    16 # import standard library
    17 
    17 
    18 # import interfaces
    18 # import interfaces
       
    19 from pyams_content.component.links.interfaces import IInternalReferencesList
    19 from pyams_content.shared.common.interfaces import ISharedContent, IWfSharedContent, ISharedTool
    20 from pyams_content.shared.common.interfaces import ISharedContent, IWfSharedContent, ISharedTool
    20 
    21 
    21 # import packages
    22 # import packages
    22 from pyams_sequence.schema import InternalReferencesList
    23 from pyams_sequence.schema import InternalReferencesList
       
    24 from pyams_thesaurus.schema import ThesaurusTermsListField
    23 from zope.interface import Interface, Attribute
    25 from zope.interface import Interface, Attribute
    24 from zope.schema import List, Choice, Bool
    26 from zope.schema import List, Choice, Bool
    25 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
    27 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
    26 
    28 
    27 from pyams_content import _
    29 from pyams_content import _
    29 
    31 
    30 VIEW_CONTENT_TYPE = 'view'
    32 VIEW_CONTENT_TYPE = 'view'
    31 VIEW_CONTENT_NAME = _('View')
    33 VIEW_CONTENT_NAME = _('View')
    32 
    34 
    33 
    35 
    34 CREATION_DATE_ORDER = 'creation_datetime'
    36 CREATION_DATE_ORDER = 'created_date'
    35 UPDATE_DATE_ORDER = 'update_datetime'
    37 UPDATE_DATE_ORDER = 'modified_date'
    36 PUBLICATION_DATE_ORDER = 'publication_datetime'
    38 PUBLICATION_DATE_ORDER = 'publication_date'
    37 FIRSTPUBLICATION_DATE_ORDER = 'first_publication_datetime'
    39 FIRSTPUBLICATION_DATE_ORDER = 'first_publication_date'
    38 
    40 
    39 VIEW_ORDER = {CREATION_DATE_ORDER: _("Creation date"),
    41 VIEW_ORDER = {CREATION_DATE_ORDER: _("Creation date"),
    40               UPDATE_DATE_ORDER: _("Last update date"),
    42               UPDATE_DATE_ORDER: _("Last update date"),
    41               PUBLICATION_DATE_ORDER: _("Current publication date"),
    43               PUBLICATION_DATE_ORDER: _("Current publication date"),
    42               FIRSTPUBLICATION_DATE_ORDER: _("First publication date")}
    44               FIRSTPUBLICATION_DATE_ORDER: _("First publication date")}
    57                                   value_type=Choice(vocabulary='PyAMS content types'),
    59                                   value_type=Choice(vocabulary='PyAMS content types'),
    58                                   required=False)
    60                                   required=False)
    59 
    61 
    60     order_by = Choice(title=_("Order by"),
    62     order_by = Choice(title=_("Order by"),
    61                       description=_("Property to use to sort results"),
    63                       description=_("Property to use to sort results"),
       
    64                       vocabulary=VIEW_ORDER_VOCABULARY,
    62                       required=True,
    65                       required=True,
    63                       vocabulary=VIEW_ORDER_VOCABULARY,
       
    64                       default=FIRSTPUBLICATION_DATE_ORDER)
    66                       default=FIRSTPUBLICATION_DATE_ORDER)
    65 
    67 
    66     reversed_order = Bool(title=_("Reversed order?"),
    68     reversed_order = Bool(title=_("Reversed order?"),
    67                           description=_("If 'yes', items order will be reversed"),
    69                           description=_("If 'yes', items order will be reversed"),
    68                           required=True,
    70                           required=True,
    69                           default=True)
    71                           default=True)
    70 
    72 
       
    73     def get_results(self, context):
       
    74         """Get results of catalog query"""
       
    75 
    71 
    76 
    72 class IView(ISharedContent):
    77 class IView(ISharedContent):
    73     """Workflow managed view interface"""
    78     """Workflow managed view interface"""
    74 
    79 
    75 
    80 
    76 class IViewExtension(Interface):
    81 class IViewQuery(Interface):
    77     """View query extension interface
    82     """View query interface"""
    78 
    83 
    79     This interface is used to add features to views from external packages
    84     def get_results(self, context):
    80     """
    85         """Get results of catalog query"""
       
    86 
       
    87 
       
    88 class IViewQueryExtension(Interface):
       
    89     """Base view query extension"""
       
    90 
       
    91     weight = Attribute("Extension weight")
       
    92 
       
    93 
       
    94 class IViewQueryParamsExtension(IViewQueryExtension):
       
    95     """View query extension interface"""
    81 
    96 
    82     def get_params(self, context):
    97     def get_params(self, context):
    83         """Add params to catalog query"""
    98         """Add params to catalog query"""
    84 
    99 
    85     weight = Attribute("Extension weight")
   100 
       
   101 class IViewQueryEsParamsExtension(IViewQueryExtension):
       
   102     """View query parameters extension for Elasticsearch"""
       
   103 
       
   104     def get_es_params(self, context):
       
   105         """Add params to Elasticsearch query"""
       
   106 
       
   107 
       
   108 class IViewQueryFilterExtension(IViewQueryExtension):
       
   109     """View query filter extension"""
    86 
   110 
    87     def filter(self, context, items):
   111     def filter(self, context, items):
    88         """Filter items after catalog query"""
   112         """Filter items after catalog query"""
    89 
   113 
    90 
   114 
    91 VIEW_REFERENCES_SETTINGS_KEY = 'pyams_content.view.references'
   115 VIEW_REFERENCES_SETTINGS_KEY = 'pyams_content.view.references'
    92 
   116 
    93 
   117 
    94 class IViewInternalReferencesSettings(Interface):
   118 ALWAYS_REFERENCE_MODE = 'always'
       
   119 IFEMPTY_REFERENCE_MODE = 'if_empty'
       
   120 
       
   121 REFERENCES_MODES = {ALWAYS_REFERENCE_MODE: _("Always include selected internal references"),
       
   122                     IFEMPTY_REFERENCE_MODE: _("Include selected internal references only if empty")}
       
   123 
       
   124 REFERENCES_MODES_VOCABULARY = SimpleVocabulary([SimpleTerm(v, title=t)
       
   125                                                 for v, t in REFERENCES_MODES.items()])
       
   126 
       
   127 
       
   128 class IViewInternalReferencesSettings(IInternalReferencesList):
    95     """View internal references settings"""
   129     """View internal references settings"""
    96 
   130 
    97     references = InternalReferencesList(title=_("Internal references"),
   131     references_mode = Choice(title=_("Internal references usage"),
    98                                         description=_("List of internal references"),
   132                              description=_("Specify how selected references are included into view results"),
    99                                         required=False)
   133                              vocabulary=REFERENCES_MODES_VOCABULARY,
       
   134                              required=True,
       
   135                              default=ALWAYS_REFERENCE_MODE)
       
   136 
       
   137 
       
   138 VIEW_THEMES_SETTINGS_KEY = 'pyams_content.view.themes'
       
   139 
       
   140 
       
   141 class IViewThemesSettings(Interface):
       
   142     """View themess ettings"""
       
   143 
       
   144     select_context_themes = Bool(title=_("Select context themes?"),
       
   145                                  description=_("If 'yes', themes will be extracted from context"),
       
   146                                  required=True,
       
   147                                  default=False)
       
   148 
       
   149     themes = ThesaurusTermsListField(title=_("Other terms"),
       
   150                                      required=False)
       
   151 
       
   152     def get_themes(self, context):
       
   153         """Get all themes for given context"""
       
   154 
       
   155     def get_themes_index(self, context):
       
   156         """Get all themes index values for given context"""