Added datatype criteria in advanced search form
authorThierry Florac <tflorac@ulthar.net>
Tue, 17 Sep 2019 16:11:08 +0200
changeset 1349 4aca0ad81b2b
parent 1348 ae293e874417
child 1350 1bbc829453f9
Added datatype criteria in advanced search form
src/pyams_content/shared/common/zmi/search.py
src/pyams_content/shared/common/zmi/templates/advanced-search.pt
--- a/src/pyams_content/shared/common/zmi/search.py	Tue Sep 17 15:33:20 2019 +0200
+++ b/src/pyams_content/shared/common/zmi/search.py	Tue Sep 17 16:11:08 2019 +0200
@@ -9,6 +9,8 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.shared.common.interfaces.types import DATA_TYPES_VOCABULARY, ITypedSharedTool
+
 
 __docformat__ = 'restructuredtext'
 
@@ -173,6 +175,10 @@
                     vocabulary=SHARED_TOOL_WORKFLOW_STATES_VOCABULARY,
                     required=False)
 
+    data_type = Choice(title=_("Data type"),
+                       vocabulary=DATA_TYPES_VOCABULARY,
+                       required=False)
+
     created_after = Datetime(title=_("Created after..."),
                              required=False)
 
@@ -214,6 +220,8 @@
         workflow = IWorkflow(self.context)
         fields = field.Fields(ISharedToolAdvancedSearchFields)
         fields['status'].vocabulary = workflow.states
+        if not ITypedSharedTool.providedBy(self.context):
+            fields = fields.omit('data_type')
         fields['tags'].widgetFactory = ThesaurusTermsTreeFieldWidget
         if IThemesManagerTarget.providedBy(self.context):
             fields['themes'].widgetFactory = ThesaurusTermsTreeFieldWidget
@@ -274,6 +282,8 @@
             params &= Eq(catalog['role:owner'], data['owner'])
         if data.get('status'):
             params &= Eq(catalog['workflow_state'], data['status'])
+        if data.get('data_type'):
+            params &= Eq(catalog['data_type'], data['data_type'])
         if data.get('created_after'):
             params &= Ge(catalog['created_date'], data['created_after'])
         if data.get('created_before'):
--- a/src/pyams_content/shared/common/zmi/templates/advanced-search.pt	Tue Sep 17 15:33:20 2019 +0200
+++ b/src/pyams_content/shared/common/zmi/templates/advanced-search.pt	Tue Sep 17 16:11:08 2019 +0200
@@ -124,6 +124,29 @@
 										</div>
 									</div>
 								</tal:var>
+								<tal:if define="widget view.widgets.get('data_type')"
+										condition="widget">
+									<tal:var >
+										<label class="control-label col-md-1">
+											<span>
+												<tal:var content="widget.label" />
+												<i class="fa fa-question-circle hint" title="Input hint"
+												   tal:define="description widget.field.description"
+												   tal:condition="description"
+												   tal:attributes="title description;
+																   data-ams-hint-html '<' in description;"></i>
+											</span>
+										</label>
+										<div class="col-md-4">
+											<div class="input"
+												 tal:attributes="class widget.widget_css_class | default;
+																 data-ams-data tales:object_data(widget);
+																 data-ams-form-validator view.get_widget_callback(widget.field.getName())">
+												<input tal:replace="structure widget.render()" />
+											</div>
+										</div>
+									</tal:var>
+								</tal:if>
 							</div>
 							<div class="form-group">
 								<label class="control-label col-md-3">