forked from itucsdb1606/itucsdb1606
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhobiler.py
97 lines (84 loc) · 2.75 KB
/
hobiler.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
import datetime
import os
import json
import re
import psycopg2 as dbapi2
class Hobiler:
def __init__(self, isim, resim, alan, koordinator, aciklama):
self.isim = isim
self.resim = resim
self.alan = alan
self.koordinator = koordinator
self.aciklama = aciklama
def init_hobiler_db(cursor):
query = """CREATE TABLE IF NOT EXISTS HOBILER (
ID SERIAL PRIMARY KEY,
ISIM varchar(100) NOT NULL,
RESIM VARCHAR(80) NOT NULL DEFAULT 'defaulthobi.jpg',
ALAN varchar(100) NOT NULL,
KOORDINATOR INTEGER NOT NULL REFERENCES KISILER(ID) ON DELETE CASCADE ON UPDATE CASCADE,
ACIKLAMA varchar(1000) NOT NULL
)"""
cursor.execute(query)
insert_hobiler(cursor)
def insert_hobiler(cursor):
query = """INSERT INTO HOBILER
(ISIM, RESIM, ALAN, KOORDINATOR, ACIKLAMA) VALUES (
'Okculuk',
'okculuk.jpg',
'Spor',
4,
'Okculuk ok ve yay ile yapilan bir hobidir..'
);
INSERT INTO HOBILER
(ISIM, RESIM, ALAN, KOORDINATOR, ACIKLAMA) VALUES (
'Dagcilik',
'dagcilik.jpg',
'Spor',
3,
'Daglara ciktin mi tum ulke, tum dunya ayalarinin altindadir, boyle bir hobidir..'
);
INSERT INTO HOBILER
(ISIM, RESIM, ALAN, KOORDINATOR, ACIKLAMA) VALUES (
'Resim',
'resim.jpg',
'Sanat',
1,
'Belki bir picasso olamayabilirsin ama kendini bulacagin bir hobidir..'
);
INSERT INTO HOBILER
(ISIM, RESIM, ALAN, KOORDINATOR, ACIKLAMA) VALUES (
'Gitar',
'gitar.jpg',
'Muzik',
2,
'Herkes muzigi sever, en azindan dinlemeyi, siz de bir adim oteye gecin...'
);
;"""
cursor.execute(query)
def add_hobiler(cursor, request, hobi1):
query = """INSERT INTO HOBILER
(ISIM, RESIM, ALAN, KOORDINATOR, ACIKLAMA) VALUES (
INITCAP(%s),
INITCAP(%s),
INITCAP(%s),
%s,
INITCAP(%s)
)"""
cursor.execute(query, (hobi1.isim, hobi1.resim, hobi1.alan,
hobi1.koordinator, hobi1.aciklama))
def delete_hobiler(cursor, id):
query="""DELETE FROM HOBILER WHERE ID = %s"""
cursor.execute(query, id)
def update_hobiler(cursor, id, hobi1):
query="""
UPDATE HOBILER
SET ISIM=INITCAP(%s),
RESIM=INITCAP(%s),
ALAN=INITCAP(%s),
KOORDINATOR=%s,
ACIKLAMA=INITCAP(%s)
WHERE ID=%s
"""
cursor.execute(query, (hobi1.isim, hobi1.resim, hobi1.alan,
hobi1.koordinator, hobi1.aciklama, id))