-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspletna_banka.py
98 lines (88 loc) · 3.08 KB
/
spletna_banka.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
# Testni projekt o banki.
# Sodelavci na projektu:
# - alenFMF
# - MarinaUVP
# - PoljanecB15
# - Larisa123
# - AnjaTrop
# - SavliE12
# - kulan89
# - martincesnovar
import modeli as modeli
from bottle import *
from datetime import datetime
def pretvoriDatum(x):
if x is None:
return None
if isinstance(x, str):
return time.strftime("%d.%m.%Y", time.strptime(x, '%Y-%m-%d %H:%M:%S'))
else:
return datetime.strftime(x, "%d.%m.%Y")
@get('/')
def glavniMenu():
return template('glavni.html', ime = None, priimek = None, emso = None,
ulica = None, hisna_st = None, postna_st = None,
kraj = None, napaka = None)
@get('/static/<filename:path>')
def static(filename):
return static_file(filename, root='static')
@get('/oseba/<emso>')
def oOsebi(emso):
napaka = request.query.napaka
if not napaka:
napaka = None
emso, ime, priimek, ulica, hisna_st, postna_st, posta = modeli.poisciEMSO(emso)
racuni = modeli.racunEMSO(emso)
return template('oseba.html', emso = emso, ime = ime, priimek = priimek,
ulica = ulica, hisna_st = hisna_st, postna_st = postna_st,
posta = posta, racuni = racuni, pretvori = pretvoriDatum,
napaka = napaka)
@get('/isci')
def isci():
priimek = request.query.iskalniNiz
rezultat = modeli.poisciPriimek(priimek)
return template('isci.html', rezultat = rezultat)
@post('/dodaj')
def dodaj():
emso = request.forms.emso
ime = request.forms.ime
priimek = request.forms.priimek
ulica = request.forms.ulica
hisna_st = request.forms.hisna_st
postna_st = request.forms.postna_st
kraj = request.forms.kraj
try:
if not modeli.dodajOsebo(ime, priimek, emso, ulica, hisna_st, postna_st):
modeli.dodajKraj(postna_st, kraj)
modeli.dodajOsebo(ime, priimek, emso, ulica, hisna_st, postna_st)
except Exception as e:
return template('glavni.html', ime = ime, priimek = priimek, emso = emso,
ulica = ulica, hisna_st = hisna_st, postna_st = postna_st,
kraj = kraj, napaka = e)
redirect('/oseba/' + emso)
@post('/polog/<racun>')
def polog(racun):
emso, = modeli.emsoRacun(racun)
try:
znesek = int(request.forms.znesek)
except Exception as e:
redirect('/oseba/' + emso + '?napaka=Neveljaven znesek!')
if znesek <= 0:
redirect('/oseba/' + emso + '?napaka=Znesek mora biti pozitiven!')
else:
modeli.dodajTransakcijo(racun, znesek)
redirect('/oseba/' + emso)
@post('/dvig/<racun>')
def dvig(racun):
emso, = modeli.emsoRacun(racun)
try:
znesek = int(request.forms.znesek)
except Exception as e:
redirect('/oseba/' + emso + '?napaka=Neveljaven znesek!')
if znesek <= 0:
redirect('/oseba/' + emso + '?napaka=Znesek mora biti pozitiven!')
else:
modeli.dodajTransakcijo(racun, -znesek)
redirect('/oseba/' + emso)
# poženemo strežnik na portu 8080, glej http://localhost:8080/
run(host='localhost', port=8080, reloader=True)