# HG changeset patch
# User Arthur Lutz <arthur.lutz@logilab.fr>
# Date 1464803427 -7200
#      Wed Jun 01 19:50:27 2016 +0200
# Node ID 452c9e6ab6d97a9ba22ab567ca2676f855a414be
# Parent  727f5c30d1c4d975938f42f3a32a170df2fdeb3b
flake8

diff --git a/es.py b/es.py
--- a/es.py
+++ b/es.py
@@ -31,20 +31,20 @@
                         'french_snowball': {'type': 'snowball',
                                             'language': 'French'}
                         }
-             }
-            ,
-            "mappings" : {
-                "Did" : {
-                    "properties" : {
-                        "unitid" : {
-                            "type" : "string",
-                            "index" : "not_analyzed" 
+             },
+            "mappings": {
+                "Did": {
+                    "properties": {
+                        "unitid": {
+                            "type": "string",
+                            "index": "not_analyzed"
                         }
                     }
                 }
             }
 
-    }
+            }
+
 
 def indexable_types(schema):
     global INDEXABLE_TYPES
diff --git a/test/test_compose_search.py b/test/test_compose_search.py
--- a/test/test_compose_search.py
+++ b/test/test_compose_search.py
@@ -24,20 +24,23 @@
 
 class ComposeSearchTestCase(testlib.TestCase):
 
-    
     def compose_search(self, query):
         self.search = Search()
         return compose_search(self.search, query)
-    
+
     def test_simple(self):
         self.assertEquals(self.compose_search('test').to_dict(),
                           self.search.query('bool',
-                                            must=[Q('multi_match', query='test', fields=())]).to_dict())
-    
+                                            must=[Q('multi_match',
+                                                    query='test',
+                                                    fields=())]).to_dict())
+
     def test_two_terms(self):
         self.assertEquals(self.compose_search('test this').to_dict(),
                           self.search.query('bool',
-                                            must=[Q('multi_match', query='test this', fields=())]).to_dict())
+                                            must=[Q('multi_match',
+                                                    query='test this',
+                                                    fields=())]).to_dict())
 
     def test_two_with_quotes(self):
         self.assertEquals(self.compose_search('"test this"').to_dict(),
@@ -58,7 +61,7 @@
                                                     query='test this',
                                                     type="phrase",
                                                     fields=())]).to_dict())
-    
+
     # def test_three_with_quotes(self):
     #     self.assertEquals(self.compose_search('"test this" this_too').to_dict(),
     #                       Q('bool',
@@ -69,23 +72,34 @@
     def test_two_with_negate(self):
         self.assertEquals(self.compose_search('test -this').to_dict(),
                           self.search.query('bool',
-                            must=[Q('multi_match', query='test', fields=())],
-                            must_not=[Q('multi_match', query='this', fields=())]).to_dict())
+                                            must=[
+                                                Q('multi_match',
+                                                  query='test',
+                                                  fields=())],
+                                            must_not=[Q('multi_match',
+                                                        query='this',
+                                                        fields=())]).to_dict())
 
     def test_two_with_or(self):
         self.assertEquals(self.compose_search('test or this').to_dict(),
                           self.search.query('bool',
-                            should=[Q('multi_match', query='test', fields=()),
-                                    Q('multi_match', query='this', fields=())]).to_dict())
+                                            should=[Q('multi_match',
+                                                      query='test',
+                                                      fields=()),
+                                                    Q('multi_match',
+                                                      query='this',
+                                                      fields=())]).to_dict())
         # self.assertEquals(self.compose_search('test ou this'),
         #                   self.search.query('bool',
         #                     should=[Q('multi_match', query='test', fields=()),
-        #                             Q('multi_match', query='this', fields=())]).to_dict())
+        # Q('multi_match', query='this', fields=())]).to_dict())
 
     def test_or_on_its_own(self):
         self.assertEquals(self.compose_search('or').to_dict(),
                           self.search.query('bool',
-                            must=[Q('multi_match', query='or', fields=())]).to_dict())
+                                            must=[Q('multi_match',
+                                                    query='or',
+                                                    fields=())]).to_dict())
 
 
 if __name__ == '__main__':
diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -44,7 +44,8 @@
 
 class CWFacetedSearch(FacetedSearch):
     # fields that should be searched
-    fields = ["unitid^6", "title^3", "unittitle^3", "name^3", "content^2", 'content', '_all']
+    fields = ["unitid^6", "title^3", "unittitle^3",
+              "name^3", "content^2", 'content', '_all']
 
     facets = {
         # use bucket aggregations to define facets
@@ -63,7 +64,8 @@
     def query(self, search, query):
         if query:
             return compose_search(search, query=query, fields=self.fields)
-            #return search.query('multi_match', fields=self.fields, query=query)
+            # return search.query('multi_match', fields=self.fields,
+            # query=query)
         return search
 
     def highlight(self, search):
@@ -124,17 +126,21 @@
             infos = result.to_dict()
             infos['_score'] = result.meta.score
             infos['keys'] = result.to_dict().keys()
-            infos['url'] = infos['cwuri'].startswith('_auto_generated') and infos['eid'] or infos['cwuri']
-            infos.setdefault('title', infos.get('name', infos.get('reference', infos.get('unittitle', u'n/a'))))
+            infos['url'] = infos['cwuri'].startswith(
+                '_auto_generated') and infos['eid'] or infos['cwuri']
+            infos.setdefault(
+                'title', infos.get('name', infos.get('reference', infos.get('unittitle', u'n/a'))))
             try:
-                self.w(u'<a href="%(url)s">%(title)s</a> (%(_score).2f)<br/>' % (infos))
+                self.w(
+                    u'<a href="%(url)s">%(title)s</a> (%(_score).2f)<br/>' % (infos))
                 if self._cw.form.get('debug-es'):
                     self.w(u' [%(keys)s] <br/>' % infos)
             except KeyError:
                 self.w(u'Missing key in : %s' % infos.keys())
             try:
                 for fragment in result.meta.highlight.content:
-                    self.w(u'... %s' % BeautifulSoup(fragment, 'lxml').get_text())
+                    self.w(u'... %s' %
+                           BeautifulSoup(fragment, 'lxml').get_text())
                     self.w(u' ... <br/>')
             except AttributeError:
                 pass
@@ -158,7 +164,6 @@
             total_pages = response.hits.total / 10
             page_padding = 3
 
-
             if current_page > page_padding:
                 for page in range(1,
                                   min(page_padding + 1,
@@ -173,11 +178,10 @@
                 if current_page < total_pages - page_padding * 2:
                     ul(t.li(t.a("...")))
                 for page in range(max(current_page + page_padding,
-                                      total_pages -page_padding),
+                                      total_pages - page_padding),
                                   total_pages):
                     self.page_number(url_params, page, current_page, ul)
 
-
             url_params['page'] = current_page + 1
             if current_page + 1 >= (total_pages):
                 ul(t.li(t.a('>>>')))
@@ -221,8 +225,9 @@
                 else:
                     del url_params['es_{}'.format(attribute)]
                 url = self._cw.build_url(**url_params)
+                content = selected and '<b>{}</b>'.format(tag) or tag
                 self.w(facet_item.format(url,
-                                         '<b>{}</b>'.format(tag) if selected else tag,
+                                         content,
                                          count))
             self.w(u'</div>')
         self.w(u'</div></aside>')