[Checkins] SVN: z3c.formwidget.query/trunk/src/z3c/formwidget/query/widget.py start with the terms from the current selection or current value and then add the terms from the query source search, rather than the other way round, so that the search can optionally return a fake value if the real value is expensive to wake up

David Glick davidglick at onenw.org
Wed Mar 18 01:26:55 EDT 2009


Log message for revision 98217:
  start with the terms from the current selection or current value and then add the terms from the query source search, rather than the other way round, so that the search can optionally return a fake value if the real value is expensive to wake up

Changed:
  U   z3c.formwidget.query/trunk/src/z3c/formwidget/query/widget.py

-=-
Modified: z3c.formwidget.query/trunk/src/z3c/formwidget/query/widget.py
===================================================================
--- z3c.formwidget.query/trunk/src/z3c/formwidget/query/widget.py	2009-03-17 21:27:19 UTC (rev 98216)
+++ z3c.formwidget.query/trunk/src/z3c/formwidget/query/widget.py	2009-03-18 05:26:55 UTC (rev 98217)
@@ -95,38 +95,16 @@
         source = self.bound_source
 
         self.terms = SourceTerms(self.context, self.request, self.form, self.field, self, source)
-
-        # Set up query form
-
-        subform = self.subform = QuerySubForm(QueryContext(), self.request, self.name)
-        subform.update()
-
-        data, errors = subform.extractData()
-        if errors:
-            return
-
-        # Perform the search
-
-        query = data['query']
-        if query is not None:
-            terms = set(source.search(query))
-        else:
-            terms = set()
         
-        # If we have values in the request, add these to the terms. 
-        # Otherwise, take tha value from
-        # the current saved value.
+        # If we have values in the request, use these to get the terms.
+        # Otherwise, take the value from the current saved value.
 
         request_values = self.extract(default=z3c.form.interfaces.NOVALUE)
         if request_values is not z3c.form.interfaces.NOVALUE:
             if not isinstance(request_values, (tuple, set, list)):
                 request_values = (request_values,)
 
-            tokens = set([term.value for term in terms])
-            for token in request_values:
-                if token and token not in tokens:
-                    term = source.getTermByToken(token)
-                    terms.add(term)
+            terms = set([source.getTermByToken(token) for token in request_values if token])
 
         elif not self.ignoreContext:
             
@@ -136,10 +114,26 @@
             if not isinstance(selection, (tuple, set, list)):
                 selection = [selection]
             
-            values = set([term.token for term in terms])
-            for value in selection:
-                if value and value not in values:
-                    terms.add(source.getTerm(value))
+            terms = set([source.getTerm(value) for value in selection if value])
+
+        # Set up query form
+
+        subform = self.subform = QuerySubForm(QueryContext(), self.request, self.name)
+        subform.update()
+
+        data, errors = subform.extractData()
+        if errors:
+            return
+
+        # perform the search
+
+        query = data['query']
+        if query is not None:
+            query_terms = set(source.search(query))
+            tokens = set([term.token for term in terms])
+            for term in query_terms:
+                if term.token not in tokens:
+                    terms.add(term)
         
         # set terms
         self.terms = QueryTerms(self.context, self.request, self.form, self.field, self, terms)



More information about the Checkins mailing list