prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Search in EUTF akvo site
  Partner team had a training and workshop with EUTF last week and discovered that search terms in EUTF akvo site returned unrelated results.
  
  Search for tombouctou shows up a project of SNV in EUTF akvo page, which is confusing for the partner as they expect to see their own projects only on their akvo site. 
  
  <img width="1070" alt="screen shot 2017-02-06 at 15 56 41" src="https://cloud.githubusercontent.com/assets/21127166/22652066/45bdf606-ec85-11e6-9c05-25d421b329c1.png">
  
  What the partner expects is to see just projects where they are one of the participating partners. 
  If the search does not match any of their projects, it should then not return anything. 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `akvo/rest/views/typeahead.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 
  3 """Akvo RSR is covered by the GNU Affero General Public License.
  4 See more details in the license.txt file located at the root folder of the
  5 Akvo RSR module. For additional details on the GNU license please
  6 see < http://www.gnu.org/licenses/agpl.html >.
  7 """
  8 
  9 from akvo.rest.serializers import (TypeaheadCountrySerializer,
  10                                    TypeaheadOrganisationSerializer,
  11                                    TypeaheadProjectSerializer,
  12                                    TypeaheadProjectUpdateSerializer)
  13 
  14 from akvo.codelists.models import Country, Version
  15 from akvo.rsr.models import Organisation, Project, ProjectUpdate
  16 
  17 from django.conf import settings
  18 
  19 from rest_framework.decorators import api_view
  20 from rest_framework.response import Response
  21 
  22 
  23 def rejig(queryset, serializer):
  24     """Rearrange & add queryset count to the response data."""
  25     return {
  26         'count': queryset.count(),
  27         'results': serializer.data
  28     }
  29 
  30 
  31 @api_view(['GET'])
  32 def typeahead_country(request):
  33     iati_version = Version.objects.get(code=settings.IATI_VERSION)
  34     countries = Country.objects.filter(version=iati_version)
  35     return Response(
  36         rejig(countries, TypeaheadCountrySerializer(countries, many=True))
  37     )
  38 
  39 
  40 @api_view(['GET'])
  41 def typeahead_organisation(request):
  42     organisations = Organisation.objects.all()
  43     return Response(
  44         rejig(organisations, TypeaheadOrganisationSerializer(organisations,
  45                                                              many=True))
  46     )
  47 
  48 
  49 @api_view(['GET'])
  50 def typeahead_user_organisations(request):
  51     user = request.user
  52     is_admin = user.is_active and (user.is_superuser or user.is_admin)
  53     organisations = user.approved_organisations() if not is_admin else Organisation.objects.all()
  54     return Response(
  55         rejig(organisations, TypeaheadOrganisationSerializer(organisations,
  56                                                              many=True))
  57     )
  58 
  59 
  60 @api_view(['GET'])
  61 def typeahead_project(request):
  62     projects = Project.objects.all().exclude(title='')
  63     return Response(
  64         rejig(projects, TypeaheadProjectSerializer(projects, many=True))
  65     )
  66 
  67 
  68 @api_view(['GET'])
  69 def typeahead_user_projects(request):
  70     user = request.user
  71     is_admin = user.is_active and (user.is_superuser or user.is_admin)
  72     if is_admin:
  73         projects = Project.objects.all()
  74     else:
  75         projects = user.approved_organisations().all_projects()
  76     projects = projects.exclude(title='')
  77     return Response(
  78         rejig(projects, TypeaheadProjectSerializer(projects, many=True))
  79     )
  80 
  81 
  82 @api_view(['GET'])
  83 def typeahead_impact_projects(request):
  84     user = request.user
  85     projects = Project.objects.all() if user.is_admin or user.is_superuser else user.my_projects()
  86     projects = projects.published().filter(is_impact_project=True).order_by('title')
  87 
  88     return Response(
  89         rejig(projects, TypeaheadProjectSerializer(projects, many=True))
  90     )
  91 
  92 
  93 @api_view(['GET'])
  94 def typeahead_projectupdate(request):
  95     updates = ProjectUpdate.objects.all()
  96     return Response(
  97         rejig(updates, TypeaheadProjectUpdateSerializer(updates, many=True))
  98     )
  99
  ```
  --- 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/akvo/rest/views/typeahead.py b/akvo/rest/views/typeahead.py
  --- a/akvo/rest/views/typeahead.py
  +++ b/akvo/rest/views/typeahead.py
  @@ -13,6 +13,7 @@
   
   from akvo.codelists.models import Country, Version
   from akvo.rsr.models import Organisation, Project, ProjectUpdate
  +from akvo.rsr.views.project import _project_directory_coll
   
   from django.conf import settings
   
  @@ -59,7 +60,39 @@
   
   @api_view(['GET'])
   def typeahead_project(request):
  -    projects = Project.objects.all().exclude(title='')
  +    """Return the typeaheads for projects.
  +
  +    Without any query parameters, it returns the info for all the projects in
  +    the current context -- changes depending on whether we are on a partner
  +    site, or the RSR site.
  +
  +    If a project query parameter with a project id is passed, the info for all
  +    projects associated with partners for the specified project is returned.
  +
  +    NOTE: The unauthenticated user gets information about all the projects when
  +    using this API endpoint.  More permission checking will need to be added,
  +    if the amount of data being returned is changed.
  +
  +    """
  +    project_id = request.GET.get('project', None)
  +    if project_id is None:
  +        project = None
  +
  +    else:
  +        try:
  +            project = Project.objects.get(id=project_id)
  +        except Project.DoesNotExist:
  +            project = None
  +
  +    if project is None:
  +        # Search bar - organization projects, published
  +        projects = _project_directory_coll(request)
  +
  +    else:
  +        # Project editor - all projects of partners for this project
  +        projects = Project.objects.of_partners(project.partners.distinct()).distinct()
  +
  +    projects = projects.exclude(title='')
       return Response(
           rejig(projects, TypeaheadProjectSerializer(projects, many=True))
       )
  
verification_info: {"golden_diff": "diff --git a/akvo/rest/views/typeahead.py b/akvo/rest/views/typeahead.py\n--- a/akvo/rest/views/typeahead.py\n+++ b/akvo/rest/views/typeahead.py\n@@ -13,6 +13,7 @@\n \n from akvo.codelists.models import Country, Version\n from akvo.rsr.models import Organisation, Project, ProjectUpdate\n+from akvo.rsr.views.project import _project_directory_coll\n \n from django.conf import settings\n \n@@ -59,7 +60,39 @@\n \n @api_view(['GET'])\n def typeahead_project(request):\n-    projects = Project.objects.all().exclude(title='')\n+    \"\"\"Return the typeaheads for projects.\n+\n+    Without any query parameters, it returns the info for all the projects in\n+    the current context -- changes depending on whether we are on a partner\n+    site, or the RSR site.\n+\n+    If a project query parameter with a project id is passed, the info for all\n+    projects associated with partners for the specified project is returned.\n+\n+    NOTE: The unauthenticated user gets information about all the projects when\n+    using this API endpoint.  More permission checking will need to be added,\n+    if the amount of data being returned is changed.\n+\n+    \"\"\"\n+    project_id = request.GET.get('project', None)\n+    if project_id is None:\n+        project = None\n+\n+    else:\n+        try:\n+            project = Project.objects.get(id=project_id)\n+        except Project.DoesNotExist:\n+            project = None\n+\n+    if project is None:\n+        # Search bar - organization projects, published\n+        projects = _project_directory_coll(request)\n+\n+    else:\n+        # Project editor - all projects of partners for this project\n+        projects = Project.objects.of_partners(project.partners.distinct()).distinct()\n+\n+    projects = projects.exclude(title='')\n     return Response(\n         rejig(projects, TypeaheadProjectSerializer(projects, many=True))\n     )\n", "issue": "Search in EUTF akvo site\nPartner team had a training and workshop with EUTF last week and discovered that search terms in EUTF akvo site returned unrelated results.\r\n\r\nSearch for tombouctou shows up a project of SNV in EUTF akvo page, which is confusing for the partner as they expect to see their own projects only on their akvo site. \r\n\r\n<img width=\"1070\" alt=\"screen shot 2017-02-06 at 15 56 41\" src=\"https://cloud.githubusercontent.com/assets/21127166/22652066/45bdf606-ec85-11e6-9c05-25d421b329c1.png\">\r\n\r\nWhat the partner expects is to see just projects where they are one of the participating partners. \r\nIf the search does not match any of their projects, it should then not return anything. \n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\nSee more details in the license.txt file located at the root folder of the\nAkvo RSR module. For additional details on the GNU license please\nsee < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rest.serializers import (TypeaheadCountrySerializer,\n                                   TypeaheadOrganisationSerializer,\n                                   TypeaheadProjectSerializer,\n                                   TypeaheadProjectUpdateSerializer)\n\nfrom akvo.codelists.models import Country, Version\nfrom akvo.rsr.models import Organisation, Project, ProjectUpdate\n\nfrom django.conf import settings\n\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\n\n\ndef rejig(queryset, serializer):\n    \"\"\"Rearrange & add queryset count to the response data.\"\"\"\n    return {\n        'count': queryset.count(),\n        'results': serializer.data\n    }\n\n\n@api_view(['GET'])\ndef typeahead_country(request):\n    iati_version = Version.objects.get(code=settings.IATI_VERSION)\n    countries = Country.objects.filter(version=iati_version)\n    return Response(\n        rejig(countries, TypeaheadCountrySerializer(countries, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_organisation(request):\n    organisations = Organisation.objects.all()\n    return Response(\n        rejig(organisations, TypeaheadOrganisationSerializer(organisations,\n                                                             many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_user_organisations(request):\n    user = request.user\n    is_admin = user.is_active and (user.is_superuser or user.is_admin)\n    organisations = user.approved_organisations() if not is_admin else Organisation.objects.all()\n    return Response(\n        rejig(organisations, TypeaheadOrganisationSerializer(organisations,\n                                                             many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_project(request):\n    projects = Project.objects.all().exclude(title='')\n    return Response(\n        rejig(projects, TypeaheadProjectSerializer(projects, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_user_projects(request):\n    user = request.user\n    is_admin = user.is_active and (user.is_superuser or user.is_admin)\n    if is_admin:\n        projects = Project.objects.all()\n    else:\n        projects = user.approved_organisations().all_projects()\n    projects = projects.exclude(title='')\n    return Response(\n        rejig(projects, TypeaheadProjectSerializer(projects, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_impact_projects(request):\n    user = request.user\n    projects = Project.objects.all() if user.is_admin or user.is_superuser else user.my_projects()\n    projects = projects.published().filter(is_impact_project=True).order_by('title')\n\n    return Response(\n        rejig(projects, TypeaheadProjectSerializer(projects, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_projectupdate(request):\n    updates = ProjectUpdate.objects.all()\n    return Response(\n        rejig(updates, TypeaheadProjectUpdateSerializer(updates, many=True))\n    )\n", "path": "akvo/rest/views/typeahead.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"Akvo RSR is covered by the GNU Affero General Public License.\nSee more details in the license.txt file located at the root folder of the\nAkvo RSR module. For additional details on the GNU license please\nsee < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rest.serializers import (TypeaheadCountrySerializer,\n                                   TypeaheadOrganisationSerializer,\n                                   TypeaheadProjectSerializer,\n                                   TypeaheadProjectUpdateSerializer)\n\nfrom akvo.codelists.models import Country, Version\nfrom akvo.rsr.models import Organisation, Project, ProjectUpdate\nfrom akvo.rsr.views.project import _project_directory_coll\n\nfrom django.conf import settings\n\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\n\n\ndef rejig(queryset, serializer):\n    \"\"\"Rearrange & add queryset count to the response data.\"\"\"\n    return {\n        'count': queryset.count(),\n        'results': serializer.data\n    }\n\n\n@api_view(['GET'])\ndef typeahead_country(request):\n    iati_version = Version.objects.get(code=settings.IATI_VERSION)\n    countries = Country.objects.filter(version=iati_version)\n    return Response(\n        rejig(countries, TypeaheadCountrySerializer(countries, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_organisation(request):\n    organisations = Organisation.objects.all()\n    return Response(\n        rejig(organisations, TypeaheadOrganisationSerializer(organisations,\n                                                             many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_user_organisations(request):\n    user = request.user\n    is_admin = user.is_active and (user.is_superuser or user.is_admin)\n    organisations = user.approved_organisations() if not is_admin else Organisation.objects.all()\n    return Response(\n        rejig(organisations, TypeaheadOrganisationSerializer(organisations,\n                                                             many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_project(request):\n    \"\"\"Return the typeaheads for projects.\n\n    Without any query parameters, it returns the info for all the projects in\n    the current context -- changes depending on whether we are on a partner\n    site, or the RSR site.\n\n    If a project query parameter with a project id is passed, the info for all\n    projects associated with partners for the specified project is returned.\n\n    NOTE: The unauthenticated user gets information about all the projects when\n    using this API endpoint.  More permission checking will need to be added,\n    if the amount of data being returned is changed.\n\n    \"\"\"\n    project_id = request.GET.get('project', None)\n    if project_id is None:\n        project = None\n\n    else:\n        try:\n            project = Project.objects.get(id=project_id)\n        except Project.DoesNotExist:\n            project = None\n\n    if project is None:\n        # Search bar - organization projects, published\n        projects = _project_directory_coll(request)\n\n    else:\n        # Project editor - all projects of partners for this project\n        projects = Project.objects.of_partners(project.partners.distinct()).distinct()\n\n    projects = projects.exclude(title='')\n    return Response(\n        rejig(projects, TypeaheadProjectSerializer(projects, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_user_projects(request):\n    user = request.user\n    is_admin = user.is_active and (user.is_superuser or user.is_admin)\n    if is_admin:\n        projects = Project.objects.all()\n    else:\n        projects = user.approved_organisations().all_projects()\n    projects = projects.exclude(title='')\n    return Response(\n        rejig(projects, TypeaheadProjectSerializer(projects, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_impact_projects(request):\n    user = request.user\n    projects = Project.objects.all() if user.is_admin or user.is_superuser else user.my_projects()\n    projects = projects.published().filter(is_impact_project=True).order_by('title')\n\n    return Response(\n        rejig(projects, TypeaheadProjectSerializer(projects, many=True))\n    )\n\n\n@api_view(['GET'])\ndef typeahead_projectupdate(request):\n    updates = ProjectUpdate.objects.all()\n    return Response(\n        rejig(updates, TypeaheadProjectUpdateSerializer(updates, many=True))\n    )\n", "path": "akvo/rest/views/typeahead.py"}]}