-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
86 lines (71 loc) · 1.99 KB
/
views.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
# -*- coding: utf-8 -*-
import sqlite3
class HeaderClass:
def __str__(self):
print "Content-type:text/html\r\n\r\n"
with open("header.html", 'r') as fin:
return fin.read()
class FooterClass:
def __str__(self):
with open("footer.html", 'r') as fin:
return fin.read()
# A bit of expriment class to mess with...
class WelcomeClass:
def __init__(self, arg_file):
self.var_file = arg_file
def set_file(self, arg_file):
self.var_file = arg_file
def __str__(self):
with open(self.var_file, 'r') as fin:
return fin.read()
class FormClass:
def __str__(self):
with open("form.html", 'r') as fin:
return fin.read()
class EditFormClass:
def __str__(self):
with open("editform.html", 'r') as fin:
return fin.read()
class CountClass:
def __str__(self):
conn = sqlite3.connect('addressbook.db')
c = conn.cursor()
c.execute("SELECT Count(*) FROM addressbook")
rows = c.fetchall()
conn.commit()
conn.close()
return str(rows[0][0])
class NotesClass:
def __str__(self):
conn = sqlite3.connect('addressbook.db')
c = conn.cursor()
c.execute("SELECT * FROM notes")
rows = c.fetchall()
conn.commit()
conn.close()
# return "hello"
def print_view_test(rows):
print """\
<form action="index.cgi?action=update&id={3}" method="POST">
Name:<br>
<input type="text" name="name" value="{0}">
<br>
Surname:<br>
<input type="text" name="surname" value="{1}">
<br><br>
Email:<br>
<input type="text" name="email" value="{2}">
<br><br>
<input type="submit" value="Submit">
</form>
""".format(rows[0][1], rows[0][2], rows[0][3], rows[0][0])
def add_note_form(arg_var):
print """\
<form action='index.cgi?action=add_note_row&id={0}' method="POST">
Note:<br>
<input type="text" name="note" value="">
<br>
<br><br>
<input type="submit" value="Submit">
</form>
""".format(arg_var)