1
0
Fork 0

PC automatically get from current login user

This commit is contained in:
Ethanell 2020-03-06 15:36:56 +01:00
parent d3c7532009
commit 13adbc8197
5 changed files with 9 additions and 10 deletions

View file

@ -137,7 +137,6 @@ class Dessert(db.Model):
class Service(db.Model):
pc_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
sandwich1_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
sandwich2_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
sandwich3_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)

View file

@ -72,7 +72,7 @@ def addcmd(json):
Command.number.desc()).first().number + 1
except AttributeError:
c.number = 1
c.pc_id = current_user.id
c.pc_id = json["pc"]
if all(i in json and json[i] for i in ["firstname", "lastname", "client"]):
db.session.add(User(username=json["client"], firstname=json["firstname"], lastname=json["lastname"]))
if "client" in json:
@ -256,7 +256,7 @@ def lsservice(json=None, broadcast=False):
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
s = {}
if service:
for i in [["pc", service.pc_id], ["sandwich1", service.sandwich1_id], ["sandwich2", service.sandwich2_id],
for i in [["sandwich1", service.sandwich1_id], ["sandwich2", service.sandwich2_id],
["sandwich3", service.sandwich3_id], ["commi1", service.commi1_id], ["commi2", service.commi2_id]]:
s[i[0]] = User.query.get(i[1]).username
emit("list service", s, broadcast=broadcast)
@ -268,13 +268,13 @@ def setservice(json):
service = Service.query.filter_by(date=datetime.datetime.now().date()).first()
if not service:
service = Service()
if all(i in json and json[i] for i in ["pc", "sandwich1", "sandwich2", "sandwich3", "commi1", "commi2"]):
for i in [["pc", "pc_id"], ["sandwich1", "sandwich1_id"], ["sandwich2", "sandwich2_id"],
if all(i in json and json[i] for i in ["sandwich1", "sandwich2", "sandwich3", "commi1", "commi2"]):
for i in [["sandwich1", "sandwich1_id"], ["sandwich2", "sandwich2_id"],
["sandwich3", "sandwich3_id"], ["commi1", "commi1_id"], ["commi2", "commi2_id"]]:
setattr(service, i[1], User.query.filter_by(username=json[i[0]]).first().id)
else:
dummy = User.query.filter_by(username="dummy").first().id
for i in ["pc_id", "sandwich1_id","sandwich2_id", "sandwich3_id", "commi1_id", "commi2_id"]:
for i in ["sandwich1_id","sandwich2_id", "sandwich3_id", "commi1_id", "commi2_id"]:
setattr(service, i[1], dummy)
service.sandwich1 = False
service.sandwich2 = False

View file

@ -295,6 +295,7 @@ document.querySelector(".validation").addEventListener("click", ev => {
}
current["client"] = user.value;
current["pc"] = pc_id;
socket.emit("add command", current);
current = {"plate": null, "ingredient": [], "sauce": [], "drink": null, "dessert": null, "price": {}};
document.querySelectorAll("input[name=plate],input[name=drink],input[name=dessert]").forEach( e => {

View file

@ -9,10 +9,6 @@
<div class="bg-contact2" id="main-container" style="background-image: url({{ url_for('static',filename='images/bg-01.jpg') }});">
<form id="stocks" class="container" action="#">
<div id="equipes">
<div id="equipePC">
<label for="pc">PC :</label>
<input list="user_list" type="text" id="pc">
</div>
<div id="sandwich">
<label for="sandwich1">Sandiwch 1 :</label>
<input list="user_list" type="text" id="sandwich1">

View file

@ -77,6 +77,9 @@
</div>
<!--===============================================================================================-->
<script>
let pc_id = '{{ session.user_id }}';
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
<script src="{{ url_for('static', filename='js/pc.js') }}"></script>
{% endblock %}