prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  After creating a new organization it should appear in the pending approval menu
  Please make sure if a user adds an organization the Pending Approval menu is updated
  
  http://staging.changelog.qgis.org/en/qgis/pending-certifyingorganisation/list/
  
  --- 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, Version
  7 from changes.models import Category, SponsorshipLevel, SponsorshipPeriod, Entry
  8 
  9 
  10 class NavContextMiddleware(object):
  11     """
  12     Adds the required navigation variables to each response
  13     """
  14 
  15     def __init__(self):
  16         pass
  17 
  18     @staticmethod
  19     def process_template_response(request, response):
  20         """
  21         Add 'the_project', 'the_entry', 'the_version' to context for the
  22             navigation.
  23 
  24         Justification: To make the navigation functional, we need to know
  25             which Project (or Version, Committee etc) the current context
  26             relates to. This is required for URLs. Rather than include lots of
  27             if/else in the navigation template, it seems cleaner to add the
  28             above variables to the context here.
  29 
  30         :param request: Http Request obj
  31         :param response: Http Response obj
  32         :return: context :rtype: dict
  33         """
  34         context = response.context_data
  35 
  36         if context.get('project', None):
  37             context['the_project'] = context.get('project')
  38             versions = Version.objects.filter(project=context.get('project'))
  39             context['has_pending_versions'] = (
  40                 Version.unapproved_objects.filter(
  41                     project=context.get('project')).exists())
  42             context['has_pending_categories'] = (
  43                 Category.unapproved_objects.filter(
  44                     project=context.get('project')).exists())
  45             context['has_pending_sponsor_lvl'] = (
  46                 SponsorshipLevel.unapproved_objects.filter(
  47                     project=context.get('project')).exists())
  48             context['has_pending_sponsor_period'] = (
  49                 SponsorshipPeriod.unapproved_objects.filter(
  50                     project=context.get('project')).exists())
  51             if versions:
  52                 context['has_pending_entries'] = (
  53                     Entry.unapproved_objects.filter(
  54                         version__in=versions).exists())
  55 
  56         else:
  57             if request.user.is_staff:
  58                 context['the_projects'] = Project.objects.all()
  59             else:
  60                 context['the_projects'] = Project.approved_objects.filter(
  61                     private=False
  62                 )
  63 
  64         if context.get('version', None):
  65             context['the_version'] = context.get('version')
  66             context['the_project'] = context.get('version').project
  67 
  68         if context.get('committee', None):
  69             context['the_committee'] = context.get('committee')
  70             context['the_project'] = context.get('committee').project
  71 
  72         if context.get('ballot', None):
  73             context['the_committee'] = context.get('ballot').committee
  74             context['the_project'] = context.get('ballot').committee.project
  75 
  76         if context.get('category', None):
  77             context['the_project'] = context.get('category').project
  78 
  79         if context.get('ballots', None):
  80             try:
  81                 context['the_project'] = \
  82                     context.get('ballots')[0].committee.project
  83             except (KeyError, IndexError):
  84                 pass
  85 
  86         if context.get('entry', None):
  87             context['the_entry'] = context.get('entry')
  88             context['the_version'] = context.get('entry').version
  89             context['the_project'] = context.get('entry').version.project
  90 
  91         if context.get('committees', None):
  92             try:
  93                 context['the_project'] = context.get('committees')[0].project
  94             except (KeyError, IndexError):
  95                 pass
  96 
  97         if context.get('versions', None):
  98             try:
  99                 context['the_project'] = context.get('versions')[0].project
  100             except (KeyError, IndexError):
  101                 pass
  102 
  103         if context.get('entries', None):
  104             try:
  105                 context['the_version'] = context.get('entries')[0].version
  106                 context['the_project'] = \
  107                     context.get('entries')[0].version.project
  108             except (KeyError, IndexError):
  109                 pass
  110 
  111         if context.get('categories', None):
  112             try:
  113                 context['the_project'] = \
  114                     context.get('categories')[0].project
  115             except (KeyError, IndexError):
  116                 pass
  117 
  118         return response
  119
  ```
  --- 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()
  
  ```
  
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
  @@ -5,6 +5,7 @@
   """
   from base.models import Project, Version
   from changes.models import Category, SponsorshipLevel, SponsorshipPeriod, Entry
  +from certification.models import CertifyingOrganisation
   
   
   class NavContextMiddleware(object):
  @@ -48,6 +49,9 @@
               context['has_pending_sponsor_period'] = (
                   SponsorshipPeriod.unapproved_objects.filter(
                       project=context.get('project')).exists())
  +            context['has_pending_organisations'] = (
  +                CertifyingOrganisation.unapproved_objects.filter(
  +                    project=context.get('project')).exists())
               if versions:
                   context['has_pending_entries'] = (
                       Entry.unapproved_objects.filter(
  
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@@ -5,6 +5,7 @@\n \"\"\"\n from base.models import Project, Version\n from changes.models import Category, SponsorshipLevel, SponsorshipPeriod, Entry\n+from certification.models import CertifyingOrganisation\n \n \n class NavContextMiddleware(object):\n@@ -48,6 +49,9 @@\n             context['has_pending_sponsor_period'] = (\n                 SponsorshipPeriod.unapproved_objects.filter(\n                     project=context.get('project')).exists())\n+            context['has_pending_organisations'] = (\n+                CertifyingOrganisation.unapproved_objects.filter(\n+                    project=context.get('project')).exists())\n             if versions:\n                 context['has_pending_entries'] = (\n                     Entry.unapproved_objects.filter(\n", "issue": "After creating a new organization it should appear in the pending approval menu\nPlease make sure if a user adds an organization the Pending Approval menu is updated\r\n\r\nhttp://staging.changelog.qgis.org/en/qgis/pending-certifyingorganisation/list/\n", "before_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, Entry\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            versions = Version.objects.filter(project=context.get('project'))\n            context['has_pending_versions'] = (\n                Version.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            context['has_pending_categories'] = (\n                Category.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            context['has_pending_sponsor_lvl'] = (\n                SponsorshipLevel.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            context['has_pending_sponsor_period'] = (\n                SponsorshipPeriod.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            if versions:\n                context['has_pending_entries'] = (\n                    Entry.unapproved_objects.filter(\n                        version__in=versions).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"}], "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, Entry\nfrom certification.models import CertifyingOrganisation\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            versions = Version.objects.filter(project=context.get('project'))\n            context['has_pending_versions'] = (\n                Version.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            context['has_pending_categories'] = (\n                Category.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            context['has_pending_sponsor_lvl'] = (\n                SponsorshipLevel.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            context['has_pending_sponsor_period'] = (\n                SponsorshipPeriod.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            context['has_pending_organisations'] = (\n                CertifyingOrganisation.unapproved_objects.filter(\n                    project=context.get('project')).exists())\n            if versions:\n                context['has_pending_entries'] = (\n                    Entry.unapproved_objects.filter(\n                        version__in=versions).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"}]}