prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Organization view pages result in 500 error
  Only on stag.  I tested several different orgs. 
  
  ![image](https://cloud.githubusercontent.com/assets/1654485/5165739/e9046902-73e8-11e4-9358-19cd8652c0c8.png)
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ckanext-hdx_search/ckanext/hdx_search/plugin.py`
  Content:
  ```
  1 import logging, re
  2 import ckan.plugins as plugins
  3 import ckan.plugins.toolkit as tk
  4 import ckan.lib.plugins as lib_plugins
  5 
  6 def convert_country(q):
  7     for c in tk.get_action('group_list')({'user':'127.0.0.1'},{'all_fields': True}):
  8         if re.findall(c['display_name'].lower(),q.lower()):
  9             q += ' '+c['name']
  10     return q
  11 
  12 class HDXSearchPlugin(plugins.SingletonPlugin):
  13     plugins.implements(plugins.IConfigurer, inherit=False)
  14     plugins.implements(plugins.IRoutes, inherit=True)
  15     plugins.implements(plugins.ITemplateHelpers, inherit=False)
  16     plugins.implements(plugins.IPackageController, inherit=True)
  17 
  18     def update_config(self, config):
  19         tk.add_template_directory(config, 'templates')
  20 
  21     def get_helpers(self):
  22         return {}
  23 
  24     def before_map(self, map):
  25         map.connect('search', '/search',
  26                     controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')
  27         map.connect('simple_search',
  28             '/dataset', controller='ckanext.hdx_search.controllers.simple_search_controller:HDXSimpleSearchController', action='package_search')
  29         return map
  30 
  31     def after_map(self, map):
  32         map.connect('search', '/search',
  33                     controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')
  34         map.connect('simple_search',
  35             '/dataset', controller='ckanext.hdx_search.controllers.simple_search_controller:HDXSimpleSearchController', action='package_search')
  36         return map
  37 
  38     def before_search(self, search_params):
  39         search_params['q'] = convert_country(search_params['q'])
  40         if 'facet.field' in search_params and 'vocab_Topics' not in search_params['facet.field']:
  41             search_params['facet.field'].append('vocab_Topics')
  42 
  43         # If indicator flag is set, search only that type
  44         if 'ext_indicator' in search_params['extras']:
  45             if int(search_params['extras']['ext_indicator']) == 1:
  46                 search_params['fq'] = search_params['fq'] + ' +extras_indicator:1'
  47             elif int(search_params['extras']['ext_indicator']) == 0:
  48                 search_params['fq'] = search_params[
  49                     'fq'] + ' -extras_indicator:1'
  50         return search_params
  51 
  52     def after_search(self, search_results, search_params):
  53         return search_results
  54 
  55     def before_view(self, pkg_dict):
  56         return pkg_dict
  57
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/ckanext-hdx_search/ckanext/hdx_search/plugin.py b/ckanext-hdx_search/ckanext/hdx_search/plugin.py
  --- a/ckanext-hdx_search/ckanext/hdx_search/plugin.py
  +++ b/ckanext-hdx_search/ckanext/hdx_search/plugin.py
  @@ -36,7 +36,7 @@
           return map
   
       def before_search(self, search_params):
  -        search_params['q'] = convert_country(search_params['q'])
  +        #search_params['q'] = convert_country(search_params['q'])
           if 'facet.field' in search_params and 'vocab_Topics' not in search_params['facet.field']:
               search_params['facet.field'].append('vocab_Topics')
  
verification_info: {"golden_diff": "diff --git a/ckanext-hdx_search/ckanext/hdx_search/plugin.py b/ckanext-hdx_search/ckanext/hdx_search/plugin.py\n--- a/ckanext-hdx_search/ckanext/hdx_search/plugin.py\n+++ b/ckanext-hdx_search/ckanext/hdx_search/plugin.py\n@@ -36,7 +36,7 @@\n         return map\n \n     def before_search(self, search_params):\n-        search_params['q'] = convert_country(search_params['q'])\n+        #search_params['q'] = convert_country(search_params['q'])\n         if 'facet.field' in search_params and 'vocab_Topics' not in search_params['facet.field']:\n             search_params['facet.field'].append('vocab_Topics')\n", "issue": "Organization view pages result in 500 error\nOnly on stag.  I tested several different orgs. \n\n![image](https://cloud.githubusercontent.com/assets/1654485/5165739/e9046902-73e8-11e4-9358-19cd8652c0c8.png)\n\n", "before_files": [{"content": "import logging, re\nimport ckan.plugins as plugins\nimport ckan.plugins.toolkit as tk\nimport ckan.lib.plugins as lib_plugins\n\ndef convert_country(q):\n    for c in tk.get_action('group_list')({'user':'127.0.0.1'},{'all_fields': True}):\n        if re.findall(c['display_name'].lower(),q.lower()):\n            q += ' '+c['name']\n    return q\n\nclass HDXSearchPlugin(plugins.SingletonPlugin):\n    plugins.implements(plugins.IConfigurer, inherit=False)\n    plugins.implements(plugins.IRoutes, inherit=True)\n    plugins.implements(plugins.ITemplateHelpers, inherit=False)\n    plugins.implements(plugins.IPackageController, inherit=True)\n\n    def update_config(self, config):\n        tk.add_template_directory(config, 'templates')\n\n    def get_helpers(self):\n        return {}\n\n    def before_map(self, map):\n        map.connect('search', '/search',\n                    controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')\n        map.connect('simple_search',\n            '/dataset', controller='ckanext.hdx_search.controllers.simple_search_controller:HDXSimpleSearchController', action='package_search')\n        return map\n\n    def after_map(self, map):\n        map.connect('search', '/search',\n                    controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')\n        map.connect('simple_search',\n            '/dataset', controller='ckanext.hdx_search.controllers.simple_search_controller:HDXSimpleSearchController', action='package_search')\n        return map\n\n    def before_search(self, search_params):\n        search_params['q'] = convert_country(search_params['q'])\n        if 'facet.field' in search_params and 'vocab_Topics' not in search_params['facet.field']:\n            search_params['facet.field'].append('vocab_Topics')\n\n        # If indicator flag is set, search only that type\n        if 'ext_indicator' in search_params['extras']:\n            if int(search_params['extras']['ext_indicator']) == 1:\n                search_params['fq'] = search_params['fq'] + ' +extras_indicator:1'\n            elif int(search_params['extras']['ext_indicator']) == 0:\n                search_params['fq'] = search_params[\n                    'fq'] + ' -extras_indicator:1'\n        return search_params\n\n    def after_search(self, search_results, search_params):\n        return search_results\n\n    def before_view(self, pkg_dict):\n        return pkg_dict\n", "path": "ckanext-hdx_search/ckanext/hdx_search/plugin.py"}], "after_files": [{"content": "import logging, re\nimport ckan.plugins as plugins\nimport ckan.plugins.toolkit as tk\nimport ckan.lib.plugins as lib_plugins\n\ndef convert_country(q):\n    for c in tk.get_action('group_list')({'user':'127.0.0.1'},{'all_fields': True}):\n        if re.findall(c['display_name'].lower(),q.lower()):\n            q += ' '+c['name']\n    return q\n\nclass HDXSearchPlugin(plugins.SingletonPlugin):\n    plugins.implements(plugins.IConfigurer, inherit=False)\n    plugins.implements(plugins.IRoutes, inherit=True)\n    plugins.implements(plugins.ITemplateHelpers, inherit=False)\n    plugins.implements(plugins.IPackageController, inherit=True)\n\n    def update_config(self, config):\n        tk.add_template_directory(config, 'templates')\n\n    def get_helpers(self):\n        return {}\n\n    def before_map(self, map):\n        map.connect('search', '/search',\n                    controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')\n        map.connect('simple_search',\n            '/dataset', controller='ckanext.hdx_search.controllers.simple_search_controller:HDXSimpleSearchController', action='package_search')\n        return map\n\n    def after_map(self, map):\n        map.connect('search', '/search',\n                    controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')\n        map.connect('simple_search',\n            '/dataset', controller='ckanext.hdx_search.controllers.simple_search_controller:HDXSimpleSearchController', action='package_search')\n        return map\n\n    def before_search(self, search_params):\n        #search_params['q'] = convert_country(search_params['q'])\n        if 'facet.field' in search_params and 'vocab_Topics' not in search_params['facet.field']:\n            search_params['facet.field'].append('vocab_Topics')\n\n        # If indicator flag is set, search only that type\n        if 'ext_indicator' in search_params['extras']:\n            if int(search_params['extras']['ext_indicator']) == 1:\n                search_params['fq'] = search_params['fq'] + ' +extras_indicator:1'\n            elif int(search_params['extras']['ext_indicator']) == 0:\n                search_params['fq'] = search_params[\n                    'fq'] + ' -extras_indicator:1'\n        return search_params\n\n    def after_search(self, search_results, search_params):\n        return search_results\n\n    def before_view(self, pkg_dict):\n        return pkg_dict\n", "path": "ckanext-hdx_search/ckanext/hdx_search/plugin.py"}]}