prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  In the pending approval menu, only show menu items that have pending approvals
  The **Pending approval** menu should be filtered to show only items in the active project where there are pending approvals.
  
  
  </issue>
  <code>
  [start of django_project/core/custom_middleware.py]
  1 # coding=utf-8
  2 # flake8: noqa
  3 """
  4 core.custom_middleware
  5 """
  6 from base.models import Project
  7 
  8 
  9 class NavContextMiddleware(object):
  10     """
  11     Adds the required navigation variables to each response
  12     """
  13 
  14     def __init__(self):
  15         pass
  16 
  17     @staticmethod
  18     def process_template_response(request, response):
  19         """
  20         Add 'the_project', 'the_entry', 'the_version' to context for the
  21             navigation.
  22 
  23         Justification: To make the navigation functional, we need to know
  24             which Project (or Version, Committee etc) the current context
  25             relates to. This is required for URLs. Rather than include lots of
  26             if/else in the navigation template, it seems cleaner to add the
  27             above variables to the context here.
  28 
  29         :param request: Http Request obj
  30         :param response: Http Response obj
  31         :return: context :rtype: dict
  32         """
  33         context = response.context_data
  34 
  35         if context.get('project', None):
  36             context['the_project'] = context.get('project')
  37         else:
  38             if request.user.is_staff:
  39                 context['the_projects'] = Project.objects.all()
  40             else:
  41                 context['the_projects'] = Project.approved_objects.filter(
  42                     private=False
  43                 )
  44 
  45         if context.get('version', None):
  46             context['the_version'] = context.get('version')
  47             context['the_project'] = context.get('version').project
  48 
  49         if context.get('committee', None):
  50             context['the_committee'] = context.get('committee')
  51             context['the_project'] = context.get('committee').project
  52 
  53         if context.get('ballot', None):
  54             context['the_committee'] = context.get('ballot').committee
  55             context['the_project'] = context.get('ballot').committee.project
  56 
  57         if context.get('category', None):
  58             context['the_project'] = context.get('category').project
  59 
  60         if context.get('ballots', None):
  61             try:
  62                 context['the_project'] = \
  63                     context.get('ballots')[0].committee.project
  64             except (KeyError, IndexError):
  65                 pass
  66 
  67         if context.get('entry', None):
  68             context['the_entry'] = context.get('entry')
  69             context['the_version'] = context.get('entry').version
  70             context['the_project'] = context.get('entry').version.project
  71 
  72         if context.get('committees', None):
  73             try:
  74                 context['the_project'] = context.get('committees')[0].project
  75             except (KeyError, IndexError):
  76                 pass
  77 
  78         if context.get('versions', None):
  79             try:
  80                 context['the_project'] = context.get('versions')[0].project
  81             except (KeyError, IndexError):
  82                 pass
  83 
  84         if context.get('entries', None):
  85             try:
  86                 context['the_version'] = context.get('entries')[0].version
  87                 context['the_project'] = \
  88                     context.get('entries')[0].version.project
  89             except (KeyError, IndexError):
  90                 pass
  91 
  92         if context.get('categories', None):
  93             try:
  94                 context['the_project'] = \
  95                     context.get('categories')[0].project
  96             except (KeyError, IndexError):
  97                 pass
  98 
  99         return response
  100
  [end of django_project/core/custom_middleware.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/django_project/core/custom_middleware.py b/django_project/core/custom_middleware.py
  --- a/django_project/core/custom_middleware.py
  +++ b/django_project/core/custom_middleware.py
  @@ -3,7 +3,8 @@
   """
   core.custom_middleware
   """
  -from base.models import Project
  +from base.models import Project, Version
  +from changes.models import Category, SponsorshipLevel, SponsorshipPeriod
   
   
   class NavContextMiddleware(object):
  @@ -34,6 +35,15 @@
   
           if context.get('project', None):
               context['the_project'] = context.get('project')
  +            context['has_pending_versions'] = Version.unapproved_objects.filter(
  +                project=context.get('project')).exists()
  +            context['has_pending_categories'] = Category.unapproved_objects.filter(
  +                project=context.get('project')).exists()
  +            context['has_pending_sponsor_lvl'] = SponsorshipLevel.unapproved_objects.filter(
  +                project=context.get('project')).exists()
  +            context['has_pending_sponsor_period'] = SponsorshipPeriod.unapproved_objects.filter(
  +                project=context.get('project')).exists()
  +
           else:
               if request.user.is_staff:
                   context['the_projects'] = Project.objects.all()
  
verification_info: {"golden_diff": "diff --git a/django_project/core/custom_middleware.py b/django_project/core/custom_middleware.py\n--- a/django_project/core/custom_middleware.py\n+++ b/django_project/core/custom_middleware.py\n@@ -3,7 +3,8 @@\n \"\"\"\n core.custom_middleware\n \"\"\"\n-from base.models import Project\n+from base.models import Project, Version\n+from changes.models import Category, SponsorshipLevel, SponsorshipPeriod\n \n \n class NavContextMiddleware(object):\n@@ -34,6 +35,15 @@\n \n         if context.get('project', None):\n             context['the_project'] = context.get('project')\n+            context['has_pending_versions'] = Version.unapproved_objects.filter(\n+                project=context.get('project')).exists()\n+            context['has_pending_categories'] = Category.unapproved_objects.filter(\n+                project=context.get('project')).exists()\n+            context['has_pending_sponsor_lvl'] = SponsorshipLevel.unapproved_objects.filter(\n+                project=context.get('project')).exists()\n+            context['has_pending_sponsor_period'] = SponsorshipPeriod.unapproved_objects.filter(\n+                project=context.get('project')).exists()\n+\n         else:\n             if request.user.is_staff:\n                 context['the_projects'] = Project.objects.all()\n", "issue": "In the pending approval menu, only show menu items that have pending approvals\nThe **Pending approval** menu should be filtered to show only items in the active project where there are pending approvals.\n\n", "before_files": [{"content": "# coding=utf-8\n# flake8: noqa\n\"\"\"\ncore.custom_middleware\n\"\"\"\nfrom base.models import Project\n\n\nclass NavContextMiddleware(object):\n    \"\"\"\n    Adds the required navigation variables to each response\n    \"\"\"\n\n    def __init__(self):\n        pass\n\n    @staticmethod\n    def process_template_response(request, response):\n        \"\"\"\n        Add 'the_project', 'the_entry', 'the_version' to context for the\n            navigation.\n\n        Justification: To make the navigation functional, we need to know\n            which Project (or Version, Committee etc) the current context\n            relates to. This is required for URLs. Rather than include lots of\n            if/else in the navigation template, it seems cleaner to add the\n            above variables to the context here.\n\n        :param request: Http Request obj\n        :param response: Http Response obj\n        :return: context :rtype: dict\n        \"\"\"\n        context = response.context_data\n\n        if context.get('project', None):\n            context['the_project'] = context.get('project')\n        else:\n            if request.user.is_staff:\n                context['the_projects'] = Project.objects.all()\n            else:\n                context['the_projects'] = Project.approved_objects.filter(\n                    private=False\n                )\n\n        if context.get('version', None):\n            context['the_version'] = context.get('version')\n            context['the_project'] = context.get('version').project\n\n        if context.get('committee', None):\n            context['the_committee'] = context.get('committee')\n            context['the_project'] = context.get('committee').project\n\n        if context.get('ballot', None):\n            context['the_committee'] = context.get('ballot').committee\n            context['the_project'] = context.get('ballot').committee.project\n\n        if context.get('category', None):\n            context['the_project'] = context.get('category').project\n\n        if context.get('ballots', None):\n            try:\n                context['the_project'] = \\\n                    context.get('ballots')[0].committee.project\n            except (KeyError, IndexError):\n                pass\n\n        if context.get('entry', None):\n            context['the_entry'] = context.get('entry')\n            context['the_version'] = context.get('entry').version\n            context['the_project'] = context.get('entry').version.project\n\n        if context.get('committees', None):\n            try:\n                context['the_project'] = context.get('committees')[0].project\n            except (KeyError, IndexError):\n                pass\n\n        if context.get('versions', None):\n            try:\n                context['the_project'] = context.get('versions')[0].project\n            except (KeyError, IndexError):\n                pass\n\n        if context.get('entries', None):\n            try:\n                context['the_version'] = context.get('entries')[0].version\n                context['the_project'] = \\\n                    context.get('entries')[0].version.project\n            except (KeyError, IndexError):\n                pass\n\n        if context.get('categories', None):\n            try:\n                context['the_project'] = \\\n                    context.get('categories')[0].project\n            except (KeyError, IndexError):\n                pass\n\n        return response\n", "path": "django_project/core/custom_middleware.py"}]}