Initial commit
This commit is contained in:
commit
cf077fe892
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
env/
|
||||||
|
list.db
|
||||||
87
shop.py
Normal file
87
shop.py
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
from flask import Flask, render_template, make_response, request, redirect, url_for
|
||||||
|
from pprint import pprint
|
||||||
|
import sqlite3
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
DBNAME = "list.db"
|
||||||
|
|
||||||
|
def doesDBExist(DBNAME):
|
||||||
|
try:
|
||||||
|
if not os.path.isfile(DBNAME):
|
||||||
|
conn = sqlite3.connect(DBNAME)
|
||||||
|
conn.cursor().execute('''CREATE TABLE SHOPLIST (item text, cost real, gotten integer, requester text)''')
|
||||||
|
conn.close()
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def readFromDB():
|
||||||
|
conn = sqlite3.connect(DBNAME)
|
||||||
|
results = conn.cursor().execute('''select rowid,* from shoplist''').fetchall()
|
||||||
|
conn.close()
|
||||||
|
return results
|
||||||
|
|
||||||
|
def findByName(name):
|
||||||
|
conn = sqlite3.connect(DBNAME)
|
||||||
|
query = '''select * from shoplist where requester like ''' + name
|
||||||
|
results = conn.cursor().execute(query).findall()
|
||||||
|
conn.close()
|
||||||
|
return results
|
||||||
|
|
||||||
|
def insertToDB(data):
|
||||||
|
query = f"INSERT INTO SHOPLIST VALUES (\"{data['item']}\", 0, 0, \"{data['name']}\")"
|
||||||
|
print(query)
|
||||||
|
conn = sqlite3.connect(DBNAME)
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute(query)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def deleteRow(rowID):
|
||||||
|
query = f"DELETE FROM SHOPLIST WHERE ROWID = {rowID}"
|
||||||
|
conn = sqlite3.connect(DBNAME)
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute(query)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def getItem(rowID):
|
||||||
|
query = f"UPDATE shoplist set gotten = 1 where rowid = {rowID}"
|
||||||
|
conn = sqlite3.connect(DBNAME)
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute(query)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config["DEBUG"] = True
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
query = readFromDB()
|
||||||
|
data = {"title":"Cart", "results":query}
|
||||||
|
return render_template('index.html', data=data)
|
||||||
|
|
||||||
|
@app.route('/post', methods=['POST'])
|
||||||
|
def handle_data():
|
||||||
|
pprint(request.form)
|
||||||
|
if "addValue" in request.form:
|
||||||
|
for x in request.form:
|
||||||
|
# print(x)
|
||||||
|
if request.form[x] == '':
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
insertToDB(request.form)
|
||||||
|
if "rem" in request.form:
|
||||||
|
print(request.form["rem"])
|
||||||
|
deleteRow(request.form["rem"])
|
||||||
|
|
||||||
|
if "got" in request.form:
|
||||||
|
getItem(request.form["got"])
|
||||||
|
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
doesDBExist(DBNAME)
|
||||||
|
app.run(host="0.0.0.0")
|
||||||
9
static/css/index.css
Normal file
9
static/css/index.css
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
aside {
|
||||||
|
width: 20%;
|
||||||
|
padding-left: .5rem;
|
||||||
|
margin-left: .5rem;
|
||||||
|
float: right;
|
||||||
|
box-shadow: inset 5px 0 5px -5px #000000;
|
||||||
|
font-style: italic;
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
59
templates/index.html
Normal file
59
templates/index.html
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>This is my site</title>
|
||||||
|
<!-- Latest compiled and minified CSS -->
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<link rel="stylesheet" href="/static/css/index.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 class="container" style="text-align: center">{{ data["title"] }}</h1>
|
||||||
|
<aside>
|
||||||
|
<form action="/post" method="post">
|
||||||
|
Name:<br>
|
||||||
|
<input type="text" name="name" value=""><br>
|
||||||
|
Item:<br>
|
||||||
|
<input type="text" name="item" value=""><br><br>
|
||||||
|
<input type="submit" name="addValue"value="Submit">
|
||||||
|
</form>
|
||||||
|
</aside>
|
||||||
|
<div class="container" id="memes">
|
||||||
|
<table class="table-striped table">
|
||||||
|
<thead class="thead-dark">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Item</th>
|
||||||
|
<th scope="col">Requester</th>
|
||||||
|
<th scope="col">Gottem?</th>
|
||||||
|
<th scope="col">Remove</th>
|
||||||
|
</tr>
|
||||||
|
{% for x in data["results"] %}
|
||||||
|
<tr id="row-{{x[0]}}">
|
||||||
|
<td>{{x[1]}}</td>
|
||||||
|
<td>{{x[4]}}</td>
|
||||||
|
|
||||||
|
<td> {% if x[3] == 0 %}
|
||||||
|
<form><button type="submit" formaction="/post" formmethod="POST" name="got" value="{{x[0]}}">No</button></form>
|
||||||
|
{% else %}
|
||||||
|
yes
|
||||||
|
{% endif %}</td>
|
||||||
|
<td><form>
|
||||||
|
<button type="submit" formaction="/post" formmethod="POST" name="rem" value="{{x[0]}}">Remove</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- jQuery library -->
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Popper JS -->
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Latest compiled JavaScript -->
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user