Commit 10db4cc6 by Kálmán Viktor

common: add messages for humanreadablex

parent 7bb23000
......@@ -23,6 +23,7 @@ from logging import getLogger
from time import time
from warnings import warn
from django.contrib import messages
from django.contrib.auth.models import User
from django.core.cache import cache
from django.core.serializers.json import DjangoJSONEncoder
......@@ -407,10 +408,17 @@ create_readable = HumanReadableObject.create
class HumanReadableException(HumanReadableObject, Exception):
"""HumanReadableObject that is an Exception so can used in except clause.
level = "error"
def send_message(self, request):
if request.user and request.user.is_superuser:
msg = self.get_admin_text()
msg = self.get_user_text()
getattr(messages, self.level)(request, msg)
def humanize_exception(message, exception=None, **params):
def humanize_exception(message, exception=None, level=None, **params):
"""Return new dynamic-class exception which is based on
HumanReadableException and the original class with the dict of exception.
......@@ -420,6 +428,9 @@ def humanize_exception(message, exception=None, **params):
if level is not None:
exception.level = level
Ex = type("HumanReadable" + type(exception).__name__,
(HumanReadableException, type(exception)),
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment