Error handling
This commit is contained in:
parent
344d48a6f8
commit
df681072e2
5 changed files with 43 additions and 6 deletions
|
@ -7,5 +7,12 @@ register = template.Library()
|
|||
|
||||
@register.inclusion_tag('manager/notifications.html', takes_context=True)
|
||||
def getNotifications(context, login=False):
|
||||
return { 'notifications': [notification for notification in Notification.objects.filter(Q(expiry__gte = timezone.now()) | Q(expiry = None)) if (notification.on_login or (not login)) ] }
|
||||
|
||||
notifications = [notification for notification in Notification.objects.filter(Q(expiry__gte = timezone.now()) | Q(expiry = None)) if (notification.on_login or (not login)) ]
|
||||
if context.dicts[3]["exception"]:
|
||||
exception = Notification()
|
||||
exception.status = 2
|
||||
exception.text = context.dicts[3]["exception"].human
|
||||
if context.dicts[3]["user"].is_superuser:
|
||||
exception.text += "<br><br><code>" + str(context.dicts[3]["exception"]) + "</code>"
|
||||
notifications = [ exception ] + notifications
|
||||
return { 'notifications': notifications }
|
||||
|
|
|
@ -135,8 +135,8 @@ def ping(request, device_id):
|
|||
return HttpResponse(ajax, content_type="application/json")
|
||||
|
||||
@login_required
|
||||
def devices(request):
|
||||
return render(request, "manager/index.html", {"title": "Device Administration"})
|
||||
def devices(request, code=200, exception=None):
|
||||
return render(request, "manager/index.html", {"title": "Device Administration", "exception": exception}, status=code)
|
||||
|
||||
@login_required
|
||||
def editdevice(request, device_id):
|
||||
|
@ -479,3 +479,26 @@ def saveUserStatus(sender, instance, **kwargs):
|
|||
except:
|
||||
UserStatus.objects.create(user=instance)
|
||||
|
||||
def errorhandler(request, code, exception):
|
||||
if code == 403:
|
||||
exception.human = "You have no permission to access the requested page."
|
||||
elif code == 400:
|
||||
exception.human = "Something seems to be wrong with the request you sent. Please try again."
|
||||
elif code == 404:
|
||||
exception.human = "Sorry, we were unable to find the page you requested. Please check the address and try again."
|
||||
elif code == 500:
|
||||
exception.human = "Sorry, something seems to be wrong on our end. Please try again later or contact support if the problem persists."
|
||||
|
||||
return devices(request, code=code, exception=exception)
|
||||
|
||||
def handler400(request, exception):
|
||||
return errorhandler(request, 400, exception)
|
||||
|
||||
def handler403(request, exception):
|
||||
return errorhandler(request, 403, exception)
|
||||
|
||||
def handler404(request, exception):
|
||||
return errorhandler(request, 404, exception)
|
||||
|
||||
def handler500(request):
|
||||
return errorhandler(request, 500, Exception("Please check the server logs for additional information."))
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
‐ <a id="linkorgas" href="#" onclick="showorgas();">Organizations</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<p></p>
|
||||
{% autoescape off %}
|
||||
{% getNotifications %}
|
||||
{% endautoescape %}
|
||||
|
||||
<div name="devicespart" id="devicespart">
|
||||
<h2>Devices</h2>
|
||||
|
|
|
@ -7,7 +7,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||
SECRET_KEY = '=go8&h#^kh6ksr11e2z-@4qqd6t%63$x#-!s#l_yhw@oyanrys'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = False
|
||||
|
||||
ALLOWED_HOSTS = ["admin360.kumi.host", "test360.kumi.host"]
|
||||
|
||||
|
|
|
@ -19,3 +19,8 @@ urlpatterns = [
|
|||
path('admin/', admin.site.urls),
|
||||
path('accounts/', include('django.contrib.auth.urls'))
|
||||
]
|
||||
|
||||
handler400 = "manager.views.handler400"
|
||||
handler403 = "manager.views.handler403"
|
||||
handler404 = "manager.views.handler404"
|
||||
handler500 = "manager.views.handler500"
|
||||
|
|
Loading…
Reference in a new issue