Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 72ae7c3835 | |||
| aa2911d969 | |||
| 62dcad7946 | |||
| 8df55ad17a | |||
| 508f309223 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
venv/
|
venv/
|
||||||
.idea/
|
.idea/
|
||||||
.pytest_cache
|
.pytest_cache
|
||||||
*_pycache_*
|
*_pycache_*
|
||||||
|
*.db
|
||||||
@@ -6,4 +6,4 @@ COPY . /app
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN pip3 install -r requirements.txt
|
RUN pip3 install -r requirements.txt
|
||||||
ENTRYPOINT ["python3"]
|
ENTRYPOINT ["python3"]
|
||||||
CMD ["app.py"]
|
CMD ["web/app.py"]
|
||||||
|
|||||||
1
README.md
Normal file
1
README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This project is to allow homebrew club members to be given an identifying number/letter to put on their bottles for competitions.
|
||||||
@@ -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
|
||||||
@@ -16,9 +18,11 @@ pluggy==0.12.0
|
|||||||
py==1.8.0
|
py==1.8.0
|
||||||
pyparsing==2.4.0
|
pyparsing==2.4.0
|
||||||
pytest==5.0.0
|
pytest==5.0.0
|
||||||
|
pytest-env==0.6.2
|
||||||
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
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from web import app
|
from web import app
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client():
|
||||||
app.app.config['TESTING'] = True
|
app.app.config['TESTING'] = True
|
||||||
@@ -12,4 +11,15 @@ def client():
|
|||||||
def test_root_page(client):
|
def test_root_page(client):
|
||||||
|
|
||||||
rv = client.get('/')
|
rv = client.get('/')
|
||||||
assert b'Hello World!' in rv.data
|
assert rv.status_code == 200
|
||||||
|
assert b'Please enter your first name and initial' in rv.data
|
||||||
|
|
||||||
|
def test_generate_first(client):
|
||||||
|
rv2 = client.post('/generate', data=dict(name='tester'), follow_redirects=True)
|
||||||
|
assert rv2.status_code == 200
|
||||||
|
assert b'Please mark all of your bottlecaps with the following identifier: <strong>A' in rv2.data
|
||||||
|
|
||||||
|
def test_generate_second(client):
|
||||||
|
rv = client.post('/generate', data=dict(name='tester'), follow_redirects=True)
|
||||||
|
assert rv.status_code == 200
|
||||||
|
assert b'Please mark all of your bottlecaps with the following identifier: <strong>B' in rv.data
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
ignore::DeprecationWarning
|
ignore::DeprecationWarning
|
||||||
|
env =
|
||||||
|
HBC_DB_PATH=tests
|
||||||
10
user_experience.md
Normal file
10
user_experience.md
Normal 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
|
||||||
|
|
||||||
56
web/app.py
56
web/app.py
@@ -1,11 +1,63 @@
|
|||||||
from flask import Flask
|
from flask import Flask, render_template, request
|
||||||
|
from flask_bootstrap import Bootstrap
|
||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
import string
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
Bootstrap(app)
|
||||||
|
|
||||||
|
|
||||||
|
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__':
|
||||||
|
|||||||
19
web/templates/generate.html
Normal file
19
web/templates/generate.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{% extends "bootstrap/base.html" %}
|
||||||
|
{% block title %}Wigan Homebrew Club Competition Entry{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="jumbotron text-center">
|
||||||
|
<h2>Wigan Homebrew Club Competition Entry</h2>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2"></div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<p><p>You have been entered into the competition to brew a <strong>{{ brew_name }}</strong>, which will be judged at the meeting in <strong>{{ brew_month }}</strong>.</p>
|
||||||
|
<br/>
|
||||||
|
<p class="bg-success lead text-center" style="padding: 10px 10px 10px 10px">Please mark all of your bottlecaps with the following identifier: <strong>{{ identifier }}</strong></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
27
web/templates/index.html
Normal file
27
web/templates/index.html
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{% extends "bootstrap/base.html" %}
|
||||||
|
{% block title %}Wigan Homebrew Club Competition Entry{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="jumbotron text-center">
|
||||||
|
<h2>Wigan Homebrew Club Competition Entry</h2>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-2"></div>
|
||||||
|
<div class="col-md-8">
|
||||||
|
<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>
|
||||||
|
<br/>
|
||||||
|
<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>
|
||||||
|
<hr>
|
||||||
|
<form action="{{ url_for('generate') }}" method="POST">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Please enter your first name and initial (or nickname)</label>
|
||||||
|
<input name="name" type="text" id="name" class="form-control input-lg" placeholder="eg: Sean C">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Enter Competition</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user