Skip to content

Commit 1df4bf4

Browse files
committed
Končno stanje aplikacije za letos
1 parent 6d5a0f9 commit 1df4bf4

11 files changed

Lines changed: 382 additions & 15 deletions

predavanja/primeri/banka/banka.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,164 @@ def komitenti(uporabnik):
209209
pass
210210

211211

212+
@bottle.get('/komitenti/<emso>/racuni/')
213+
@bottle.view('komitenti.racuni.html')
214+
@prijavljen
215+
def komitenti_racuni(uporabnik, emso):
216+
preveri_lastnika(uporabnik, emso)
217+
try:
218+
return dict(oseba=Oseba.z_id(emso))
219+
except ValueError:
220+
bottle.abort(404, f'Uporabnik z EMŠOm {emso} ne obstaja!')
221+
222+
223+
@bottle.get('/komitenti/<emso>/transakcije/')
224+
@bottle.view('komitenti.transakcije.html')
225+
@prijavljen
226+
def komitenti_transakcije(uporabnik, emso):
227+
preveri_lastnika(uporabnik, emso)
228+
try:
229+
return dict(oseba=Oseba.z_id(emso))
230+
except ValueError:
231+
bottle.abort(404, f'Uporabnik z EMŠOm {emso} ne obstaja!')
232+
233+
234+
@bottle.get('/komitenti/<emso>/uredi/')
235+
@bottle.view('komitenti.uredi.html')
236+
@prijavljen
237+
def komitenti_uredi(uporabnik, emso):
238+
preveri_lastnika(uporabnik, emso)
239+
try:
240+
return dict(oseba=Oseba.z_id(emso))
241+
except ValueError:
242+
bottle.abort(404, f'Uporabnik z EMŠOm {emso} ne obstaja!')
243+
244+
245+
@bottle.post('/komitenti/<emso>/uredi/')
246+
@prijavljen
247+
def komitenti_uredi_post(uporabnik, emso):
248+
preveri_lastnika(uporabnik, emso)
249+
ime = bottle.request.forms.getunicode('ime')
250+
priimek = bottle.request.forms.getunicode('priimek')
251+
naslov = bottle.request.forms.getunicode('naslov')
252+
try:
253+
kraj = int(bottle.request.forms.getunicode('kraj'))
254+
except ValueError:
255+
kraj = None
256+
uporabnisko_ime = bottle.request.forms.getunicode('uporabnisko_ime')
257+
geslo = bottle.request.forms.getunicode('geslo')
258+
geslo2 = bottle.request.forms.getunicode('geslo2')
259+
try:
260+
oseba = Oseba.z_id(emso)
261+
except ValueError:
262+
bottle.abort(404, f'Uporabnik z EMŠOm {emso} ne obstaja!')
263+
oseba.posodobi_polja(ime=ime, priimek=priimek, naslov=naslov, kraj=kraj, uporabnisko_ime=uporabnisko_ime)
264+
if uporabnik.admin:
265+
oseba.admin = bool(bottle.request.forms.getunicode('admin'))
266+
if geslo:
267+
if geslo == geslo2:
268+
oseba.geslo = geslo
269+
else:
270+
nastavi_sporocilo("Gesli se ne ujemata!")
271+
nastavi_obrazec(f'komitenti_uredi-{emso}', oseba)
272+
bottle.redirect(bottle.url('komitenti_uredi', emso))
273+
try:
274+
oseba.posodobi()
275+
nastavi_sporocilo(f"Uspešno posodobljen komitenta z EMŠOm {emso}!")
276+
if uporabnik.admin:
277+
bottle.redirect(bottle.url('komitenti'))
278+
else:
279+
bottle.redirect(bottle.url('index'))
280+
except IntegrityError:
281+
nastavi_sporocilo(f"Urejanje komitenta z EMŠOm {emso} ni uspelo!")
282+
nastavi_obrazec(f'komitenti_uredi-{emso}', oseba)
283+
bottle.redirect(bottle.url('komitenti_uredi', emso))
284+
285+
286+
@bottle.get('/komitenti/dodaj/')
287+
@bottle.view('komitenti.dodaj.html')
288+
@admin
289+
def komitenti_dodaj(uporabnik):
290+
pass
291+
292+
293+
@bottle.post('/komitenti/dodaj/')
294+
@admin
295+
def komitenti_dodaj_post(uporabnik):
296+
emso = bottle.request.forms.getunicode('emso')
297+
ime = bottle.request.forms.getunicode('ime')
298+
priimek = bottle.request.forms.getunicode('priimek')
299+
naslov = bottle.request.forms.getunicode('naslov')
300+
try:
301+
kraj = int(bottle.request.forms.getunicode('kraj'))
302+
except ValueError:
303+
kraj = None
304+
uporabnisko_ime = bottle.request.forms.getunicode('uporabnisko_ime')
305+
geslo = bottle.request.forms.getunicode('geslo')
306+
geslo2 = bottle.request.forms.getunicode('geslo2')
307+
admin = bool(bottle.request.forms.getunicode('admin'))
308+
oseba = Oseba(emso=emso, ime=ime, priimek=priimek, naslov=naslov, kraj=kraj, uporabnisko_ime=uporabnisko_ime, admin=admin)
309+
if geslo:
310+
if geslo == geslo2:
311+
oseba.geslo = geslo
312+
else:
313+
nastavi_sporocilo("Gesli se ne ujemata!")
314+
nastavi_obrazec(f'komitenti_dodaj', oseba)
315+
bottle.redirect(bottle.url('komitenti_dodaj'))
316+
try:
317+
oseba.vstavi()
318+
nastavi_sporocilo(f"Uspešno dodan komitent z EMŠOm {emso}!")
319+
bottle.redirect(bottle.url('komitenti'))
320+
except IntegrityError:
321+
nastavi_sporocilo(f"Dodajanje komitenta z EMŠOm {emso} ni uspelo!")
322+
nastavi_obrazec(f'komitenti_dodaj', oseba)
323+
bottle.redirect(bottle.url('komitenti_dodaj'))
324+
325+
326+
@bottle.post('/komitenti/<emso>/izbrisi/')
327+
@admin
328+
def komitenti_izbrisi_post(uporabnik, emso):
329+
try:
330+
Oseba.z_id(emso).izbrisi()
331+
nastavi_sporocilo(f'Komitent z EMŠOm {emso} uspešno izbrisan.')
332+
except ValueError:
333+
bottle.abort(404, f'Uporabnik z EMŠOm {emso} ne obstaja!')
334+
except IntegrityError:
335+
nastavi_sporocilo(f'Brisanje komitenta z EMŠOm {emso} ni bilo uspešno!')
336+
bottle.redirect(bottle.url('komitenti'))
337+
338+
339+
@bottle.post('/komitenti/<emso>/dodaj_racun/')
340+
@admin
341+
def komitenti_dodaj_racun_post(uporabnik, emso):
342+
try:
343+
racun = Racun(lastnik=emso)
344+
racun.vstavi()
345+
nastavi_sporocilo(f'Račun s številko {racun.stevilka} uspešno dodan.')
346+
except IntegrityError:
347+
nastavi_sporocilo(f'Dodajanje računa za komitenta z EMŠOm {emso} ni bilo uspešno!')
348+
bottle.redirect(bottle.url('komitenti_racuni', emso=emso))
349+
350+
212351
@bottle.get('/racuni/')
213352
@bottle.view('racuni.html')
214353
@admin
215354
def racuni(uporabnik):
216355
pass
217356

218357

358+
@bottle.get('/racuni/<stevilka:int>/transakcije/')
359+
@bottle.view('racuni.transakcije.html')
360+
@prijavljen
361+
def racuni_transakcije(uporabnik, stevilka):
362+
try:
363+
racun = Racun.z_id(stevilka)
364+
except ValueError:
365+
bottle.abort(404, f'Račun s številko {stevilka} ne obstaja!')
366+
preveri_lastnika(uporabnik, racun.lastnik.emso)
367+
return dict(racun=racun)
368+
369+
219370
@bottle.get('/transakcije/')
220371
@bottle.view('transakcije.html')
221372
@admin

predavanja/primeri/banka/model.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ def racuni(self):
295295
for stevilka, znesek in cur:
296296
yield Racun(stevilka, self, znesek)
297297

298+
def transakcije(self):
299+
with conn.transaction():
300+
with conn.cursor() as cur:
301+
cur.execute(
302+
"""
303+
SELECT id, stevilka, znesek, cas, opis FROM transakcija
304+
JOIN racun ON racun = stevilka
305+
WHERE lastnik = %s
306+
ORDER BY cas DESC
307+
""", (self.emso, )
308+
)
309+
for id, stevilka, *podatki in cur:
310+
yield Transakcija(id, Racun(stevilka, self), *podatki)
311+
298312
def dodaj_racun(self):
299313
racun = Racun(lastnik=self)
300314
racun.vstavi()
@@ -315,12 +329,16 @@ def vstavi(self):
315329
def posodobi(self):
316330
with conn.transaction():
317331
with conn.cursor() as cur:
318-
cur.execute(
332+
podatki = self.kot_slovar()
333+
cur.execute(sql.SQL(
319334
"""
320335
UPDATE oseba SET ime = %(ime)s, priimek = %(priimek)s, naslov = %(naslov)s,
321336
kraj = %(kraj)s, uporabnisko_ime = %(uporabnisko_ime)s, admin = %(admin)s
337+
{geslo}
322338
WHERE emso = %(emso)s
323-
""", self.kot_slovar()
339+
""").format(
340+
geslo=sql.SQL(", geslo = %(geslo)s" if podatki['geslo'] else "")
341+
), podatki
324342
)
325343

326344
def izbrisi(self):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
% rebase('osnova.html', stran=f'komitenti_dodaj', naslov='Dodajanje komitenta')
2+
% oseba = preberi_obrazec(f'komitenti_dodaj', Oseba)
3+
4+
<h1 class="title">
5+
Dodajanje komitenta
6+
</h1>
7+
8+
<form action="{{url('komitenti_dodaj_post')}}" method="POST">
9+
% include('komitenti.obrazec.html', admin=True)
10+
<div class="field">
11+
<div class="control">
12+
<button class="button is-link">Dodaj komitenta</button>
13+
</div>
14+
</div>
15+
</form>

predavanja/primeri/banka/views/komitenti.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1 class="title">
1111
</div>
1212
<div class="level-right">
1313
<div class="level-item">
14-
<a class="button is-primary">
14+
<a href="{{url('komitenti_dodaj')}}" class="button is-primary">
1515
Dodaj komitenta
1616
</a>
1717
</div>
@@ -27,17 +27,21 @@ <h1 class="title">
2727
</tr>
2828
% for oseba in Oseba.seznam():
2929
<tr>
30-
<td>{{oseba.emso}}</td>
30+
<td>
31+
<a href="{{url('komitenti_racuni', emso=oseba.emso)}}"">
32+
{{oseba.emso}}
33+
</a>
34+
</td>
3135
<td>{{oseba.ime}} {{oseba.priimek}}</td>
3236
<td>{{oseba.naslov}}, {{oseba.kraj.posta}}, {{oseba.kraj.kraj}}</td>
3337
<td>
3438
<div class="buttons">
35-
<a class="button is-primary">
39+
<a href="{{url('komitenti_uredi', emso=oseba.emso)}}" class="button is-primary">
3640
<span class="icon is-small">
3741
<i class="fas fa-pen"></i>
3842
</span>
3943
</a>
40-
<form method="POST"
44+
<form method="POST" action="{{url('komitenti_izbrisi_post', emso=oseba.emso)}}"
4145
onsubmit="return confirm('Ali res želiš izbrisati komitenta z EMŠOm {{oseba.emso}}?')">
4246
<button class="button is-danger">
4347
<span class="icon is-small">
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
% rebase('osnova.html', stran=f'komitenti_racuni-{oseba.emso}', naslov='Računi komienta')
2+
3+
<div class="container">
4+
<div class="level">
5+
<div class="level-left">
6+
<div class="level-item">
7+
<h1 class="title">
8+
Računi komitenta {{oseba.ime}} {{oseba.priimek}} ({{oseba.emso}})
9+
</h1>
10+
</div>
11+
</div>
12+
<div class="level-right">
13+
<div class="level-item">
14+
<form method="POST" action="{{url('komitenti_dodaj_racun_post', emso=oseba.emso)}}">
15+
<button class="button is-primary">
16+
Dodaj račun
17+
</button>
18+
</form>
19+
</div>
20+
</div>
21+
</div>
22+
23+
<table class="table">
24+
<tr>
25+
<th>Številka</th>
26+
<th>Stanje</th>
27+
<th></th>
28+
</tr>
29+
% for racun in oseba.racuni():
30+
<tr>
31+
<td>
32+
<a href="{{url('racuni_transakcije', stevilka=racun.stevilka)}}">
33+
{{racun.stevilka}}
34+
</a>
35+
</td>
36+
<td>{{racun.stanje}}</td>
37+
<td>
38+
<div class="buttons">
39+
<form method="POST"
40+
onsubmit="return confirm('Ali res želiš izbrisati račun s številko {{racun.stevilka}}?')">
41+
<button class="button is-danger">
42+
<span class="icon is-small">
43+
<i class="fas fa-trash"></i>
44+
</span>
45+
</button>
46+
</form>
47+
</div>
48+
</td>
49+
</tr>
50+
% end
51+
</table>
52+
</div>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
% rebase('osnova.html', stran=f'komitenti_transakcije-{oseba.emso}', naslov='Transakcije komitenta')
2+
3+
<div class="container">
4+
<h1 class="title">Transakcije komitenta {{oseba.ime}} {{oseba.priimek}} ({{oseba.emso}})</h1>
5+
6+
<table class="table">
7+
<tr>
8+
<th>ID</th>
9+
<th>Račun</th>
10+
<th>Znesek</th>
11+
<th>Čas</th>
12+
<th>Opis</th>
13+
% if uporabnik.admin:
14+
<th></th>
15+
% end
16+
</tr>
17+
% for transakcija in oseba.transakcije():
18+
<tr>
19+
<td>{{transakcija.id}}</td>
20+
<td>
21+
<a href="{{url('racuni_transakcije', stevilka=transakcija.racun.stevilka)}}">
22+
{{transakcija.racun.stevilka}}
23+
</a>
24+
</td>
25+
<td>{{transakcija.znesek}}</td>
26+
<td class="cas">{{transakcija.cas}}</td>
27+
<td>{{transakcija.opis}}</td>
28+
% if uporabnik.admin:
29+
<td>
30+
<div class="buttons">
31+
<a class="button is-primary">
32+
<span class="icon is-small">
33+
<i class="fas fa-pen"></i>
34+
</span>
35+
</a>
36+
<form method="POST"
37+
onsubmit="return confirm('Ali res želiš izbrisati transakcijo z ID-jem {{transakcija.id}}?')">
38+
<button class="button is-danger">
39+
<span class="icon is-small">
40+
<i class="fas fa-trash"></i>
41+
</span>
42+
</button>
43+
</form>
44+
</div>
45+
</td>
46+
% end
47+
</tr>
48+
% end
49+
</table>
50+
</div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
% rebase('osnova.html', stran=f'komitenti_uredi-{oseba.emso}', naslov='Urejanje komitenta')
2+
% oseba = preberi_obrazec(f'komitenti_uredi-{oseba.emso}', oseba)
3+
4+
<h1 class="title">
5+
Urejanje komitenta
6+
</h1>
7+
8+
<form action="{{url('komitenti_uredi_post', emso=oseba.emso)}}" method="POST">
9+
% include('komitenti.obrazec.html', onemogoci_emso=True, admin=uporabnik.admin)
10+
<div class="field">
11+
<div class="control">
12+
<button class="button is-link">Spremeni podatke</button>
13+
</div>
14+
</div>
15+
</form>

predavanja/primeri/banka/views/osnova.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</a>
5555

5656
<div class="navbar-dropdown">
57-
<a class="navbar-item {{'is-selected' if stran == f'komitenti_racuni-{uporabnik.emso}' else ''}}">
57+
<a href="{{url('komitenti_racuni', emso=uporabnik.emso)}}" class="navbar-item {{'is-selected' if stran == f'komitenti_racuni-{uporabnik.emso}' else ''}}">
5858
Moji računi
5959
</a>
6060
% if uporabnik.admin:
@@ -71,7 +71,7 @@
7171
</a>
7272

7373
<div class="navbar-dropdown">
74-
<a class="navbar-item {{'is-selected' if stran == f'komitenti_transakcije-{uporabnik.emso}' else ''}}">
74+
<a href="{{url('komitenti_transakcije', emso=uporabnik.emso)}}" class="navbar-item {{'is-selected' if stran == f'komitenti_transakcije-{uporabnik.emso}' else ''}}">
7575
Moje transakcije
7676
</a>
7777
% if uporabnik.admin:

0 commit comments

Comments
 (0)