prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Remove save button on disabled forms
  Even if objects are archived and the corresponding forms are disabled, the save buttons are still visible, leading to errors when submitting.
  Remove the buttons for:
  - [ ] Pages
  - [ ] Events
  - [x] POIs
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `backend/cms/views/pages/page_view.py`
  Content:
  ```
  1 """
  2 
  3 Returns:
  4     [type]: [description]
  5 """
  6 import logging
  7 
  8 from django.contrib import messages
  9 from django.contrib.auth.decorators import login_required
  10 from django.contrib.auth.mixins import PermissionRequiredMixin
  11 from django.core.exceptions import PermissionDenied
  12 from django.shortcuts import render, redirect
  13 from django.utils.decorators import method_decorator
  14 from django.utils.translation import ugettext as _
  15 from django.views.generic import TemplateView
  16 
  17 from ...constants import status
  18 from ...decorators import region_permission_required
  19 from ...forms.pages import PageForm, PageTranslationForm
  20 from ...models import Page, PageTranslation, Region, Language
  21 
  22 logger = logging.getLogger(__name__)
  23 
  24 
  25 @method_decorator(login_required, name='dispatch')
  26 @method_decorator(region_permission_required, name='dispatch')
  27 class PageView(PermissionRequiredMixin, TemplateView):
  28     permission_required = 'cms.view_pages'
  29     raise_exception = True
  30 
  31     template_name = 'pages/page_form.html'
  32     base_context = {
  33         'current_menu_item': 'pages',
  34         'PUBLIC': status.PUBLIC
  35     }
  36 
  37     def get(self, request, *args, **kwargs):
  38 
  39         region = Region.objects.get(slug=kwargs.get('region_slug'))
  40 
  41         language = Language.objects.get(code=kwargs.get('language_code'))
  42 
  43         # get page and translation objects if they exist
  44         page = Page.objects.filter(id=kwargs.get('page_id')).first()
  45         page_translation = PageTranslation.objects.filter(
  46             page=page,
  47             language=language,
  48         ).first()
  49 
  50         # Make form disabled if user has no permission to edit the page
  51         disabled = not request.user.has_perm('cms.edit_page', page)
  52         if disabled:
  53             messages.warning(request, _("You don't have the permission to edit this page."))
  54 
  55         page_form = PageForm(
  56             instance=page,
  57             region=region,
  58             language=language,
  59             disabled=disabled
  60         )
  61         page_translation_form = PageTranslationForm(
  62             instance=page_translation,
  63             disabled=disabled
  64         )
  65 
  66         return render(request, self.template_name, {
  67             **self.base_context,
  68             'page_form': page_form,
  69             'page_translation_form': page_translation_form,
  70             'page': page,
  71             'language': language,
  72             # Languages for tab view
  73             'languages': region.languages if page else [language],
  74         })
  75 
  76     # pylint: disable=too-many-branches,unused-argument
  77     def post(self, request, *args, **kwargs):
  78 
  79         region = Region.objects.get(slug=kwargs.get('region_slug'))
  80         language = Language.objects.get(code=kwargs.get('language_code'))
  81 
  82         page_instance = Page.objects.filter(id=kwargs.get('page_id')).first()
  83         page_translation_instance = PageTranslation.objects.filter(
  84             page=page_instance,
  85             language=language,
  86         ).first()
  87 
  88         if not request.user.has_perm('cms.edit_page', page_instance):
  89             raise PermissionDenied
  90 
  91         page_form = PageForm(
  92             request.POST,
  93             instance=page_instance,
  94             region=region,
  95             language=language,
  96         )
  97         page_translation_form = PageTranslationForm(
  98             request.POST,
  99             instance=page_translation_instance,
  100             region=region,
  101             language=language,
  102         )
  103 
  104         if page_translation_form.data.get('public') and 'public' in page_translation_form.changed_data:
  105             if not request.user.has_perm('cms.publish_page', page_instance):
  106                 raise PermissionDenied
  107 
  108         # TODO: error handling
  109         if not page_form.is_valid() or not page_translation_form.is_valid():
  110             messages.error(request, _('Errors have occurred.'))
  111             return render(request, self.template_name, {
  112                 **self.base_context,
  113                 'page_form': page_form,
  114                 'page_translation_form': page_translation_form,
  115                 'page': page_instance,
  116                 'language': language,
  117                 # Languages for tab view
  118                 'languages': region.languages if page_instance else [language],
  119             })
  120 
  121         if not page_form.has_changed() and not page_translation_form.has_changed():
  122             messages.info(request, _('No changes detected.'))
  123             return render(request, self.template_name, {
  124                 **self.base_context,
  125                 'page_form': page_form,
  126                 'page_translation_form': page_translation_form,
  127                 'page': page_instance,
  128                 'language': language,
  129                 # Languages for tab view
  130                 'languages': region.languages if page_instance else [language],
  131             })
  132 
  133         page = page_form.save()
  134         page_translation = page_translation_form.save(
  135             page=page,
  136             user=request.user,
  137         )
  138 
  139         published = page_translation.status == status.PUBLIC
  140         if not page_instance:
  141             if published:
  142                 messages.success(request, _('Page was successfully created and published.'))
  143             else:
  144                 messages.success(request, _('Page was successfully created.'))
  145         elif not page_translation_instance:
  146             if published:
  147                 messages.success(request, _('Translation was successfully created and published.'))
  148             else:
  149                 messages.success(request, _('Translation was successfully created.'))
  150         else:
  151             if published:
  152                 messages.success(request, _('Translation was successfully published.'))
  153             else:
  154                 messages.success(request, _('Translation was successfully saved.'))
  155 
  156         return redirect('edit_page', **{
  157             'page_id': page.id,
  158             'region_slug': region.slug,
  159             'language_code': language.code,
  160         })
  161
  ```
  --- 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/backend/cms/views/pages/page_view.py b/backend/cms/views/pages/page_view.py
  --- a/backend/cms/views/pages/page_view.py
  +++ b/backend/cms/views/pages/page_view.py
  @@ -48,9 +48,14 @@
           ).first()
   
           # Make form disabled if user has no permission to edit the page
  -        disabled = not request.user.has_perm('cms.edit_page', page)
  -        if disabled:
  +        if not request.user.has_perm('cms.edit_page', page):
  +            disabled = True
               messages.warning(request, _("You don't have the permission to edit this page."))
  +        elif page and page.archived:
  +            disabled = True
  +            messages.warning(request, _("You cannot edit this page because it is archived."))
  +        else:
  +            disabled = False
   
           page_form = PageForm(
               instance=page,
  
verification_info: {"golden_diff": "diff --git a/backend/cms/views/pages/page_view.py b/backend/cms/views/pages/page_view.py\n--- a/backend/cms/views/pages/page_view.py\n+++ b/backend/cms/views/pages/page_view.py\n@@ -48,9 +48,14 @@\n         ).first()\n \n         # Make form disabled if user has no permission to edit the page\n-        disabled = not request.user.has_perm('cms.edit_page', page)\n-        if disabled:\n+        if not request.user.has_perm('cms.edit_page', page):\n+            disabled = True\n             messages.warning(request, _(\"You don't have the permission to edit this page.\"))\n+        elif page and page.archived:\n+            disabled = True\n+            messages.warning(request, _(\"You cannot edit this page because it is archived.\"))\n+        else:\n+            disabled = False\n \n         page_form = PageForm(\n             instance=page,\n", "issue": "Remove save button on disabled forms\nEven if objects are archived and the corresponding forms are disabled, the save buttons are still visible, leading to errors when submitting.\r\nRemove the buttons for:\r\n- [ ] Pages\r\n- [ ] Events\r\n- [x] POIs\n", "before_files": [{"content": "\"\"\"\n\nReturns:\n    [type]: [description]\n\"\"\"\nimport logging\n\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required\nfrom django.contrib.auth.mixins import PermissionRequiredMixin\nfrom django.core.exceptions import PermissionDenied\nfrom django.shortcuts import render, redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import ugettext as _\nfrom django.views.generic import TemplateView\n\nfrom ...constants import status\nfrom ...decorators import region_permission_required\nfrom ...forms.pages import PageForm, PageTranslationForm\nfrom ...models import Page, PageTranslation, Region, Language\n\nlogger = logging.getLogger(__name__)\n\n\n@method_decorator(login_required, name='dispatch')\n@method_decorator(region_permission_required, name='dispatch')\nclass PageView(PermissionRequiredMixin, TemplateView):\n    permission_required = 'cms.view_pages'\n    raise_exception = True\n\n    template_name = 'pages/page_form.html'\n    base_context = {\n        'current_menu_item': 'pages',\n        'PUBLIC': status.PUBLIC\n    }\n\n    def get(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        # get page and translation objects if they exist\n        page = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation = PageTranslation.objects.filter(\n            page=page,\n            language=language,\n        ).first()\n\n        # Make form disabled if user has no permission to edit the page\n        disabled = not request.user.has_perm('cms.edit_page', page)\n        if disabled:\n            messages.warning(request, _(\"You don't have the permission to edit this page.\"))\n\n        page_form = PageForm(\n            instance=page,\n            region=region,\n            language=language,\n            disabled=disabled\n        )\n        page_translation_form = PageTranslationForm(\n            instance=page_translation,\n            disabled=disabled\n        )\n\n        return render(request, self.template_name, {\n            **self.base_context,\n            'page_form': page_form,\n            'page_translation_form': page_translation_form,\n            'page': page,\n            'language': language,\n            # Languages for tab view\n            'languages': region.languages if page else [language],\n        })\n\n    # pylint: disable=too-many-branches,unused-argument\n    def post(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        page_instance = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation_instance = PageTranslation.objects.filter(\n            page=page_instance,\n            language=language,\n        ).first()\n\n        if not request.user.has_perm('cms.edit_page', page_instance):\n            raise PermissionDenied\n\n        page_form = PageForm(\n            request.POST,\n            instance=page_instance,\n            region=region,\n            language=language,\n        )\n        page_translation_form = PageTranslationForm(\n            request.POST,\n            instance=page_translation_instance,\n            region=region,\n            language=language,\n        )\n\n        if page_translation_form.data.get('public') and 'public' in page_translation_form.changed_data:\n            if not request.user.has_perm('cms.publish_page', page_instance):\n                raise PermissionDenied\n\n        # TODO: error handling\n        if not page_form.is_valid() or not page_translation_form.is_valid():\n            messages.error(request, _('Errors have occurred.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        if not page_form.has_changed() and not page_translation_form.has_changed():\n            messages.info(request, _('No changes detected.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        page = page_form.save()\n        page_translation = page_translation_form.save(\n            page=page,\n            user=request.user,\n        )\n\n        published = page_translation.status == status.PUBLIC\n        if not page_instance:\n            if published:\n                messages.success(request, _('Page was successfully created and published.'))\n            else:\n                messages.success(request, _('Page was successfully created.'))\n        elif not page_translation_instance:\n            if published:\n                messages.success(request, _('Translation was successfully created and published.'))\n            else:\n                messages.success(request, _('Translation was successfully created.'))\n        else:\n            if published:\n                messages.success(request, _('Translation was successfully published.'))\n            else:\n                messages.success(request, _('Translation was successfully saved.'))\n\n        return redirect('edit_page', **{\n            'page_id': page.id,\n            'region_slug': region.slug,\n            'language_code': language.code,\n        })\n", "path": "backend/cms/views/pages/page_view.py"}], "after_files": [{"content": "\"\"\"\n\nReturns:\n    [type]: [description]\n\"\"\"\nimport logging\n\nfrom django.contrib import messages\nfrom django.contrib.auth.decorators import login_required\nfrom django.contrib.auth.mixins import PermissionRequiredMixin\nfrom django.core.exceptions import PermissionDenied\nfrom django.shortcuts import render, redirect\nfrom django.utils.decorators import method_decorator\nfrom django.utils.translation import ugettext as _\nfrom django.views.generic import TemplateView\n\nfrom ...constants import status\nfrom ...decorators import region_permission_required\nfrom ...forms.pages import PageForm, PageTranslationForm\nfrom ...models import Page, PageTranslation, Region, Language\n\nlogger = logging.getLogger(__name__)\n\n\n@method_decorator(login_required, name='dispatch')\n@method_decorator(region_permission_required, name='dispatch')\nclass PageView(PermissionRequiredMixin, TemplateView):\n    permission_required = 'cms.view_pages'\n    raise_exception = True\n\n    template_name = 'pages/page_form.html'\n    base_context = {\n        'current_menu_item': 'pages',\n        'PUBLIC': status.PUBLIC\n    }\n\n    def get(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        # get page and translation objects if they exist\n        page = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation = PageTranslation.objects.filter(\n            page=page,\n            language=language,\n        ).first()\n\n        # Make form disabled if user has no permission to edit the page\n        if not request.user.has_perm('cms.edit_page', page):\n            disabled = True\n            messages.warning(request, _(\"You don't have the permission to edit this page.\"))\n        elif page and page.archived:\n            disabled = True\n            messages.warning(request, _(\"You cannot edit this page because it is archived.\"))\n        else:\n            disabled = False\n\n        page_form = PageForm(\n            instance=page,\n            region=region,\n            language=language,\n            disabled=disabled\n        )\n        page_translation_form = PageTranslationForm(\n            instance=page_translation,\n            disabled=disabled\n        )\n\n        return render(request, self.template_name, {\n            **self.base_context,\n            'page_form': page_form,\n            'page_translation_form': page_translation_form,\n            'page': page,\n            'language': language,\n            # Languages for tab view\n            'languages': region.languages if page else [language],\n        })\n\n    # pylint: disable=too-many-branches,unused-argument\n    def post(self, request, *args, **kwargs):\n\n        region = Region.objects.get(slug=kwargs.get('region_slug'))\n        language = Language.objects.get(code=kwargs.get('language_code'))\n\n        page_instance = Page.objects.filter(id=kwargs.get('page_id')).first()\n        page_translation_instance = PageTranslation.objects.filter(\n            page=page_instance,\n            language=language,\n        ).first()\n\n        if not request.user.has_perm('cms.edit_page', page_instance):\n            raise PermissionDenied\n\n        page_form = PageForm(\n            request.POST,\n            instance=page_instance,\n            region=region,\n            language=language,\n        )\n        page_translation_form = PageTranslationForm(\n            request.POST,\n            instance=page_translation_instance,\n            region=region,\n            language=language,\n        )\n\n        if page_translation_form.data.get('public') and 'public' in page_translation_form.changed_data:\n            if not request.user.has_perm('cms.publish_page', page_instance):\n                raise PermissionDenied\n\n        # TODO: error handling\n        if not page_form.is_valid() or not page_translation_form.is_valid():\n            messages.error(request, _('Errors have occurred.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        if not page_form.has_changed() and not page_translation_form.has_changed():\n            messages.info(request, _('No changes detected.'))\n            return render(request, self.template_name, {\n                **self.base_context,\n                'page_form': page_form,\n                'page_translation_form': page_translation_form,\n                'page': page_instance,\n                'language': language,\n                # Languages for tab view\n                'languages': region.languages if page_instance else [language],\n            })\n\n        page = page_form.save()\n        page_translation = page_translation_form.save(\n            page=page,\n            user=request.user,\n        )\n\n        published = page_translation.status == status.PUBLIC\n        if not page_instance:\n            if published:\n                messages.success(request, _('Page was successfully created and published.'))\n            else:\n                messages.success(request, _('Page was successfully created.'))\n        elif not page_translation_instance:\n            if published:\n                messages.success(request, _('Translation was successfully created and published.'))\n            else:\n                messages.success(request, _('Translation was successfully created.'))\n        else:\n            if published:\n                messages.success(request, _('Translation was successfully published.'))\n            else:\n                messages.success(request, _('Translation was successfully saved.'))\n\n        return redirect('edit_page', **{\n            'page_id': page.id,\n            'region_slug': region.slug,\n            'language_code': language.code,\n        })\n", "path": "backend/cms/views/pages/page_view.py"}]}