-
Notifications
You must be signed in to change notification settings - Fork 0
/
tablemodel
268 lines (229 loc) · 10.5 KB
/
tablemodel
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<!-- EXTEND (base.html), homesite/base.html is template for all rendered pages in the project -->
{% extends "homesite/base.html" %}
<!-- STYLE (in <head>), style enhancements for page -->
{% block style %}
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
margin-left: auto;
margin-right: auto;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
{% endblock %}
<!-- SCRIPT (in <head>), script enhancements for page -->
{% block script %}
<script>
<!-- Password verification and error message -->
function verifyPassword() {
const psw = document.getElementById("password").value;
if (psw.length < 6 || psw.length > 20) {
document.getElementById("pswError").innerHTML = "Password must be between 6 and 20 characters";
return false;
}
}
</script>
{% endblock %}
<!-- CONTENT (in <body>), content for this page -->
{% block content %}
<!-- Links to code for Front End and Backend for this lesson; Also, link to Login example -->
<div class="jumbotron jumbotron-fluid" style="height: 50%; ">
<div class="row justify-content-center">
<div class="col-10" style="text-align: center;">
<h1>Hello to Databases and Python</h1>
<table id="links">
<tr>
<td><a href=#FE-HTML>HTML Code</a></td>
<td><a href=#BE-VIEW>View Code</a></td>
<td><a href=#BE-MODELDEFINE>Model Define</a></td>
<td><a href=#BE-MODELCRUD>Model CRUD</a></td>
<td><a href={{url_for('.login')}}>Authorise User</a></td>
</tr>
</table>
</div>
</div>
</div>
<!-- Sample table rendering and filtering link -->
<div class="jumbotron jumbotron-fluid" style="height: 50%; ">
<!-- title -->
<div class="row justify-content-center">
<div class="col-10" style="text-align: center;">
<h1>Login Information</h1>
</div>
</div>
<!-- backend filtering actions -->
<div class="row courses-buttons justify-content-center">
<table id="links">
<tr>
<td><a href={{url_for('.databases')}}>Full Table </a></td>
<td><a href={{url_for('.emails')}}>E-Mails only</a></td>
<td><a href={{url_for('.phones')}}>Phones only</a></td>
</tr>
</table>
</div>
<!-- Table display, "table" variable and rows with "dictionary elements" are expected -->
<table>
<tr>
<th>Number</th>
<th>Username</th>
<th>Password</th>
<th>Emails</th>
<th>Phone Numbers</th>
</tr>
<!-- Loop through rows in table -->
{% for row in table %}
<!--
Prepare table for display
caution: phone number needs "~" format step to force type to string
-->
{% set pn = "" ~ row['phone_numbers'] %}
{% set pnf = "(" ~ pn[0:3] ~ ")" ~ pn[3:6] ~ "-" ~ pn[6:10] %}
<tr>
<th>{{ row['id'] }}</th>
<th>{{ row['name'] }}</th>
<th>{{ row['password'] }}</th>
<th>{{ row['emails'] }}</th>
<th>{{ pnf }}</th>
</tr>
{% endfor %}
</table>
</div>
<!-- Create action, input and "Add" a new row to table -->
<div class="jumbotron jumbotron-fluid" style="height: 50%; ">
<div class="row justify-content-center">
<div class="col-10" style="text-align: center;">
<h1>CRUD: Create</h1>
</div>
</div>
<div class="row courses-buttons justify-content-center">
<form method="POST" ID="create" onsubmit ="return verifyPassword()" action={{url_for('.create')}} >
<table>
<tr>
<th><label for="username">Name</label></th>
<th><label for="password">Password</label></th>
<th><label for="email">Email</label></th>
<th><label for="phone_number">Phone Number</label></th>
</tr>
<tr>
<th><input type="text" name="username" id="username" required></th>
<th><input type="password" name="password" id="password" required></th>
<th><input type="email" name="email" id="email" placeholder="[email protected]"></th>
<th><input type="tel" name="phone_number" id="phone_number" pattern="[0-9]{10}" placeholder="1234567890"></th>
<th><input type="submit" value="Add"></th>
</tr>
</table>
<p id="pswError"></p>
</form>
</div>
</div>
<!-- Read action, filter table on page to single row -->
<div class="jumbotron jumbotron-fluid" style="height: 50%; ">
<div class="row justify-content-center">
<div class="col-10" style="text-align: center;">
<h1>CRUD: Read</h1>
</div>
</div>
<div class="row courses-buttons justify-content-center">
<form method="POST" ID="read" action={{url_for('.read')}} >
<table id="links">
<tr><th><label for="ID">ID</label></th></tr>
<tr><td><select name="ID" id="ID">
<optgroup label="userid">
{% for row in table %}
<option label="{{ row['id'] }}">{{ row['id'] }}</option>
{% endfor %}
</optgroup>
</select></td>
<td><input type="submit" value="Filter"></td>
</tr>
</table>
</form>
</div>
</div>
<!-- Update action, change selected rows email and phone number -->
<div class="jumbotron jumbotron-fluid" style="height: 50%; ">
<div class="row justify-content-center">
<div class="col-10" style="text-align: center;">
<h1>CRUD: Update</h1>
</div>
</div>
<div class="row courses-buttons justify-content-center">
<form method="POST" ID="update" action={{url_for('.update')}} >
<table id="links">
<tr>
<th><label for="ID">ID</label></th>
<th><label for="email">Email</label></th>
<th><label for="phone_number">Phone Number</label></th>
</tr>
<tr>
<td>
<select name="ID" id="ID">
<optgroup label="userid">
{% for row in table %}
<option label="{{ row['id'] }}">{{ row['id'] }}</option>
{% endfor %}
</optgroup>
</select>
</td>
<th><input type="email" name="email" id="email" placeholder="[email protected]"></th>
<th><input type="tel" name="phone_number" id="phone_number" pattern="[0-9]{10}" placeholder="1234567890"></th>
<th><input type="submit" value="Update"></th>
</tr>
</table>
</form>
</div>
</div>
<!-- Delete action, delete selected row from table -->
<div class="jumbotron jumbotron-fluid" style="height: 50%; ">
<div class="row justify-content-center">
<div class="col-10" style="text-align: center;">
<h1>CRUD: Delete</h1>
</div>
</div>
<div class="row courses-buttons justify-content-center">
<form method="POST" ID="delete" action={{url_for('.delete')}} >
<table id="links">
<tr><th><label for="ID">ID</label></th></tr>
<tr><td><select name="ID" id="ID">
<optgroup label="userid">
{% for row in table %}
<option label="{{ row['id'] }}">{{ row['id'] }}</option>
{% endfor %}
</optgroup>
</select>
</td><td><input type="submit" value="Delete"></td></tr>
</table>
</form>
</div>
</div>
<!-- Display CRUD code to support Tech Talks -->
<!-- Front End HTML, shows this file -->
<div align="center" >
<h1 id="FE-HTML">Front End HTML Code</h1>
<script src="https://emgithub.com/embed.js?target=https%3A%2F%2Fgithub.com%2Fnighthawkcoders%2Fflask-idea-homesite%2Fblob%2Fmaster%2Fviews%2Fpythondb%2Ftemplates%2Fpythondb%2Findex.html&style=github&showBorder=on&showLineNumbers=on&showFileMeta=on"></script>
</div>
<!-- Back end View and Control code -->
<div align="center" >
<h1 id="BE-VIEW">Back End View Code</h1>
<script src="https://emgithub.com/embed.js?target=https%3A%2F%2Fgithub.com%2Fnighthawkcoders%2Fflask-idea-homesite%2Fblob%2Fmaster%2Fviews%2Fpythondb%2Fview.py&style=github&showBorder=on&showLineNumbers=on&showFileMeta=on"></script>
</div>
<!-- Back end SQL data definition code (SQLalchemy) -->
<div align="center" >
<h1 id="BE-MODELDEFINE">Back End Model Definition Code</h1>
<script src="https://emgithub.com/embed.js?target=https%3A%2F%2Fgithub.com%2Fnighthawkcoders%2Fflask-idea-homesite%2Fblob%2Fmaster%2Fmodels%2F__init__.py&style=github&showBorder=on&showLineNumbers=on&showFileMeta=on"></script>
</div>
<!-- Back end SQL CRUD supporting code -->
<div align="center" >
<h1 id="BE-MODELCRUD">Back End Model CRUD Code</h1>
<script src="https://emgithub.com/embed.js?target=https%3A%2F%2Fgithub.com%2Fnighthawkcoders%2Fflask-idea-homesite%2Fblob%2Fmaster%2Fmodels%2Fcrud.py&style=github&showBorder=on&showLineNumbers=on&showFileMeta=on"></script>
</div>
{% endblock %}