diff --git a/.gitignore b/.gitignore index f1a853d..86bfd85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ venv/ .idea/ .pytest_cache -*_pycache_* \ No newline at end of file +*_pycache_* +*.db \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 69bd613..3c3d0e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,9 @@ certifi==2019.6.16 chardet==3.0.4 Click==7.0 colorama==0.4.1 +dominate==2.3.5 Flask==1.0.3 +Flask-Bootstrap==3.3.7.1 idna==2.8 importlib-metadata==0.18 itsdangerous==1.1.0 @@ -19,6 +21,7 @@ pytest==5.0.0 requests==2.22.0 six==1.12.0 urllib3==1.25.3 +visitor==0.1.3 wcwidth==0.1.7 Werkzeug==0.15.4 zipp==0.5.1 diff --git a/tests/pytest.ini b/tests/pytest.ini index b0e5a94..d7467ff 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -1,3 +1,5 @@ [pytest] filterwarnings = - ignore::DeprecationWarning \ No newline at end of file + ignore::DeprecationWarning +env = + HBC_DB_PATH=tests \ No newline at end of file diff --git a/user_experience.md b/user_experience.md new file mode 100644 index 0000000..3847623 --- /dev/null +++ b/user_experience.md @@ -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 + diff --git a/web/app.py b/web/app.py index c8f34f6..3686b35 100644 --- a/web/app.py +++ b/web/app.py @@ -1,11 +1,61 @@ -from flask import Flask +from flask import Flask, render_template, request +import sqlite3 +import os +import string + 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('/') 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__': diff --git a/web/templates/generate.html b/web/templates/generate.html new file mode 100644 index 0000000..2a4aa95 --- /dev/null +++ b/web/templates/generate.html @@ -0,0 +1,11 @@ + + +
+ +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: {{ identifier }}
+ + \ No newline at end of file diff --git a/web/templates/index.html b/web/templates/index.html new file mode 100644 index 0000000..94a64d8 --- /dev/null +++ b/web/templates/index.html @@ -0,0 +1,17 @@ + + + + +The next competition brew will be a {{ brew_name }}. It will be judged at the meeting in {{ brew_month }}
+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
+ + + \ No newline at end of file