forked from itucsdb1606/itucsdb1606
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsirketler.py
119 lines (109 loc) · 3.25 KB
/
sirketler.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
import json
import datetime
import re
import os
import psycopg2 as dbapi2
from flask import Flask
from flask import render_template
from flask import redirect
from flask import request
from flask.helpers import url_for
class Sirket:
def __init__(self, name, date, location, ceo_id, work_area, photo):
self.name = name
self.date = date
self.location = location
self.ceo_id = ceo_id
self.work_area = work_area
self.photo = photo
def init_sirketler_db(cursor):
query = """DROP TABLE IF EXISTS SIRKET"""
cursor.execute(query)
query = """CREATE TABLE SIRKET (
ID SERIAL PRIMARY KEY,
NAME varchar(100) UNIQUE NOT NULL,
DATE varchar NOT NULL,
LOCATION INTEGER NOT NULL REFERENCES LOKASYON(ID) ON DELETE CASCADE ON UPDATE CASCADE,
CEO_ID INTEGER NOT NULL REFERENCES KISILER(ID) ON DELETE CASCADE ON UPDATE CASCADE DEFAULT 1,
WORK_AREA varchar(500),
PHOTO varchar(80) UNIQUE
)"""
cursor.execute(query)
insert_sirket(cursor)
def insert_sirket(cursor):
query = """INSERT INTO SIRKET
(NAME, DATE, LOCATION, CEO_ID, WORK_AREA, PHOTO) VALUES (
'SiMiT Lab',
2010,
1,
4,
'Akıllı Etkileşim, Mobil İstihbarat, Multimedya Teknolojileri',
'itulogo.png'
)"""
cursor.execute(query)
query = """INSERT INTO SIRKET
(NAME, DATE, LOCATION, CEO_ID, WORK_AREA, PHOTO) VALUES (
'Siemens AG',
1847,
5,
5,
'Endüstri, Enerji, Sağlık',
'siemens1.png'
)"""
cursor.execute(query)
query = """INSERT INTO SIRKET
(NAME, DATE, LOCATION, CEO_ID, WORK_AREA, PHOTO) VALUES (
'Vestel',
1984,
1,
2,
'Beyaz eşya, Elektrikli ev gereçleri, Otel ürünleri üretimi',
'vestel1.png'
)"""
cursor.execute(query)
query = """INSERT INTO SIRKET
(NAME, DATE, LOCATION, CEO_ID, WORK_AREA, PHOTO) VALUES (
'Ülker Bisküvi Sanayi A.Ş.',
1944,
1,
2,
'İçecek, Çikolata, Bisküvi, Dondurma',
'ülker.png'
)"""
cursor.execute(query)
query = """INSERT INTO SIRKET
(NAME, DATE, LOCATION, CEO_ID, WORK_AREA, PHOTO) VALUES (
'Koç Holding',
1926,
1,
2,
'Beyaz eşya, Otomotiv, Bankacılık, Akaryakıt',
'koc.png'
)"""
cursor.execute(query)
def add_sirket(cursor, request, sirket):
query = """INSERT INTO SIRKET
(NAME, DATE, LOCATION, CEO_ID, WORK_AREA, PHOTO) VALUES (
%s,
%s,
%s,
%s,
%s,
%s
)"""
cursor.execute(query, (sirket.name, sirket.date, sirket.location, sirket.ceo_id, sirket.work_area, sirket.photo))
def delete_sirketler(cursor, id):
query="""DELETE FROM SIRKET WHERE ID = %s"""
cursor.execute(query, id)
def update_sirketler(cursor, id, sirket):
query="""
UPDATE SIRKET
SET NAME=INITCAP(%s),
DATE=%s,
LOCATION=%s,
CEO_ID=%s,
WORK_AREA=%s,
PHOTO=%s
WHERE ID=%s
"""
cursor.execute(query,(sirket.name, sirket.date, sirket.location, sirket.ceo_id, sirket.work_area, sirket.photo, id))