-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
208 lines (134 loc) · 7.16 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import sys
sys.path.append("home/lucas/Documentos/NSI/eis/eispatterns-examples")
sys.path.append("/home/lucas/Documentos/NSI/eis/eispatterns")
from django.core.context_processors import csrf
from django.shortcuts import render_to_response
from django.http import HttpResponse
from bank_system.models import *
from django.contrib.auth import authenticate, logout, login as authlogin
from django.template import RequestContext, Context, loader
from bank_system.resources.bill import Bill
from django.core.exceptions import ObjectDoesNotExist
def home(request):
csrfContext = RequestContext(request)
return render_to_response('home.html', csrfContext)
def login(request):
if request.user.id:
return render_to_response('logged.html',context_instance = RequestContext(request, {}))
if request.POST:
accountUser = request.POST.get('account')
passwordUser = request.POST.get('password')
u = authenticate(username = accountUser, password = passwordUser)
if u is not None:
if u.is_active:
authlogin(request, u)
user = User.objects.get(username = accountUser)
user.self_decorate()
user.save()
account = BankAccountDecorator.objects.get(number = user)
account.self_decorate()
account.save()
if request.POST.get('next'):
return HttpResponseRedirect(request.POST.get('next'))
return render_to_response('logged.html',locals(),context_instance = RequestContext(request, {}))
return render_to_response('login.html',(),context_instance = RequestContext(request, {}))
def log_out(request):
logout(request)
csrfContext = RequestContext(request)
return render_to_response('home.html',csrfContext)
def contact(request):
first_name = request.POST.get('first_name')
last_name = request.POST.get('last_name')
email = request.POST.get('email')
telephone = request.POST.get('telephone')
comments = request.POST.get('comments')
if first_name and email and comments is not None:
contact = ContactDecorator.objects.create(first_name = first_name, last_name = last_name , emailUser = email , telephone = telephone , comments = comments)
contact.self_decorate()
contact.save()
return render_to_response('send.html',RequestContext(request))
return render_to_response('contact.html',locals(),context_instance = RequestContext(request, {}))
def balance(request):
if not request.user.id or request.user.is_superuser == True:
return render_to_response('logged_error.html',context_instance = RequestContext(request, {}))
user = User.objects.get(username = request.user)
user.self_decorate()
user.save()
account = BankAccountDecorator.objects.get(number = user)
account.self_decorate()
account.save()
number = account.number
client = account.client
average_credit = account.average_credit
balance = account.balance
log = account.log_area
return render_to_response('balance.html',locals(),context_instance = RequestContext(request, {}))
def transfer(request):
if not request.user.id or request.user.is_superuser == True:
return render_to_response('logged_error.html',context_instance = RequestContext(request, {}))
if request.POST:
accountNumber = request.POST.get('account_number')
amountTransfer = request.POST.get('amount_transfer')
user = User.objects.get(username = request.user)
user.self_decorate()
user.save()
bank_account = BankAccountDecorator.objects.get(number = user)
bank_account.self_decorate()
user = User.objects.get(username = accountNumber)
user.self_decorate()
user.save()
the_other_bank_account = BankAccountDecorator.objects.get(number = user)
the_other_bank_account.self_decorate()
if user == request.user :
return render_to_response('transfer_error.html',context_instance = RequestContext(request,{}))
bank_account.log_area += '/ / Transfer: ' + str(user) + ' Value: ' + str(amountTransfer) + " / /\n\n"
bank_account.transfer(amountTransfer,the_other_bank_account)
bank_account.save()
the_other_bank_account.save()
return render_to_response('sucess.html',context_instance = RequestContext(request,{}))
return render_to_response('transfer.html',context_instance = RequestContext(request, {}))
def loans(request):
if not request.user.id or request.user.is_superuser == True:
return render_to_response('logged_error.html',context_instance = RequestContext(request, {}))
if request.POST:
RuleManager.rule_base = BankSystemRuleBase()
user = User.objects.get(username = request.user)
user.self_decorate()
user.save()
bank_account = BankAccountDecorator.objects.get(number = user)
bank_account.self_decorate()
amount_loan = request.POST.get('loan')
try:
credit_analyst = CreditAnalystDecorator.objects.get(register = request.POST.get('analyst'))
except (CreditAnalystDecorator.DoesNotExist):
return render_to_response('loan_error.html',context_instance = RequestContext(request,{}))
bank_account.log_area += '/ / Loan: ' + str(amount_loan) + ' Credit Analyst: ' + str(credit_analyst.register) + "/ /\n\n"
a_loan_request = LoanRequest(bank_account,amount_loan,credit_analyst)
a_loan = Loan(a_loan_request)
bank_account.save()
return render_to_response('sucess.html',locals(),context_instance = RequestContext(request, {}))
return render_to_response('loans.html',(),context_instance = RequestContext(request, {}))
def payments(request):
if not request.user.id or request.user.is_superuser == True:
return render_to_response('logged_error.html',context_instance = RequestContext(request, {}))
if request.POST:
RuleManager.rule_base = BankSystemRuleBase()
user = User.objects.get(username = request.user)
user.self_decorate()
user.save()
bank_account = BankAccountDecorator.objects.get(number = user)
bank_account.self_decorate()
bill = request.POST.get('bill')
payment = request.POST.get('number')
amount_charged = request.POST.get('amount_charged')
bank_account.log_area += '/ / Payment: ' + str(bill) + ' Value: ' + str(amount_charged) + ' Payed: ' + str(payment) + "/ /\n\n"
bill_payment = Bill(bank_account,bill,payment,amount_charged)
bank_account.save()
return render_to_response('sucess.html',locals(),context_instance = RequestContext(request, {}))
return render_to_response('payments.html',(),context_instance = RequestContext(request, {}))
def sucess(request):
csrfContext = RequestContext(request)
return render_to_response('sucess.html', csrfContext)
def about(request):
csrfContext = RequestContext(request)
return render_to_response('about.html', csrfContext)