Merge branch 'master' of git://github.com/lapilofu/philo
[philo.git] / contrib / sobol / search.py
index cce3ec6..33603f3 100644 (file)
@@ -42,8 +42,9 @@ class SearchRegistry(object):
        def register(self, search, slug=None):
                slug = slug or search.slug
                if slug in self._registry:
-                       if self._registry[slug] != search:
-                               raise RegistrationError("A different search is already registered as `%s`")
+                       registered = self._registry[slug]
+                       if registered.__module__ != search.__module__:
+                               raise RegistrationError("A different search is already registered as `%s`" % slug)
                else:
                        self._registry[slug] = search
        
@@ -69,6 +70,9 @@ class SearchRegistry(object):
        
        def __getitem__(self, key):
                return self._registry[key]
+       
+       def __iter__(self):
+               return self._registry.__iter__()
 
 
 registry = SearchRegistry()
@@ -90,7 +94,7 @@ class Result(object):
                return self.search.get_result_title(self.result)
        
        def get_url(self):
-               return self.search.get_result_querydict(self.result).urlencode()
+               return "?%s" % self.search.get_result_querydict(self.result).urlencode()
        
        def get_template(self):
                return self.search.get_result_template(self.result)
@@ -98,13 +102,17 @@ class Result(object):
        def get_extra_context(self):
                return self.search.get_result_extra_context(self.result)
        
-       def render(self):
-               t = self.get_template()
-               c = Context(self.get_extra_context())
-               c.update({
+       def get_context(self):
+               context = self.get_extra_context()
+               context.update({
                        'title': self.get_title(),
                        'url': self.get_url()
                })
+               return context
+       
+       def render(self):
+               t = self.get_template()
+               c = Context(self.get_context())
                return t.render(c)
        
        def __unicode__(self):
@@ -211,9 +219,6 @@ class BaseSearch(object):
                        self._result_template = Template(DEFAULT_RESULT_TEMPLATE_STRING)
                return self._result_template
        
-       def get_ajax_result_template(self, result):
-               return getattr(self, 'ajax_result_template', DEFAULT_RESULT_TEMPLATE_STRING)
-       
        def get_result_extra_context(self, result):
                return {}
        
@@ -357,7 +362,7 @@ else:
                def parse_response(self, response, limit=None):
                        strainer = self.strainer
                        soup = BeautifulSoup(response, parseOnlyThese=strainer)
-                       return self.parse_results(soup[:limit])
+                       return self.parse_results(soup.findAll(recursive=False, limit=limit))
                
                def parse_results(self, results):
                        """