We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `django_project/core/custom_middleware.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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()

{"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"}], "after_files": [{"content": "# coding=utf-8\n# flake8: noqa\n\"\"\"\ncore.custom_middleware\n\"\"\"\nfrom base.models import Project, Version\nfrom changes.models import Category, SponsorshipLevel, SponsorshipPeriod\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            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            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"}]}