Projet

Général

Profil

0001-middleware-use-a-template-for-maintenance-page-65126.patch

Emmanuel Cazenave, 11 mai 2022 18:51

Télécharger (1,89 ko)

Voir les différences:

Subject: [PATCH] middleware: use a template for maintenance page (#65126)

 .../templates/hobo/maintenance/maintenance_page.html       | 5 +++++
 hobo/middleware/maintenance.py                             | 7 +++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 hobo/maintenance/templates/hobo/maintenance/maintenance_page.html
hobo/maintenance/templates/hobo/maintenance/maintenance_page.html
1
<html>
2
  <body>
3
    <h1>{{ maintenance_msg }}</h1>
4
  </body>
5
</html>
hobo/middleware/maintenance.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.conf import settings
18
from django.http import HttpResponse
18
from django.template.response import TemplateResponse
19 19
from django.utils.translation import ugettext as _
20 20

  
21 21

  
......
39 39
        maintenance_mode = getattr(settings, 'MAINTENANCE_PAGE', None)
40 40
        if maintenance_mode and not pass_through(request):
41 41
            maintenance_msg = _('The site is under maintenance')
42
            return HttpResponse('<h1>%s</h1>' % maintenance_msg, status=503)
42
            context = {'maintenance_msg': maintenance_msg}
43
            return TemplateResponse(
44
                request, 'hobo/maintenance/maintenance_page.html', context=context, status=503
45
            ).render()
43 46
        return self.get_response(request)
44
-