diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2017-12-29 13:31:30 +0100 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2017-12-29 13:31:30 +0100 |
commit | af81a32e5d304187f50a070a4bc65f87ee90750e (patch) | |
tree | 1822547afc2506df6349ed379d3eac9b22537429 /talerbank/app/middleware.py | |
parent | e3c242043b199ddade6ae540bcc8284c0e377d5e (diff) | |
download | bank-af81a32e5d304187f50a070a4bc65f87ee90750e.tar.gz bank-af81a32e5d304187f50a070a4bc65f87ee90750e.tar.bz2 bank-af81a32e5d304187f50a070a4bc65f87ee90750e.zip |
linting everything but (almost) unavoidable things
Diffstat (limited to 'talerbank/app/middleware.py')
-rw-r--r-- | talerbank/app/middleware.py | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/talerbank/app/middleware.py b/talerbank/app/middleware.py index ab4269a..88e3b1b 100644 --- a/talerbank/app/middleware.py +++ b/talerbank/app/middleware.py @@ -1,5 +1,6 @@ import logging from django.http import JsonResponse +from django.shortcuts import redirect from .models import BankAccount, BankTransaction from .views import \ (DebitLimitException, SameAccountException, @@ -11,52 +12,54 @@ from .amount import CurrencyMismatch, BadFormatAmount LOGGER = logging.getLogger() -EXCS = { - BankAccount.DoesNotExist: 0, - BankTransaction.DoesNotExist: 1, - SameAccountException: 2, - DebitLimitException: 3, - URLParameterMissing: 8, - URLParameterMalformed: 9, - JSONFieldException: 6, - CurrencyMismatch: 11, - BadFormatAmount: 11, - LoginFailed: 12, - RejectNoRightsException: 13, - UnknownCurrencyException: 14} - -APIS = { - "/reject": 5300, - "/history": 5200, - "/admin/add/incoming": 5100} - -RENDER = { - "/profile": "profile", - "/register": "index", - "/public-accounts": "index", - "/pin/verify": "profile"} - class ExceptionMiddleware: def __init__(self, get_response): self.get_response = get_response + self.excs = { + BankAccount.DoesNotExist: 0, + BankTransaction.DoesNotExist: 1, + SameAccountException: 2, + DebitLimitException: 3, + URLParameterMissing: 8, + URLParameterMalformed: 9, + JSONFieldException: 6, + CurrencyMismatch: 11, + BadFormatAmount: 11, + LoginFailed: 12, + RejectNoRightsException: 13, + UnknownCurrencyException: 14} + + self.apis = { + "/reject": 5300, + "/history": 5200, + "/admin/add/incoming": 5100} + + self.render = { + "/profile": "profile", + "/register": "index", + "/public-accounts": "index", + "/pin/verify": "profile"} + + def __call__(self, request): return self.get_response(request) def process_exception(self, request, exception): - if not EXCS.get(exception.__class__): + if not self.excs.get(exception.__class__): return None - taler_ec = EXCS.get(exception.__class__) + taler_ec = self.excs.get(exception.__class__) # The way error codes compose matches definitions found # at [1]. - taler_ec += APIS.get(request.path, 1000) - render_to = RENDER.get(request.path) + taler_ec += self.apis.get(request.path, 1000) + render_to = self.render.get(request.path) if not render_to: return JsonResponse({"ec": taler_ec, "error": exception.hint}, status=exception.http_status_code) - request.session["profile_hint"] = True, False, hint + request.session["profile_hint"] = \ + True, False, exception.hint return redirect(render_to) -# [1] https://git.taler.net/exchange.git/tree/src/include/taler_error_codes.h#n1502 +# [1] https://git.taler.net/exchange.git/tree/src/include/taler_error_codes.h#n1502 |