gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-bank] 01/04: define db custom type


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 01/04: define db custom type
Date: Tue, 31 Oct 2017 15:05:08 +0100

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

marcello pushed a commit to branch master
in repository bank.

commit 034d17745f005fc1de33f81d21a7ce1f61f54173
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Oct 30 13:43:56 2017 +0100

    define db custom type
---
 talerbank/app/models.py         | 31 +++++++++++++++++++++++++++++++
 talerbank/app/static/web-common |  2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/talerbank/app/models.py b/talerbank/app/models.py
index 868b0d6..e758b92 100644
--- a/talerbank/app/models.py
+++ b/talerbank/app/models.py
@@ -19,6 +19,37 @@ from __future__ import unicode_literals
 from django.contrib.auth.models import User
 from django.db import models
 
+class AmountField(models.Field):
+    
+    description = 'Amount object in Taler style'
+    
+    def __init__(self, *args, **kwargs):
+        super(AmountField, self).__init__(*args, **kwargs)
+
+    def deconstruct(self):
+        name, path, args, kwargs = super(AmountField, self).deconstruct()
+        return name, path, args, kwargs
+
+    def db_type(self):
+        return "taleramount"
+
+    # Pass stringified object to db connector
+    def get_prep_value(self, value):
+        return value.stringify()
+
+    def from_db_value(self, value, expression, connection, context):
+        if None is value:
+            return value
+        return Amount.parse(value)
+
+    def to_python(self, value):
+        if isinstance(value, Amount) or None is value:
+            return value
+        try:
+            return Amount.parse(value)
+        except BadAmount:
+            raise models.ValidationError()
+
 
 class BankAccount(models.Model):
     is_public = models.BooleanField(default=False)
diff --git a/talerbank/app/static/web-common b/talerbank/app/static/web-common
index d7e0135..489a9e3 160000
--- a/talerbank/app/static/web-common
+++ b/talerbank/app/static/web-common
@@ -1 +1 @@
-Subproject commit d7e013594d15388b1a7342a44a0e9c8d4ecca82d
+Subproject commit 489a9e38e6960fdce309ab8cf5ff66d930ecb3bc

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



reply via email to

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