Added list management to admin page
This commit is contained in:
parent
9d7d26c657
commit
614bbebc46
33
shop.py
33
shop.py
@ -110,13 +110,27 @@ def get_items(user_id, list_id=None):
|
||||
|
||||
def get_list_ids(user_id):
|
||||
ret = {}
|
||||
query = "select USER_META.list_id, LISTS.name from USER_META inner join LISTS on LISTS.id = USER_META.list_id where USER_META.user_id = %s"
|
||||
data = (user_id,)
|
||||
res = runQuery(query, data)
|
||||
if user_id == "admin":
|
||||
query = "SELECT id, name from LISTS;"
|
||||
res = runQuery(query)
|
||||
else:
|
||||
query = "select USER_META.list_id, LISTS.name from USER_META inner join LISTS on LISTS.id = USER_META.list_id where USER_META.user_id = %s"
|
||||
data = (user_id,)
|
||||
res = runQuery(query, data)
|
||||
for lid, name in res:
|
||||
ret[lid] = name
|
||||
return ret
|
||||
|
||||
def addList(list_name):
|
||||
query = "insert into LISTS (name) values (%s)"
|
||||
data = (list_name,)
|
||||
runQuery(query, data)
|
||||
|
||||
def addUserToList(userid, listid):
|
||||
query = "insert into USER_META (user_id, list_id) values (%s, %s)"
|
||||
data = (userid, listid)
|
||||
runQuery(query, data)
|
||||
|
||||
application = Flask(__name__)
|
||||
application.config["DEBUG"] = True
|
||||
application.secret_key = b'*$#@U9423jr92jioJKL_)_;dasfj()12'
|
||||
@ -140,6 +154,7 @@ def index():
|
||||
|
||||
@application.route('/post', methods=['POST'])
|
||||
def handle_data():
|
||||
print(request.form)
|
||||
if "addValue" in request.form:
|
||||
for x in request.form:
|
||||
if request.form[x] == '':
|
||||
@ -186,6 +201,15 @@ def handle_data():
|
||||
|
||||
if "list" in request.form:
|
||||
session["active_id"] = request.form['list']
|
||||
|
||||
if "addList" in request.form:
|
||||
print(request.form["addList"])
|
||||
addList(request.form["addList"])
|
||||
|
||||
if "add2list" in request.form:
|
||||
userid = request.form["add2list"]
|
||||
listid = request.form["listID"]
|
||||
addUserToList(userid, listid)
|
||||
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@ -199,7 +223,8 @@ def admin():
|
||||
|
||||
#get a list of users
|
||||
userList = get_users()
|
||||
data = {"users": userList}
|
||||
lists = get_list_ids("admin")
|
||||
data = {"users": userList, "lists": lists}
|
||||
|
||||
return render_template("admin.html", data=data)
|
||||
|
||||
|
||||
@ -42,6 +42,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<h1 class="text-center">ADD LIST</h1>
|
||||
<form class="addList" action="/post" method="POST">
|
||||
<div class="form-group row">
|
||||
<label for="addlist" class="col-sm-2 col-form-label" >List</label>
|
||||
<div class="col-sm-10">
|
||||
<input type=text class="form-control" id="addlist" type="text" name="addList" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="form-group" style="padding-top: 10px; padding-left: 10px;">
|
||||
<input class="btn btn-secondary" id="addlist" type="submit" name="newlist" value="Add new list" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div id="logout" style="padding-top: 3px;">
|
||||
<a href="/">
|
||||
<button onclick="window.location='admin'" class="btn btn-secondary"><i style="padding-top: 3px;"
|
||||
@ -50,6 +64,34 @@
|
||||
</i></button></a>
|
||||
</div>
|
||||
</div>
|
||||
<h1 class="text-center">Add User To List</h1>
|
||||
<div class="container">
|
||||
<table class="table table-striped table-dark table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Username</th>
|
||||
<th scope="col">User</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for x in data["lists"] %}
|
||||
<tr scope="row">
|
||||
<td>{{data["lists"][x]}}</td>
|
||||
<td><form action="/post" method="POST">
|
||||
<select id="addbox" name="add2list" class="custom-select custom-select-lg mb-3">
|
||||
{% for userid in data["users"] %}
|
||||
<option type="submit" value="{{userid[2]}}" id="addbox" name="User2list">{{userid[0].title()}}</option>
|
||||
{% endfor %}
|
||||
</select> <button class="btn btn-secondary" type="submit" value="x"> Add User To List </button>
|
||||
<input name="listID" value={{x}} type="hidden"></form></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% for x in data["lists"] %}
|
||||
{{data["lists"][x]}}
|
||||
{% endfor %}
|
||||
<!-- jQuery library -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<!-- Popper JS -->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user