lib: add helper method for 400 response with message
This commit is contained in:
parent
95416623b3
commit
083e317028
|
@ -2,20 +2,20 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from random import SystemRandom
|
from random import SystemRandom
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Optional, Any
|
from typing import Any, Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from jinja2.exceptions import TemplateSyntaxError, UndefinedError
|
|
||||||
from jinja2.nativetypes import NativeEnvironment
|
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse_lazy
|
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
|
from django.urls import reverse_lazy
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_prometheus.models import ExportModelOperationsMixin
|
from django_prometheus.models import ExportModelOperationsMixin
|
||||||
from guardian.mixins import GuardianUserMixin
|
from guardian.mixins import GuardianUserMixin
|
||||||
|
from jinja2.exceptions import TemplateSyntaxError, UndefinedError
|
||||||
|
from jinja2.nativetypes import NativeEnvironment
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
from structlog import get_logger
|
from structlog import get_logger
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
<h1>{% trans 'Bad Request' %}</h1>
|
<h1>{% trans 'Bad Request' %}</h1>
|
||||||
</header>
|
</header>
|
||||||
<form>
|
<form>
|
||||||
|
{% if message %}
|
||||||
|
<p>{% trans message %}</p>
|
||||||
|
{% endif %}
|
||||||
{% if 'back' in request.GET %}
|
{% if 'back' in request.GET %}
|
||||||
<a href="{% back %}" class="btn btn-primary btn-block btn-lg">{% trans 'Back' %}</a>
|
<a href="{% back %}" class="btn btn-primary btn-block btn-lg">{% trans 'Back' %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""passbook helper views"""
|
"""passbook helper views"""
|
||||||
|
from django.http import HttpRequest, HttpResponse
|
||||||
|
from django.shortcuts import render
|
||||||
from django.views.generic import CreateView
|
from django.views.generic import CreateView
|
||||||
from guardian.shortcuts import assign_perm
|
from guardian.shortcuts import assign_perm
|
||||||
|
|
||||||
|
@ -22,3 +23,8 @@ class CreateAssignPermView(CreateView):
|
||||||
)
|
)
|
||||||
assign_perm(full_permission, self.request.user, self.object)
|
assign_perm(full_permission, self.request.user, self.object)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def bad_request_message(request: HttpRequest, message: str) -> HttpResponse:
|
||||||
|
"""Return generic error page with message, with status code set to 400"""
|
||||||
|
return render(request, "error/400.html", {"message": message}, status=400)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Generated by Django 3.0.3 on 2020-02-17 20:31
|
# Generated by Django 3.0.3 on 2020-02-17 20:31
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
import passbook.providers.saml.utils.time
|
import passbook.providers.saml.utils.time
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue