mirror of
https://github.com/tmdinosaurcenter/kiosk-guestbook.git
synced 2025-04-10 14:11:28 -06:00
Split out name to first and last, only displaying First name field and location field.
This commit is contained in:
parent
35563a4d08
commit
e18fd5fffa
18
app.py
18
app.py
@ -10,7 +10,8 @@ def init_db():
|
|||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS guests (
|
CREATE TABLE IF NOT EXISTS guests (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
name TEXT NOT NULL,
|
first_name TEXT NOT NULL,
|
||||||
|
last_name TEXT NOT NULL,
|
||||||
email TEXT NOT NULL,
|
email TEXT NOT NULL,
|
||||||
location TEXT NOT NULL,
|
location TEXT NOT NULL,
|
||||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
@ -22,21 +23,24 @@ def init_db():
|
|||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index():
|
def index():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
name = request.form.get('name')
|
first_name = request.form.get('first_name')
|
||||||
|
last_name = request.form.get('last_name')
|
||||||
email = request.form.get('email')
|
email = request.form.get('email')
|
||||||
location = request.form.get('location')
|
location = request.form.get('location')
|
||||||
if name and email and location:
|
if first_name and last_name and email and location:
|
||||||
conn = sqlite3.connect(DATABASE)
|
conn = sqlite3.connect(DATABASE)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute('INSERT INTO guests (name, email, location) VALUES (?, ?, ?)',
|
c.execute(
|
||||||
(name, email, location))
|
'INSERT INTO guests (first_name, last_name, email, location) VALUES (?, ?, ?, ?)',
|
||||||
|
(first_name, last_name, email, location)
|
||||||
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
# Retrieve guest entries to display on the page.
|
# Retrieve guest entries to display only first name and location.
|
||||||
conn = sqlite3.connect(DATABASE)
|
conn = sqlite3.connect(DATABASE)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute('SELECT name, email, location, timestamp FROM guests ORDER BY id DESC')
|
c.execute('SELECT first_name, location FROM guests ORDER BY id DESC')
|
||||||
guests = c.fetchall()
|
guests = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
return render_template('index.html', guests=guests)
|
return render_template('index.html', guests=guests)
|
||||||
|
@ -9,8 +9,11 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Museum Visitor Guestbook</h1>
|
<h1>Museum Visitor Guestbook</h1>
|
||||||
<form method="post" action="/">
|
<form method="post" action="/">
|
||||||
<label for="name">Name:</label><br>
|
<label for="first_name">First Name(s):</label><br>
|
||||||
<input type="text" id="name" name="name" required><br><br>
|
<input type="text" id="first_name" name="first_name" required><br><br>
|
||||||
|
|
||||||
|
<label for="last_name">Last Name:</label><br>
|
||||||
|
<input type="text" id="last_name" name="last_name" required><br><br>
|
||||||
|
|
||||||
<label for="email">Email:</label><br>
|
<label for="email">Email:</label><br>
|
||||||
<input type="email" id="email" name="email" required><br><br>
|
<input type="email" id="email" name="email" required><br><br>
|
||||||
@ -24,7 +27,7 @@
|
|||||||
<h2>Guest Entries</h2>
|
<h2>Guest Entries</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% for guest in guests %}
|
{% for guest in guests %}
|
||||||
<li><strong>{{ guest[0] }}</strong> from {{ guest[2] }} (<em>{{ guest[1] }}</em>) at {{ guest[3] }}</li>
|
<li><strong>{{ guest[0] }}</strong> from {{ guest[1] }}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user