You are on page 1of 4

import eel

from .user_info import user,dp_info


#data appending metode
def append_data(category,id):
#insert data received from database into the frontend
cursor=db_info['cursor']
cursor.execute("USE restaurant_app")
sql=f"SELECT*FROM food_items WHERE category='{category}'"
cursor.execute(sql)
data=cursor.fetchall()
ihtml=""

#Unpacking the received data

for i in data:
fid = i[0]
src = i[6]
title = i[1]
descrip=i[5]
price = i[3]
rat=""
for i in range (i[4]):
rat+='?'
html = f'''<div class="row section white content-img">
<div class="">
<div class="col s12 m6 14">
<div class="img-cover">
<img class="food-img z-depth-4"
src="{src}">
</div>
</div>
<div class="col s12 m6 18">
<div class="data-cover">
<h3 class="palanquin food-title
black-text">(title)</h3>
<h6 clas="grey-text food-text
kalam"><b>{descrip}</b></h6>
<h4 class="price black-text aclonica">Rs.
{price}</h4>
<h5 class="food-rat">
{rat}
</h5>
<button id='{fid}'
onclick="add_cart (this.id)" data-target="modal3" class="btn-large
orange waves-effect waves-light center modal-trigger"><i
class="material-icons right">add</i> Add to Cart</button>
</div>
</div>
</div>
</div>'''
ihtml += html
eel.f(id, ihtml)
# Creating orders page
def append_orders():
cursor=db_info['cursor']
cursor execute("USE restaurant_app")
# Checking if user is logged in or not.
if user ['user_logged_in'] == True:
ihtml = ""
#Checking if user has any present orders.
if user['user_orders' == [];
ihtml = '''
<h5 class="container red-text Autour-One center">Your cart is empty!! <br> Please
add your favourite
items. </h5>
'''
eel.f("order-content", ihtml)
else:

# Unpacking the received data.


for i in user['user_orders']:
food_name"=i[2]
order_id = i[0]
if "'" in food_name:
sql = f'SELECT * FROM food_items WHERE
food_name="{food_name}"'
else:
sql = f"SELECT * FROM food_items WHERE
food_name'{food_name}'"

cursor.execute (sql)
res=cursor.fetchall()
for j in res:
food_img = j[6]
food_desc =j[5]
food_price =j[3]
rat=""
for i in range (j[4]):
rat+='*'
ihtml+= f'''
<div class="row section white content-img">
<div class="">
<div class="col s12 m4 14">
<img class="food-img z-depth-4"
src="{food_img}">
</div>
<div class="col s12 m8 18">
<h3 class="palanquin food-title
black-text">{food_name}</h3>
<h6 class="grey-text food-text
kalam">{food_desc}</h6>
<h4 class="price black-text
aclonica">Rs.food_price}</h4>

<h5 class="food-rat">

{rat}
</h5>

<button id='{order_id}'
onclick="remove_cart (this.id)" data-target="modal3" class="btn-large orange waves-
effect waves-light
center modal-trigger"><i class="material-icons right">close</i>Remove from
Cart</button>
</div>
</div>
</div>
'''
eel.f("order-content", ihtml)
#Error message if user is not logged in.
else

ihtml='''

<h5 class="container red-text Autour-One center">You


have not logged in yet!!.. Please login at the profile tab to continue purchasing
your favourite food</h5>
eel.f("order-content",ihtml)
#Creating profile page
def append_profile(logged_in):
#Checking if user is logged in
if logged in==True:
# Inserting the profile data of user into frontend
ihtml = f'''
<div class="pro-cover center z-depth-3">
<h2 class="header center orange-text
Autour-One">Your Profile</h2>
<br><br>
<i class="large material-icons" style="font-size: 300px !
important;">account_circle</i>
<br><br>
<h5 class="category Autour-One
orange-text">Username: <i
class="black-text">{user['user_name']}</i></h5>
<h5 class="category Autour-One
orange-text">Firstname: <i
class="black-text">{user 'firstname']}</i></h5>
<h5 class="category Autour-One
orange-text">Lastname: <i
class="black-text">{user 'lastname']}</i></h5>
<h5 class="category Autour-One
orange-text">email: <i
class="black-text">{user 'email']}</i></h5>
<h5 class="category Autour-One
orange-text">Phone Number: <i
class="black-text">{user 'phnum']}</i></h5>
<h5 class="category Autour-One
orange-text">Location: <i
class="black-text">{user 'location']}</i></h5>
<br>
<button data-target="modal4" class="btn-large orange waves-effect waves-light
center modal-trigger">Change
Password</button>
<br>
<div id="change-pass-mess" class="error">
</div>
</div>
'''
eel.f("profile",ihtml)
else:
#Inserting options for login and register into frontend
ihtml = '''
<div id="login" class="pro-cover center z-depth-3">
<h4><i>You have not logged in yet!!.. Please log
in to make ordersand view your profile.</i></h4><br>
<h6 class="grey-text"><i>If you are don't have a Paradiso del Cibo account, then
please register
yourself!!..</i></h6>
<br><br>
<button data-target="modall" class="btn-large
orange waves-effect waves-light center modal-trigger">Login</button> <button data-
target="modal2"
class="btn-large orange waves-effect waves-light center
modal-trigger">Register</button>
<div id="log-reg-error" class="error">
</div>
</div>
'''
eel.f("profile",ihtml)

You might also like