From ec7dd9391d47bcb74e1856445f70967b443e172b Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 25 Feb 2009 17:42:23 +0000 Subject: [PATCH] quicksearch improvements; make search process in relation widget more flexible git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3250 fd906abe-77d9-0310-91a1-e0d9ade77398 --- browser/concept_macros.pt | 4 ++- browser/loops.css | 3 ++- browser/node.pt | 2 +- browser/node.py | 5 ++-- browser/resource_macros.pt | 4 ++- expert/browser/search.pt | 18 +++++++++---- expert/browser/search.py | 10 ++++--- expert/concept.py | 53 ++++++++++++++++++++------------------ organize/work/browser.py | 6 +++-- schema/field.py | 4 +++ schema/relation_macros.pt | 4 +-- search/browser.py | 24 ++++++++++++----- 12 files changed, 88 insertions(+), 49 deletions(-) diff --git a/browser/concept_macros.pt b/browser/concept_macros.pt index efdfece..261cc8f 100644 --- a/browser/concept_macros.pt +++ b/browser/concept_macros.pt @@ -24,7 +24,9 @@

- + Title

+ diff --git a/browser/node.py b/browser/node.py index 5568812..119bad5 100644 --- a/browser/node.py +++ b/browser/node.py @@ -105,9 +105,10 @@ class NodeView(BaseView): cm.register('top_actions', 'top_actions', name='multi_actions', subMacros=[i18n_macros.macros['language_switch']]) if self.globalOptions('expert.quicksearch'): - from loops.expert.browser.search import search_macros + from loops.expert.browser.search import searchMacrosTemplate cm.register('top_actions', 'top_quicksearch', name='multi_actions', - subMacros=[search_macros.macros['quicksearch']], priority=20) + subMacros=[searchMacrosTemplate.macros['quicksearch']], + priority=20) cm.register('portlet_left', 'navigation', title='Navigation', subMacro=node_macros.macros['menu']) if canWrite(self.context, 'title') or ( diff --git a/browser/resource_macros.pt b/browser/resource_macros.pt index 27c35f6..3204178 100644 --- a/browser/resource_macros.pt +++ b/browser/resource_macros.pt @@ -6,7 +6,9 @@

-

Title

+

Title

Description

diff --git a/expert/browser/search.pt b/expert/browser/search.pt index 248248d..3af2d8e 100644 --- a/expert/browser/search.pt +++ b/expert/browser/search.pt @@ -13,11 +13,18 @@
+
+

Search results


+ +
+ +
+

Search results

-

Search results

@@ -36,11 +43,11 @@ + description row/description; + targetUrl python:view.getUrlForTarget(row)">
- 1.1 + tal:attributes="href + string:$targetUrl?loops.viewName=listversions">1.1 diff --git a/expert/browser/search.py b/expert/browser/search.py index dd2712e..5eb7200 100644 --- a/expert/browser/search.py +++ b/expert/browser/search.py @@ -34,15 +34,19 @@ from loops import util from loops.util import _ -search_macros = ViewPageTemplateFile('search.pt') +searchMacrosTemplate = ViewPageTemplateFile('search.pt') class SearchResults(NodeView): """ Provides results listing """ + @Lazy + def search_macros(self): + return searchMacrosTemplate.macros + @Lazy def macro(self): - return search_macros.macros['search_results'] + return self.search_macros['quicksearch_view'] @Lazy def item(self): @@ -52,7 +56,7 @@ class SearchResults(NodeView): def results(self): form = self.request.form text = form.get('search.text') - type = self.globalOptions('expert.quicksearch')[0] + type = self.globalOptions('expert.quicksearch') result = FullQuery(self).query(text=text, type=type, useTitle=True, useFull=True,) return self.viewIterator(result) diff --git a/expert/concept.py b/expert/concept.py index 958b6c2..5b81035 100644 --- a/expert/concept.py +++ b/expert/concept.py @@ -124,31 +124,34 @@ class FullQuery(BaseQuery): return ScoredSet(result, scores) if text or type != 'loops:*': # TODO: this may be highly inefficient! cat = self.catalog - if type.endswith('*'): - start = type[:-1] - end = start + '\x7f' - else: - start = end = type - criteria = {'loops_type': (start, end),} - if useFull and text: - criteria['loops_text'] = text - r1 = cat.apply(criteria) #r1 = set(cat.searchResults(**criteria)) - else: - r1 = IFBucket() #r1 = set() - if useTitle and text: - if 'loops_text' in criteria: - del criteria['loops_text'] - criteria['loops_title'] = text - r2 = cat.apply(criteria) #r2 = set(cat.searchResults(**criteria)) - else: - r2 = IFBucket() #r2 = set() - if not r1 and not r2: - r1 = cat.apply(criteria) # search only for type - x, uids = weightedUnion(r1, r2) #result = r1.union(r2) - for r, score in uids.items(): - obj = intids.getObject(r) - result.add(obj) - scores[obj] = score + if isinstance(type, basestring): + type = [type] + for tp in type: + if tp.endswith('*'): + start = tp[:-1] + end = start + '\x7f' + else: + start = end = tp + criteria = {'loops_type': (start, end),} + if useFull and text: + criteria['loops_text'] = text + r1 = cat.apply(criteria) #r1 = set(cat.searchResults(**criteria)) + else: + r1 = IFBucket() #r1 = set() + if useTitle and text: + if 'loops_text' in criteria: + del criteria['loops_text'] + criteria['loops_title'] = text + r2 = cat.apply(criteria) #r2 = set(cat.searchResults(**criteria)) + else: + r2 = IFBucket() #r2 = set() + if not r1 and not r2: + r1 = cat.apply(criteria) # search only for type + x, uids = weightedUnion(r1, r2) #result = r1.union(r2) + for r, score in uids.items(): + obj = intids.getObject(r) + result.add(obj) + scores[obj] = score if rc is not None: if result: result = result.intersection(rc) diff --git a/organize/work/browser.py b/organize/work/browser.py index f2c1bfe..61a89fd 100644 --- a/organize/work/browser.py +++ b/organize/work/browser.py @@ -201,8 +201,10 @@ class BaseWorkItemsView(object): def baseCriteria(self): result = {} form = self.request.form - tsFrom = parseDate(form.get('wi_from') or self.options.wi_from) - tsTo = parseDate(form.get('wi_to') or self.options.wi_to) + tsFrom = parseDate(form.get('wi_from') or + self.options.wi_from or self.typeOptions.wi_from) + tsTo = parseDate(form.get('wi_to') or + self.options.wi_to or self.typeOptions.wi_to) if tsTo: tsTo += 3600 * 24 - 1 # include full end date if tsFrom or tsTo: diff --git a/schema/field.py b/schema/field.py index b24b78e..e2dc361 100644 --- a/schema/field.py +++ b/schema/field.py @@ -44,6 +44,10 @@ relation_macros = ViewPageTemplateFile('relation_macros.pt') class BaseRelationFieldInstance(object): + @Lazy + def selection_view(self): + return getattr(self.context, 'selection_view', 'listConceptsForComboBox.js') + @Lazy def typesParams(self): result = [] diff --git a/schema/relation_macros.pt b/schema/relation_macros.pt index a73a23c..2ea0493 100755 --- a/schema/relation_macros.pt +++ b/schema/relation_macros.pt @@ -7,7 +7,7 @@ tal:define="fieldInstance field/getFieldInstance; types fieldInstance/typesParams">
@@ -38,7 +38,7 @@ tal:define="fieldInstance field/getFieldInstance; types fieldInstance/typesParams">