-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice.py
75 lines (58 loc) · 2.26 KB
/
practice.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
from flask import Flask #The FLASK framework (the webserver)
from flask import render_template # For opening and read the HTML file and showing them as the webpage
from flask import redirect
from cs50 import SQL
from objects import *
import sqlite3
def getDictList_DB():
con = sqlite3.connect('HandTrucks.db')
cursorObj = con.cursor()
rowSTRING2 = "["
cursorObj.execute('SELECT * FROM Customer;')
rows = cursorObj.fetchall()
for row in rows:
newRow = []
c = Customer(row[0], row[1],row[2],row[3],row[4],row[5],row[6])
rowSTRING2 += "{" + c.getDict() + "},"
rowSTRING2 = rowSTRING2[0:-1]
rowSTRING2 = rowSTRING2 + "]"
# rowSTRING2 = eval(rowSTRING2)
return rowSTRING2
print(getDictList_DB())
def getPDictList_DB():
con = sqlite3.connect('HandTrucks.db')
cursorObj = con.cursor()
rowSTRING2 = "["
cursorObj.execute('SELECT * FROM Product;')
rows = cursorObj.fetchall()
for row in rows:
newRow = []
p = Product(row[0], row[1],row[2],row[3])
rowSTRING2 += "{" + p.getDict() + "},"
rowSTRING2 = rowSTRING2[0:-1]
rowSTRING2 = rowSTRING2 + "]"
rowSTRING2 = eval(rowSTRING2)
return rowSTRING2
print(getPDictList_DB())
@app.route('/<int:id>/edit/', methods=('GET', 'POST'))
def edit(id):
conn = get_db_connection()
todo = conn.execute('SELECT i.id, i.list_id, i.done, i.content, l.title \
FROM items i JOIN lists l \
ON i.list_id = l.id WHERE i.id = ?', (id,)).fetchone()
lists = conn.execute('SELECT title FROM lists;').fetchall()
if request.method == 'POST':
content = request.form['content']
list_title = request.form['list']
if not content:
flash('Content is required!')
return redirect(url_for('edit', id=id))
list_id = conn.execute('SELECT id FROM lists WHERE title = (?);',
(list_title,)).fetchone()['id']
conn.execute('UPDATE items SET content = ?, list_id = ?\
WHERE id = ?',
(content, list_id, id))
conn.commit()
conn.close()
return redirect(url_for('index'))
return render_template('edit.html', todo=todo, lists=lists)