prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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. 
  
  </issue>
  <code>
  [start of akvo/rest/views/typeahead.py]
  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 from akvo.rsr.views.project import _project_directory_coll
  17 
  18 from django.conf import settings
  19 
  20 from rest_framework.decorators import api_view
  21 from rest_framework.response import Response
  22 
  23 
  24 def rejig(queryset, serializer):
  25     """Rearrange & add queryset count to the response data."""
  26     return {
  27         'count': queryset.count(),
  28         'results': serializer.data
  29     }
  30 
  31 
  32 @api_view(['GET'])
  33 def typeahead_country(request):
  34     iati_version = Version.objects.get(code=settings.IATI_VERSION)
  35     countries = Country.objects.filter(version=iati_version)
  36     return Response(
  37         rejig(countries, TypeaheadCountrySerializer(countries, many=True))
  38     )
  39 
  40 
  41 @api_view(['GET'])
  42 def typeahead_organisation(request):
  43     organisations = Organisation.objects.all()
  44     return Response(
  45         rejig(organisations, TypeaheadOrganisationSerializer(organisations,
  46                                                              many=True))
  47     )
  48 
  49 
  50 @api_view(['GET'])
  51 def typeahead_user_organisations(request):
  52     user = request.user
  53     is_admin = user.is_active and (user.is_superuser or user.is_admin)
  54     organisations = user.approved_organisations() if not is_admin else Organisation.objects.all()
  55     return Response(
  56         rejig(organisations, TypeaheadOrganisationSerializer(organisations,
  57                                                              many=True))
  58     )
  59 
  60 
  61 @api_view(['GET'])
  62 def typeahead_project(request):
  63     """Return the typeaheads for projects.
  64 
  65     Without any query parameters, it returns the info for all the projects in
  66     the current context -- changes depending on whether we are on a partner
  67     site, or the RSR site.
  68 
  69     If a project query parameter with a project id is passed, the info for all
  70     projects associated with partners for the specified project is returned.
  71 
  72     NOTE: The unauthenticated user gets information about all the projects when
  73     using this API endpoint.  More permission checking will need to be added,
  74     if the amount of data being returned is changed.
  75 
  76     """
  77     project_id = request.GET.get('project', None)
  78     if project_id is None:
  79         project = None
  80 
  81     else:
  82         try:
  83             project = Project.objects.get(id=project_id)
  84         except Project.DoesNotExist:
  85             project = None
  86 
  87     if project is None:
  88         # Search bar - organization projects, published
  89         projects = _project_directory_coll(request)
  90 
  91     else:
  92         # Project editor - all projects of partners for this project
  93         projects = Project.objects.of_partners(project.partners.distinct()).distinct()
  94 
  95     projects = projects.exclude(title='')
  96     return Response(
  97         rejig(projects, TypeaheadProjectSerializer(projects, many=True))
  98     )
  99 
  100 
  101 @api_view(['GET'])
  102 def typeahead_user_projects(request):
  103     user = request.user
  104     is_admin = user.is_active and (user.is_superuser or user.is_admin)
  105     if is_admin:
  106         projects = Project.objects.all()
  107     else:
  108         projects = user.approved_organisations().all_projects()
  109     projects = projects.exclude(title='')
  110     return Response(
  111         rejig(projects, TypeaheadProjectSerializer(projects, many=True))
  112     )
  113 
  114 
  115 @api_view(['GET'])
  116 def typeahead_impact_projects(request):
  117     user = request.user
  118     projects = Project.objects.all() if user.is_admin or user.is_superuser else user.my_projects()
  119     projects = projects.published().filter(is_impact_project=True).order_by('title')
  120 
  121     return Response(
  122         rejig(projects, TypeaheadProjectSerializer(projects, many=True))
  123     )
  124 
  125 
  126 @api_view(['GET'])
  127 def typeahead_projectupdate(request):
  128     updates = ProjectUpdate.objects.all()
  129     return Response(
  130         rejig(updates, TypeaheadProjectUpdateSerializer(updates, many=True))
  131     )
  132
  [end of akvo/rest/views/typeahead.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
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
  @@ -66,32 +66,22 @@
       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.
  +    If a published query parameter is passed, only projects that have been
  +    published are 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
  -
  +    if request.GET.get('published', '0') == '0':
  +        # Project editor - organization projects, all
  +        page = request.rsr_page
  +        projects = page.organisation.all_projects() if page else Project.objects.all()
       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@@ -66,32 +66,22 @@\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+    If a published query parameter is passed, only projects that have been\n+    published are 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+    if request.GET.get('published', '0') == '0':\n+        # Project editor - organization projects, all\n+        page = request.rsr_page\n+        projects = page.organisation.all_projects() if page else Project.objects.all()\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", "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\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"}]}