prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Pages endpoint: skip pages if parent is not visible
  If a parent page in the page tree is in any state that makes it invisible in the API, we do not want the children to appear in the pages endpoint. This should allow for easy deactivating of "full chapters". 
  Pages endpoint: skip pages if parent is not visible
  If a parent page in the page tree is in any state that makes it invisible in the API, we do not want the children to appear in the pages endpoint. This should allow for easy deactivating of "full chapters". 
  
  </issue>
  <code>
  [start of src/api/v3/pages.py]
  1 from django.http import JsonResponse
  2 
  3 from cms.models import Region
  4 
  5 
  6 def transform_page(page_translation):
  7     if page_translation.page.parent:
  8         parent = {
  9             "id": page_translation.page.parent.id,
  10             "url": page_translation.page.parent.get_translation(
  11                 page_translation.language.code
  12             ).permalink,
  13             "path": page_translation.page.parent.get_translation(
  14                 page_translation.language.code
  15             ).slug,
  16         }
  17     else:
  18         parent = None
  19     return {
  20         "id": page_translation.id,
  21         "url": page_translation.permalink,
  22         "path": page_translation.slug,
  23         "title": page_translation.title,
  24         "modified_gmt": page_translation.last_updated,
  25         "excerpt": page_translation.text,
  26         "content": page_translation.combined_text,
  27         "parent": parent,
  28         "order": page_translation.page.lft,  # use left edge indicator of mptt model for order
  29         "available_languages": page_translation.available_languages,
  30         "thumbnail": None,
  31         "hash": None,
  32     }
  33 
  34 
  35 # pylint: disable=unused-argument
  36 def pages(request, region_slug, language_code):
  37     region = Region.get_current_region(request)
  38     result = []
  39     for page in region.pages.all():
  40         page_translation = page.get_public_translation(language_code)
  41         if page_translation:
  42             result.append(transform_page(page_translation))
  43     return JsonResponse(
  44         result, safe=False
  45     )  # Turn off Safe-Mode to allow serializing arrays
  46
  [end of src/api/v3/pages.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/pages.py b/src/api/v3/pages.py
  --- a/src/api/v3/pages.py
  +++ b/src/api/v3/pages.py
  @@ -36,10 +36,20 @@
   def pages(request, region_slug, language_code):
       region = Region.get_current_region(request)
       result = []
  -    for page in region.pages.all():
  +    for page in region.pages.filter(archived=False, parent=None):  # get main level
           page_translation = page.get_public_translation(language_code)
           if page_translation:
               result.append(transform_page(page_translation))
  +            result = get_children(page, language_code, result)
       return JsonResponse(
           result, safe=False
       )  # Turn off Safe-Mode to allow serializing arrays
  +
  +
  +def get_children(parent, language_code, result):
  +    for page in parent.children.filter(archived=False):
  +        page_translation = page.get_public_translation(language_code)
  +        if page_translation:
  +            result.append(transform_page(page_translation))
  +            result = get_children(page, language_code, result)
  +    return result
  
verification_info: {"golden_diff": "diff --git a/src/api/v3/pages.py b/src/api/v3/pages.py\n--- a/src/api/v3/pages.py\n+++ b/src/api/v3/pages.py\n@@ -36,10 +36,20 @@\n def pages(request, region_slug, language_code):\n     region = Region.get_current_region(request)\n     result = []\n-    for page in region.pages.all():\n+    for page in region.pages.filter(archived=False, parent=None):  # get main level\n         page_translation = page.get_public_translation(language_code)\n         if page_translation:\n             result.append(transform_page(page_translation))\n+            result = get_children(page, language_code, result)\n     return JsonResponse(\n         result, safe=False\n     )  # Turn off Safe-Mode to allow serializing arrays\n+\n+\n+def get_children(parent, language_code, result):\n+    for page in parent.children.filter(archived=False):\n+        page_translation = page.get_public_translation(language_code)\n+        if page_translation:\n+            result.append(transform_page(page_translation))\n+            result = get_children(page, language_code, result)\n+    return result\n", "issue": "Pages endpoint: skip pages if parent is not visible\nIf a parent page in the page tree is in any state that makes it invisible in the API, we do not want the children to appear in the pages endpoint. This should allow for easy deactivating of \"full chapters\". \nPages endpoint: skip pages if parent is not visible\nIf a parent page in the page tree is in any state that makes it invisible in the API, we do not want the children to appear in the pages endpoint. This should allow for easy deactivating of \"full chapters\". \n", "before_files": [{"content": "from django.http import JsonResponse\n\nfrom cms.models import Region\n\n\ndef transform_page(page_translation):\n    if page_translation.page.parent:\n        parent = {\n            \"id\": page_translation.page.parent.id,\n            \"url\": page_translation.page.parent.get_translation(\n                page_translation.language.code\n            ).permalink,\n            \"path\": page_translation.page.parent.get_translation(\n                page_translation.language.code\n            ).slug,\n        }\n    else:\n        parent = None\n    return {\n        \"id\": page_translation.id,\n        \"url\": page_translation.permalink,\n        \"path\": page_translation.slug,\n        \"title\": page_translation.title,\n        \"modified_gmt\": page_translation.last_updated,\n        \"excerpt\": page_translation.text,\n        \"content\": page_translation.combined_text,\n        \"parent\": parent,\n        \"order\": page_translation.page.lft,  # use left edge indicator of mptt model for order\n        \"available_languages\": page_translation.available_languages,\n        \"thumbnail\": None,\n        \"hash\": None,\n    }\n\n\n# pylint: disable=unused-argument\ndef pages(request, region_slug, language_code):\n    region = Region.get_current_region(request)\n    result = []\n    for page in region.pages.all():\n        page_translation = page.get_public_translation(language_code)\n        if page_translation:\n            result.append(transform_page(page_translation))\n    return JsonResponse(\n        result, safe=False\n    )  # Turn off Safe-Mode to allow serializing arrays\n", "path": "src/api/v3/pages.py"}]}