prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add organisation filter for maps API resources
  
  
  </issue>
  <code>
  [start of akvo/rest/views/project_update_location.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 Akvo RSR module.
  5 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
  6 
  7 
  8 from akvo.rsr.models import ProjectUpdateLocation
  9 from ..serializers import ProjectUpdateLocationSerializer, MapProjectUpdateLocationSerializer
  10 from ..viewsets import BaseRSRViewSet
  11 
  12 
  13 class ProjectUpdateLocationViewSet(BaseRSRViewSet):
  14     """
  15     API endpoint that allows organisation locations to be viewed or edited.
  16     """
  17     queryset = ProjectUpdateLocation.objects.all()
  18     serializer_class = ProjectUpdateLocationSerializer
  19 
  20 
  21 class MapProjectUpdateLocationViewSet(BaseRSRViewSet):
  22 
  23     """Returns a resource tailored for generating a map of update locations.
  24 
  25     Allowed parameters are:
  26     limit (default 100 / max 500), and
  27     location_target__project (filter on project ID)
  28     """
  29 
  30     filter_fields = ('location_target__project', )
  31     max_paginate_by = 500
  32     paginate_by = 100
  33     queryset = ProjectUpdateLocation.objects.select_related(
  34         'location_target',
  35         'location_target__project').only(
  36             'id', 'latitude', 'longitude',
  37             'location_target__id', 'location_target__project', 'location_target__title',
  38             'location_target__photo', 'location_target__video')
  39     serializer_class = MapProjectUpdateLocationSerializer
  40
  [end of akvo/rest/views/project_update_location.py]
  [start of akvo/rest/views/organisation_location.py]
  1 # -*- coding: utf-8 -*-
  2 """Akvo RSR is covered by the GNU Affero General Public License.
  3 See more details in the license.txt file located at the root folder of the Akvo RSR module.
  4 For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
  5 """
  6 
  7 from akvo.rsr.models import OrganisationLocation
  8 from ..serializers import OrganisationLocationSerializer, MapOrganisationLocationSerializer
  9 from ..viewsets import BaseRSRViewSet
  10 
  11 
  12 class OrganisationLocationViewSet(BaseRSRViewSet):
  13     """
  14     API endpoint that allows organisation locations to be viewed or edited.
  15     """
  16     queryset = OrganisationLocation.objects.all()
  17     serializer_class = OrganisationLocationSerializer
  18 
  19 
  20 class MapOrganisationLocationViewSet(BaseRSRViewSet):
  21 
  22     """Returns a resource tailored for generating a map of organisation locations.
  23 
  24     Allowed parameters are:
  25     limit (default 100 / max 500),
  26     location_target (filter on organisation ID), and
  27     country (filter on country ID)
  28     """
  29 
  30     filter_fields = ('location_target', 'country')
  31     max_paginate_by = 500
  32     paginate_by = 100
  33     queryset = OrganisationLocation.objects.select_related(
  34         'location_target', 'country').only(
  35             'id', 'latitude', 'longitude',
  36             'location_target__id', 'location_target__name',
  37             'location_target__logo',
  38             'country')
  39     serializer_class = MapOrganisationLocationSerializer
  40
  [end of akvo/rest/views/organisation_location.py]
  [start of akvo/rest/views/project_location.py]
  1 # -*- coding: utf-8 -*-
  2 """Akvo RSR is covered by the GNU Affero General Public License.
  3 See more details in the license.txt file located at the root folder of the Akvo RSR module.
  4 For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
  5 """
  6 
  7 from akvo.rsr.models import ProjectLocation
  8 from ..serializers import ProjectLocationSerializer, MapProjectLocationSerializer
  9 from ..viewsets import BaseRSRViewSet
  10 
  11 
  12 class ProjectLocationViewSet(BaseRSRViewSet):
  13     """
  14     """
  15     queryset = ProjectLocation.objects.all()
  16     serializer_class = ProjectLocationSerializer
  17     filter_fields = ('location_target', 'country', )
  18 
  19 
  20 class MapProjectLocationViewSet(BaseRSRViewSet):
  21 
  22     """Returns a resource tailored for generating a map of project locations.
  23 
  24     Allowed parameters are:
  25     limit (default 100 / max 500),
  26     location_target (filter on project ID), and
  27     country (filter on country ID)
  28     """
  29 
  30     filter_fields = ('location_target', 'country')
  31     max_paginate_by = 500
  32     paginate_by = 100
  33     queryset = ProjectLocation.objects.select_related(
  34         'location_target', 'country').only(
  35             'id', 'latitude', 'longitude',
  36             'location_target__id', 'location_target__title',
  37             'location_target__current_image',
  38             'country')
  39     serializer_class = MapProjectLocationSerializer
  40
  [end of akvo/rest/views/project_location.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/organisation_location.py b/akvo/rest/views/organisation_location.py
  --- a/akvo/rest/views/organisation_location.py
  +++ b/akvo/rest/views/organisation_location.py
  @@ -22,9 +22,9 @@
       """Returns a resource tailored for generating a map of organisation locations.
   
       Allowed parameters are:
  -    limit (default 100 / max 500),
  -    location_target (filter on organisation ID), and
  -    country (filter on country ID)
  +    __limit__ (default 100 / max 500),
  +    __location_target__ (filter on organisation ID), and
  +    __country__ (filter on country ID)
       """
   
       filter_fields = ('location_target', 'country')
  diff --git a/akvo/rest/views/project_location.py b/akvo/rest/views/project_location.py
  --- a/akvo/rest/views/project_location.py
  +++ b/akvo/rest/views/project_location.py
  @@ -22,12 +22,17 @@
       """Returns a resource tailored for generating a map of project locations.
   
       Allowed parameters are:
  -    limit (default 100 / max 500),
  -    location_target (filter on project ID), and
  -    country (filter on country ID)
  +    __limit__ (default 100 / max 500),
  +    __location_target__ (filter on project ID),
  +    __location_target\__partners__ (filter on organisation ID), and
  +    __country__ (filter on country ID)
       """
   
  -    filter_fields = ('location_target', 'country')
  +    filter_fields = (
  +        'location_target',
  +        'location_target__partners',
  +        'country'
  +    )
       max_paginate_by = 500
       paginate_by = 100
       queryset = ProjectLocation.objects.select_related(
  diff --git a/akvo/rest/views/project_update_location.py b/akvo/rest/views/project_update_location.py
  --- a/akvo/rest/views/project_update_location.py
  +++ b/akvo/rest/views/project_update_location.py
  @@ -23,11 +23,18 @@
       """Returns a resource tailored for generating a map of update locations.
   
       Allowed parameters are:
  -    limit (default 100 / max 500), and
  -    location_target__project (filter on project ID)
  +    __limit__ (default 100 / max 500),
  +    __location_target\__project__ (filter on project ID),
  +    __location_target\__project\__partners__
  +    (filter on organisation ID of the projects' organisations),
  +    __location_target\__user\__employers__ (filter on organisation ID of the users' organisations)
       """
   
  -    filter_fields = ('location_target__project', )
  +    filter_fields = (
  +        'location_target__project',
  +        'location_target__project__partners',
  +        'location_target__user__employers'
  +    )
       max_paginate_by = 500
       paginate_by = 100
       queryset = ProjectUpdateLocation.objects.select_related(
  
verification_info: {"golden_diff": "diff --git a/akvo/rest/views/organisation_location.py b/akvo/rest/views/organisation_location.py\n--- a/akvo/rest/views/organisation_location.py\n+++ b/akvo/rest/views/organisation_location.py\n@@ -22,9 +22,9 @@\n     \"\"\"Returns a resource tailored for generating a map of organisation locations.\n \n     Allowed parameters are:\n-    limit (default 100 / max 500),\n-    location_target (filter on organisation ID), and\n-    country (filter on country ID)\n+    __limit__ (default 100 / max 500),\n+    __location_target__ (filter on organisation ID), and\n+    __country__ (filter on country ID)\n     \"\"\"\n \n     filter_fields = ('location_target', 'country')\ndiff --git a/akvo/rest/views/project_location.py b/akvo/rest/views/project_location.py\n--- a/akvo/rest/views/project_location.py\n+++ b/akvo/rest/views/project_location.py\n@@ -22,12 +22,17 @@\n     \"\"\"Returns a resource tailored for generating a map of project locations.\n \n     Allowed parameters are:\n-    limit (default 100 / max 500),\n-    location_target (filter on project ID), and\n-    country (filter on country ID)\n+    __limit__ (default 100 / max 500),\n+    __location_target__ (filter on project ID),\n+    __location_target\\__partners__ (filter on organisation ID), and\n+    __country__ (filter on country ID)\n     \"\"\"\n \n-    filter_fields = ('location_target', 'country')\n+    filter_fields = (\n+        'location_target',\n+        'location_target__partners',\n+        'country'\n+    )\n     max_paginate_by = 500\n     paginate_by = 100\n     queryset = ProjectLocation.objects.select_related(\ndiff --git a/akvo/rest/views/project_update_location.py b/akvo/rest/views/project_update_location.py\n--- a/akvo/rest/views/project_update_location.py\n+++ b/akvo/rest/views/project_update_location.py\n@@ -23,11 +23,18 @@\n     \"\"\"Returns a resource tailored for generating a map of update locations.\n \n     Allowed parameters are:\n-    limit (default 100 / max 500), and\n-    location_target__project (filter on project ID)\n+    __limit__ (default 100 / max 500),\n+    __location_target\\__project__ (filter on project ID),\n+    __location_target\\__project\\__partners__\n+    (filter on organisation ID of the projects' organisations),\n+    __location_target\\__user\\__employers__ (filter on organisation ID of the users' organisations)\n     \"\"\"\n \n-    filter_fields = ('location_target__project', )\n+    filter_fields = (\n+        'location_target__project',\n+        'location_target__project__partners',\n+        'location_target__user__employers'\n+    )\n     max_paginate_by = 500\n     paginate_by = 100\n     queryset = ProjectUpdateLocation.objects.select_related(\n", "issue": "Add organisation filter for maps API resources\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\n\nfrom akvo.rsr.models import ProjectUpdateLocation\nfrom ..serializers import ProjectUpdateLocationSerializer, MapProjectUpdateLocationSerializer\nfrom ..viewsets import BaseRSRViewSet\n\n\nclass ProjectUpdateLocationViewSet(BaseRSRViewSet):\n    \"\"\"\n    API endpoint that allows organisation locations to be viewed or edited.\n    \"\"\"\n    queryset = ProjectUpdateLocation.objects.all()\n    serializer_class = ProjectUpdateLocationSerializer\n\n\nclass MapProjectUpdateLocationViewSet(BaseRSRViewSet):\n\n    \"\"\"Returns a resource tailored for generating a map of update locations.\n\n    Allowed parameters are:\n    limit (default 100 / max 500), and\n    location_target__project (filter on project ID)\n    \"\"\"\n\n    filter_fields = ('location_target__project', )\n    max_paginate_by = 500\n    paginate_by = 100\n    queryset = ProjectUpdateLocation.objects.select_related(\n        'location_target',\n        'location_target__project').only(\n            'id', 'latitude', 'longitude',\n            'location_target__id', 'location_target__project', 'location_target__title',\n            'location_target__photo', 'location_target__video')\n    serializer_class = MapProjectUpdateLocationSerializer\n", "path": "akvo/rest/views/project_update_location.py"}, {"content": "# -*- coding: utf-8 -*-\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 Akvo RSR module.\nFor additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rsr.models import OrganisationLocation\nfrom ..serializers import OrganisationLocationSerializer, MapOrganisationLocationSerializer\nfrom ..viewsets import BaseRSRViewSet\n\n\nclass OrganisationLocationViewSet(BaseRSRViewSet):\n    \"\"\"\n    API endpoint that allows organisation locations to be viewed or edited.\n    \"\"\"\n    queryset = OrganisationLocation.objects.all()\n    serializer_class = OrganisationLocationSerializer\n\n\nclass MapOrganisationLocationViewSet(BaseRSRViewSet):\n\n    \"\"\"Returns a resource tailored for generating a map of organisation locations.\n\n    Allowed parameters are:\n    limit (default 100 / max 500),\n    location_target (filter on organisation ID), and\n    country (filter on country ID)\n    \"\"\"\n\n    filter_fields = ('location_target', 'country')\n    max_paginate_by = 500\n    paginate_by = 100\n    queryset = OrganisationLocation.objects.select_related(\n        'location_target', 'country').only(\n            'id', 'latitude', 'longitude',\n            'location_target__id', 'location_target__name',\n            'location_target__logo',\n            'country')\n    serializer_class = MapOrganisationLocationSerializer\n", "path": "akvo/rest/views/organisation_location.py"}, {"content": "# -*- coding: utf-8 -*-\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 Akvo RSR module.\nFor additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\"\"\"\n\nfrom akvo.rsr.models import ProjectLocation\nfrom ..serializers import ProjectLocationSerializer, MapProjectLocationSerializer\nfrom ..viewsets import BaseRSRViewSet\n\n\nclass ProjectLocationViewSet(BaseRSRViewSet):\n    \"\"\"\n    \"\"\"\n    queryset = ProjectLocation.objects.all()\n    serializer_class = ProjectLocationSerializer\n    filter_fields = ('location_target', 'country', )\n\n\nclass MapProjectLocationViewSet(BaseRSRViewSet):\n\n    \"\"\"Returns a resource tailored for generating a map of project locations.\n\n    Allowed parameters are:\n    limit (default 100 / max 500),\n    location_target (filter on project ID), and\n    country (filter on country ID)\n    \"\"\"\n\n    filter_fields = ('location_target', 'country')\n    max_paginate_by = 500\n    paginate_by = 100\n    queryset = ProjectLocation.objects.select_related(\n        'location_target', 'country').only(\n            'id', 'latitude', 'longitude',\n            'location_target__id', 'location_target__title',\n            'location_target__current_image',\n            'country')\n    serializer_class = MapProjectLocationSerializer\n", "path": "akvo/rest/views/project_location.py"}]}