1
- from donate .database import db
1
+ from donate .extensions import db
2
2
from datetime import datetime
3
+ from flask_validator import (
4
+ ValidateInteger ,
5
+ ValidateString ,
6
+ ValidateEmail ,
7
+ ValidateNumeric ,
8
+ )
3
9
4
10
5
11
class User (db .Model ):
12
+ '''A user is someonme internal to Noisebridge who uses the system for
13
+ reportinng purposes. This should include treasurers and priviledged
14
+ users who may access sensitive user data for donations
15
+
16
+ id: unique ID of the user, e.g. primary key
17
+ username: name internal to the system
18
+ slack: slack handle
19
+ email: email address of user
20
+ '''
21
+
6
22
id = db .Column (db .Integer , primary_key = True )
7
23
username = db .Column (db .String (80 ), unique = True , nullable = False )
8
24
slack = db .Column (db .String (80 ), unique = True , nullable = False )
@@ -11,16 +27,40 @@ class User(db.Model):
11
27
def __repr__ (self ):
12
28
return ('<User {}>' .format (self .username ))
13
29
30
+ @classmethod
31
+ def __declare_last__ (cls ):
32
+ ValidateString (User .username , False , True )
33
+ ValidateString (User .slack , False , True )
34
+ ValidateEmail (User .email ,
35
+ False ,
36
+ True ,
37
+ "not a valid email address" )
38
+
14
39
15
40
class Transaction (db .Model ):
41
+ ''' A transaction moves amounts between accounts. When a transaction
42
+ occurs, an account must be debited and an account must be credited.
43
+
44
+ id: unique ID of transaction
45
+ amount: the quantity of the transaction, e.g. <X> USD or <Y> BTC.
46
+ ccy: the denomiation of the transaction, e.g. 100 <CCY>
47
+ datetime: the time of the transaction in epochs
48
+ payer_id: The account which will be debited
49
+ recvr_id: the account which will be credited
50
+ requestor_id: The user who is requesting the transfer
51
+ approver_id: The user approving the transfoer
52
+ pay_from_acct: Account linked to the payer_id
53
+ rec_to_acct: Account linked to recvr_id
54
+ '''
55
+
16
56
id = db .Column (db .Integer , primary_key = True )
17
57
amount = db .Column (db .Float , nullable = False )
18
58
ccy = db .Column (db .Integer , db .ForeignKey ('currency.id' ))
19
59
datetime = db .Column (db .DateTime , nullable = False , default = datetime .utcnow )
20
60
payer_id = db .Column (db .Integer ,
21
61
db .ForeignKey ('account.id' ),
22
62
nullable = False )
23
- recer_id = db .Column (db .Integer ,
63
+ recvr_id = db .Column (db .Integer ,
24
64
db .ForeignKey ('account.id' ),
25
65
nullable = False )
26
66
requestor_id = db .Column (db .Integer ,
@@ -31,26 +71,74 @@ class Transaction(db.Model):
31
71
nullable = False )
32
72
33
73
pay_from_acct = db .relationship ('Account' , foreign_keys = [payer_id ])
34
- rec_to_acct = db .relationship ('Account' , foreign_keys = [recer_id ])
74
+ rec_to_acct = db .relationship ('Account' , foreign_keys = [recvr_id ])
75
+
76
+ @classmethod
77
+ def __declare_last__ (cls ):
78
+ ValidateInteger (Transaction .ccy , False , True )
79
+ ValidateNumeric (Transaction .amount , False , True )
80
+ ValidateInteger (Transaction .payer_id , False , True )
81
+ ValidateInteger (Transaction .recvr_id , False , True )
82
+ ValidateInteger (Transaction .requestor_id , False , True )
83
+ ValidateInteger (Transaction .approver_id , False , True )
35
84
36
85
37
86
class Account (db .Model ):
87
+ ''' Accounts aggregate transactions. They are associated with one and
88
+ only one currenct. An account can increase or decrease based on the
89
+ sum of the transactions.
90
+
91
+ id: unique Id
92
+ name: name or nmenonic of account
93
+ tx_ids: transactions associated with account. Must link to pay/rec to
94
+ get debit or credit info
95
+ ccy: account denomination e.g. USD or BTC.
96
+ '''
97
+
38
98
id = db .Column (db .Integer , primary_key = True )
39
99
name = db .Column (db .String (120 ), unique = True , nullable = False )
40
100
tx_ids = db .Column (db .Integer , db .ForeignKey ('transaction.id' ))
41
101
ccy = db .Column (db .Integer , db .ForeignKey ('currency.id' ))
42
102
103
+ @classmethod
104
+ def __declare_last__ (cls ):
105
+ ValidateString (Account .name , False , True )
106
+ ValidateInteger (Account .tx_ids , False , True )
107
+ ValidateInteger (Account .ccy , False , True )
108
+
43
109
44
110
class Project (db .Model ):
111
+ ''' A project has a specific goal, e.g. amount to be reached. It is
112
+ linked to an account which provides information about how much has been
113
+ donated towards the goal.
114
+
115
+ id: Unique ID
116
+ name: Project name
117
+ account_id: Accunt linked to project (might need multiple for multiple ccys
118
+ goal: Amount required to read the goal of the project.
119
+ (prob need ccy)
120
+ '''
121
+
45
122
id = db .Column (db .Integer , primary_key = True )
46
123
name = db .Column (db .String (120 ), unique = True , nullable = False )
47
124
account_id = db .Column (db .Integer ,
48
125
db .ForeignKey ('account.id' ),
49
126
nullable = False )
50
127
goal = db .Column (db .Float , nullable = False , default = 0 )
51
128
129
+ @classmethod
130
+ def __declare_last__ (cls ):
131
+ ValidateString (Project .name , False , True )
132
+ ValidateInteger (Project .account_id , False , True )
133
+ ValidateNumeric (Project .goal , False , True )
134
+
52
135
53
136
class Currency (db .Model ):
54
137
id = db .Column (db .Integer , primary_key = True )
55
138
name = db .Column (db .String (120 ), unique = True , nullable = False )
56
139
code = db .Column (db .String (3 ), unique = True , nullable = False )
140
+
141
+ @classmethod
142
+ def __declare_last__ (cls ):
143
+ ValidateString (Currency .name , False , True )
144
+ ValidateString (Currency .code , False , True )
0 commit comments