prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Old permalinks not mapped in single page API endpoint
  ### Describe the Bug
  <!-- A clear and concise description of what the bug is. -->
  The permalink is checked for correctness in the single page API endpoint, but in #119 we decided not to keep track of old permalinks. Instead, we will just map permalinks based on the last url parameter (the slug) and ignore the rest.
  
  ### Steps to Reproduce
  
  1. Copy one page permalink
  2. Move that page to another parent to change the permalink
  3. Request this page in the single page API endpoint with the old permalink from step 1
  
  ### Expected Behavior
  <!-- A clear and concise description of what you expected to happen. -->
  The page should be found even if the permalink is old
  
  ### Actual Behavior
  <!-- A clear and concise description of what actually happened. -->
  The error `No Page matches the given url or id` is returned.
  
  
  
  
  </issue>
  <code>
  [start of src/api/v3/single_page.py]
  1 """
  2 View to return a JSON representation of a single page. The page can
  3 be selected via the id or the permalink.
  4 """
  5 from django.http import JsonResponse, Http404
  6 from django.shortcuts import get_object_or_404
  7 
  8 from cms.models import Region, Page
  9 from .pages import transform_page
  10 
  11 
  12 # pylint: disable=unused-argument
  13 def single_page(request, region_slug, language_code):
  14     """
  15     View function returning the desired page as a JSON or a 404 if the
  16     requested page does not exist.
  17 
  18     :param request: The request that has been sent to the Django server
  19     :type request: ~django.http.HttpRequest
  20 
  21     :param region_slug: Slug defining the region
  22     :type region_slug: str
  23 
  24     :param language_code: Code to identify the desired language
  25     :type language_code: str
  26 
  27     :raises ~django.http.Http404: HTTP status 404 if the request is malformed or no page with the given id or url exists.
  28 
  29     :return: Return a JSON with the requested page and a HTTP status 200.
  30     :rtype: ~django.http.JsonResponse
  31     """
  32     region = Region.get_current_region(request)
  33 
  34     if request.GET.get("id"):
  35         page = get_object_or_404(region.pages, id=request.GET.get("id"))
  36         page_translation = page.get_public_translation(language_code)
  37         if page_translation:
  38             return JsonResponse(transform_page(page_translation), safe=False)
  39 
  40     elif request.GET.get("url"):
  41         # Strip leading and trailing slashes to avoid ambiguous urls
  42         url = request.GET.get("url").strip("/")
  43         # Get potential page candidate by only filtering for the translation slug
  44         page = get_object_or_404(
  45             Page, region=region, translations__slug=url.split("/")[-1]
  46         )
  47         # Get most recent public revision of the page
  48         page_translation = page.get_public_translation(language_code)
  49         # Check if the whole path is correct, not only the slug
  50         # TODO: Once we have a permalink mapping of old versions, we also have to check whether the permalink was valid in the past
  51         if page_translation.permalink == url:
  52             return JsonResponse(transform_page(page_translation), safe=False)
  53 
  54     raise Http404("No Page matches the given url or id.")
  55
  [end of src/api/v3/single_page.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/src/api/v3/single_page.py b/src/api/v3/single_page.py
  --- a/src/api/v3/single_page.py
  +++ b/src/api/v3/single_page.py
  @@ -5,7 +5,7 @@
   from django.http import JsonResponse, Http404
   from django.shortcuts import get_object_or_404
   
  -from cms.models import Region, Page
  +from cms.models import Region
   from .pages import transform_page
   
   
  @@ -40,15 +40,17 @@
       elif request.GET.get("url"):
           # Strip leading and trailing slashes to avoid ambiguous urls
           url = request.GET.get("url").strip("/")
  -        # Get potential page candidate by only filtering for the translation slug
  +        # The last path component of the url is the page translation slug
  +        page_translation_slug = url.split("/")[-1]
  +        # Get page by filtering for translation slug and translation language code
           page = get_object_or_404(
  -            Page, region=region, translations__slug=url.split("/")[-1]
  +            region.pages,
  +            translations__slug=page_translation_slug,
  +            translations__language__code=language_code,
           )
           # Get most recent public revision of the page
           page_translation = page.get_public_translation(language_code)
  -        # Check if the whole path is correct, not only the slug
  -        # TODO: Once we have a permalink mapping of old versions, we also have to check whether the permalink was valid in the past
  -        if page_translation.permalink == url:
  +        if page_translation:
               return JsonResponse(transform_page(page_translation), safe=False)
   
       raise Http404("No Page matches the given url or id.")
  
verification_info: {"golden_diff": "diff --git a/src/api/v3/single_page.py b/src/api/v3/single_page.py\n--- a/src/api/v3/single_page.py\n+++ b/src/api/v3/single_page.py\n@@ -5,7 +5,7 @@\n from django.http import JsonResponse, Http404\n from django.shortcuts import get_object_or_404\n \n-from cms.models import Region, Page\n+from cms.models import Region\n from .pages import transform_page\n \n \n@@ -40,15 +40,17 @@\n     elif request.GET.get(\"url\"):\n         # Strip leading and trailing slashes to avoid ambiguous urls\n         url = request.GET.get(\"url\").strip(\"/\")\n-        # Get potential page candidate by only filtering for the translation slug\n+        # The last path component of the url is the page translation slug\n+        page_translation_slug = url.split(\"/\")[-1]\n+        # Get page by filtering for translation slug and translation language code\n         page = get_object_or_404(\n-            Page, region=region, translations__slug=url.split(\"/\")[-1]\n+            region.pages,\n+            translations__slug=page_translation_slug,\n+            translations__language__code=language_code,\n         )\n         # Get most recent public revision of the page\n         page_translation = page.get_public_translation(language_code)\n-        # Check if the whole path is correct, not only the slug\n-        # TODO: Once we have a permalink mapping of old versions, we also have to check whether the permalink was valid in the past\n-        if page_translation.permalink == url:\n+        if page_translation:\n             return JsonResponse(transform_page(page_translation), safe=False)\n \n     raise Http404(\"No Page matches the given url or id.\")\n", "issue": "Old permalinks not mapped in single page API endpoint\n### Describe the Bug\r\n<!-- A clear and concise description of what the bug is. -->\r\nThe permalink is checked for correctness in the single page API endpoint, but in #119 we decided not to keep track of old permalinks. Instead, we will just map permalinks based on the last url parameter (the slug) and ignore the rest.\r\n\r\n### Steps to Reproduce\r\n\r\n1. Copy one page permalink\r\n2. Move that page to another parent to change the permalink\r\n3. Request this page in the single page API endpoint with the old permalink from step 1\r\n\r\n### Expected Behavior\r\n<!-- A clear and concise description of what you expected to happen. -->\r\nThe page should be found even if the permalink is old\r\n\r\n### Actual Behavior\r\n<!-- A clear and concise description of what actually happened. -->\r\nThe error `No Page matches the given url or id` is returned.\r\n\r\n\r\n\n", "before_files": [{"content": "\"\"\"\nView to return a JSON representation of a single page. The page can\nbe selected via the id or the permalink.\n\"\"\"\nfrom django.http import JsonResponse, Http404\nfrom django.shortcuts import get_object_or_404\n\nfrom cms.models import Region, Page\nfrom .pages import transform_page\n\n\n# pylint: disable=unused-argument\ndef single_page(request, region_slug, language_code):\n    \"\"\"\n    View function returning the desired page as a JSON or a 404 if the\n    requested page does not exist.\n\n    :param request: The request that has been sent to the Django server\n    :type request: ~django.http.HttpRequest\n\n    :param region_slug: Slug defining the region\n    :type region_slug: str\n\n    :param language_code: Code to identify the desired language\n    :type language_code: str\n\n    :raises ~django.http.Http404: HTTP status 404 if the request is malformed or no page with the given id or url exists.\n\n    :return: Return a JSON with the requested page and a HTTP status 200.\n    :rtype: ~django.http.JsonResponse\n    \"\"\"\n    region = Region.get_current_region(request)\n\n    if request.GET.get(\"id\"):\n        page = get_object_or_404(region.pages, id=request.GET.get(\"id\"))\n        page_translation = page.get_public_translation(language_code)\n        if page_translation:\n            return JsonResponse(transform_page(page_translation), safe=False)\n\n    elif request.GET.get(\"url\"):\n        # Strip leading and trailing slashes to avoid ambiguous urls\n        url = request.GET.get(\"url\").strip(\"/\")\n        # Get potential page candidate by only filtering for the translation slug\n        page = get_object_or_404(\n            Page, region=region, translations__slug=url.split(\"/\")[-1]\n        )\n        # Get most recent public revision of the page\n        page_translation = page.get_public_translation(language_code)\n        # Check if the whole path is correct, not only the slug\n        # TODO: Once we have a permalink mapping of old versions, we also have to check whether the permalink was valid in the past\n        if page_translation.permalink == url:\n            return JsonResponse(transform_page(page_translation), safe=False)\n\n    raise Http404(\"No Page matches the given url or id.\")\n", "path": "src/api/v3/single_page.py"}]}