gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: No custom DoesNotExist


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: No custom DoesNotExist classes anymore.
Date: Fri, 12 Apr 2019 15:43:21 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new 088708f  No custom DoesNotExist classes anymore.
088708f is described below

commit 088708f1418f7e1f4fba20654c31dbec3d4d072d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Apr 12 15:42:37 2019 +0200

    No custom DoesNotExist classes anymore.
    
    They yield different results on different systems..
---
 talerbank/app/middleware.py | 19 +++++++++++++++++--
 talerbank/app/models.py     | 20 --------------------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/talerbank/app/middleware.py b/talerbank/app/middleware.py
index f6f8c1e..371d9b6 100644
--- a/talerbank/app/middleware.py
+++ b/talerbank/app/middleware.py
@@ -106,10 +106,25 @@ class ExceptionMiddleware:
         # Check if the endpoint should cause a human-readable
         # page to be returned.
         render_to = self.render.get(request.path)
+
+        try:
+            hint = exception.hint
+            http_status_code = exception.http_status_code
+        ##
+        # This exception happens when the middleware is catching
+        # DoesNotExist exceptions; the ideal fix is to get BankAccount
+        # and BankTransaction classes to override their 'DoesNotExist'
+        # field wiht some custom class, but that wasn't straightforward
+        # (in the sense that on different systems we had different
+        # results, so we fallback on this more sound / manual approach)
+        except AttributeError:
+            hint = "The database (BankAccount / BankTransaction) object wasn't 
found."
+            http_status_code = 404
+
         if not render_to:
             return JsonResponse({"ec": taler_ec,
-                                 "error": exception.hint},
-                                status=exception.http_status_code)
+                                 "error": hint},
+                                status=http_status_code)
         request.session["profile_hint"] = \
             True, False, exception.hint
         return redirect(render_to)
diff --git a/talerbank/app/models.py b/talerbank/app/models.py
index 369a84c..e617aba 100644
--- a/talerbank/app/models.py
+++ b/talerbank/app/models.py
@@ -121,24 +121,6 @@ class AmountField(models.Field):
             raise ValidationError(
                 "Invalid input for an amount string: %s" % value)
 
-
-##
-# Exception class to raise when a non-existent bank account is
-# tried to be referenced.
-class BankAccountDoesNotExist(ObjectDoesNotExist):
-    hint = "Specified bank account does not exist"
-    http_status_code = 404
-
-
-##
-# Exception class to raise when a non-existent bank transaction is
-# tried to be referenced.
-class BankTransactionDoesNotExist(ObjectDoesNotExist):
-    hint = "Specified bank transaction does not exist"
-    http_status_code = 404
-
-
-
 ##
 # The class representing a bank account.
 class BankAccount(models.Model):
@@ -147,8 +129,6 @@ class BankAccount(models.Model):
     account_no = models.AutoField(primary_key=True)
     user = models.OneToOneField(User, on_delete=models.CASCADE)
     amount = AmountField(default=get_zero_amount)
-    DoesNotExist = BankAccountDoesNotExist
-
 
 ##
 # The class representing a bank transaction.

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]