Working simple letter assignment without updated tests

This commit is contained in:
2019-07-04 21:51:03 +01:00
parent 8df55ad17a
commit 62dcad7946
7 changed files with 98 additions and 4 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ venv/
.idea/ .idea/
.pytest_cache .pytest_cache
*_pycache_* *_pycache_*
*.db

View File

@@ -4,7 +4,9 @@ certifi==2019.6.16
chardet==3.0.4 chardet==3.0.4
Click==7.0 Click==7.0
colorama==0.4.1 colorama==0.4.1
dominate==2.3.5
Flask==1.0.3 Flask==1.0.3
Flask-Bootstrap==3.3.7.1
idna==2.8 idna==2.8
importlib-metadata==0.18 importlib-metadata==0.18
itsdangerous==1.1.0 itsdangerous==1.1.0
@@ -19,6 +21,7 @@ pytest==5.0.0
requests==2.22.0 requests==2.22.0
six==1.12.0 six==1.12.0
urllib3==1.25.3 urllib3==1.25.3
visitor==0.1.3
wcwidth==0.1.7 wcwidth==0.1.7
Werkzeug==0.15.4 Werkzeug==0.15.4
zipp==0.5.1 zipp==0.5.1

View File

@@ -1,3 +1,5 @@
[pytest] [pytest]
filterwarnings = filterwarnings =
ignore::DeprecationWarning ignore::DeprecationWarning
env =
HBC_DB_PATH=tests

10
user_experience.md Normal file
View File

@@ -0,0 +1,10 @@
# User Goals
* Obtain a letter for their brew
* The letter should be different to everyone elses
* If they forget they should get a new letter
* If we run out of letters hand out numbers instead
# Security Concerns
* Nobody should see what anyone else has
* It would be nice to be able to dump out a list at the end of who's who

View File

@@ -1,11 +1,61 @@
from flask import Flask from flask import Flask, render_template, request
import sqlite3
import os
import string
app = Flask(__name__) app = Flask(__name__)
def get_db_connection():
db_path = os.environ.get('HBC_DB_PATH')
if not db_path:
raise Exception("DB Path not defined")
return sqlite3.connect(db_path + '/hbc.db')
def db_setup():
conn = get_db_connection()
sql_create_table = """ CREATE TABLE IF NOT EXISTS brewers (
id integer PRIMARY KEY,
name text NOT NULL,
identifier text NOT NULL );"""
c = conn.cursor()
c.execute(sql_create_table)
conn.close()
db_setup()
brew_name = "Fruit Beer"
brew_month = "October"
identifiers = list(string.ascii_uppercase) + list(range(1, 100))
def get_identifier(name):
conn = get_db_connection()
c = conn.cursor()
for identifier in identifiers:
c.execute('''SELECT identifier FROM brewers WHERE identifier=?''', (str(identifier),))
data = c.fetchone()
if data is None:
print("Assigning " + identifier + " to " + name)
c.execute("INSERT INTO brewers (name,identifier) VALUES(?, ?)",(name, identifier) )
conn.commit()
conn.close()
return identifier
@app.route('/') @app.route('/')
def hello_world(): def hello_world():
return 'Hello World!' return render_template('index.html', brew_name=brew_name, brew_month=brew_month)
@app.route('/generate', methods=["POST"])
def generate():
identifier = get_identifier(request.form['name'])
return render_template('generate.html', brew_name=brew_name, brew_month=brew_month, identifier=identifier)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wigan Homebrew Club Competition Entry</title>
</head>
<body>
<h1>Wigan Homebrew Club Competition Entry</h1>
<p>You have been entered into the competition to brew a {{ brew_name }}, for {{ brew_month }}. Please mark all of your bottlecaps with the following identifier: <strong>{{ identifier }}</strong></p>
</body>
</html>

17
web/templates/index.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wigan Homebrew Club Competition Entry</title>
</head>
<body>
<h1>Wigan Homebrew Club Competition Entry</h1>
<p>The next competition brew will be a <strong>{{ brew_name }}</strong>. It will be judged at the meeting in <strong>{{ brew_month }}</strong></p>
<p>If you would like to enter the competition, please enter your name below to generate a letter/number that will be used to identify your entry</p>
<form action="{{ url_for('generate') }}" method="POST">
<label for="name">Please enter your name and initial (eg: Sean C):</label>
<input name="name" type="text" id="name"><br>
<button type="submit">Enter Competition</button>
</form>
</body>
</html>