#!/usr/bin/python3 from python.webpage_functions import print_html, get_form_data, has_form_data, print_main, get_user, set_cookie from python.htmlGenerators import viewProducts, nav from python.password import Password from python.login import tryLogIn # Either show login page or landing page if not get_user().logged_in: if has_form_data(): # Page loading with incoming form data # Try to log in with the data login_id, password = get_form_data("id"), Password(get_form_data("password")) logInCookie = tryLogIn(login_id, password) if logInCookie: # successful set_cookie(logInCookie) # print the main dashboard print_main(viewProducts.create_table_of_locations()) else: # unsuccessful - print login page with error message print_html('login.html') #### Error message? else: # No data - Print log in page print_html('login.html') else: print_main(viewProducts.create_table_of_locations())
#!/usr/bin/python3 from python.webpage_functions import print_main print_main('updateLocation.html')
return _get_chart('bar', title, column_names, scales, *bar_data) bar_html = get_html_template('chart_template.html') output = get_html_template('pdf_buttons.html').safe_substitute() # Get bar chart for location space usage names, full_space, empty_space = get_how_full_locations_are() used_data = get_chart_data('Space Used', full_space, 'blue') empty_data = get_chart_data('Total Space', empty_space, 'red') output += get_bar_chart('Location Space Usage', names, used_data, empty_data) # Get bar chart for dates food expires at dates, dates_count = count_of_expiring_food() expiring_data = get_chart_data('Amount of Product', dates_count, 'blue') output += get_bar_chart('Product Expiring On', dates, expiring_data) # count_of_expiring_food_to_total_of_that_product names, total, expiring = count_of_expiring_food_to_total_of_that_product() total_data = get_chart_data('Total Product', total, 'blue') expiring_data = get_chart_data('Expiring Product', expiring, 'red') output += get_bar_chart('Number of Products Expiring in 10 days', names, expiring_data, total_data) # pie_chart_showing_distribution_of_products names, values = pie_chart_showing_distribution_of_products() data = get_chart_data('Products', values, colorArray) output += get_pie_chart('Distribution of Product', names, data) print_main(output)
#!/usr/bin/python3 from python.webpage_functions import print_main print_main('remove_product.html')
def show_add_product(): # get_form_data might return None so switch that to '' for printing for k, v in values.items(): if not v: values[k] = '' print_main('add_product.html', values)
from python.databases.databaseQueries import select_all_with_conditions, update_user if get_user().logged_in: if has_form_data(): user_id = get_form_data("users") updated = update_user(int(user_id), "role", "1") userForm = "" users = select_all_with_conditions("users", "role", "0") if len(users) > 0: for row in users: userForm += '<option value="%s">%s %s</option>' % ( row["id"], row["fname"], row["lname"]) else: userForm += '<option value="">None</option>' if get_user().logged_in: if has_form_data(): user_id = get_form_data("users") updated = update_user(int(user_id), "role", "1") if updated: #successful print_main("makeAdmin.html", dict(msg="Successful!", users=userForm)) else: #failed print_main("makeAdmin.html", dict(msg="Unsuccessful, try again", users=userForm)) else: print_main("makeAdmin.html", dict(msg="", users=userForm)) else: print_html('redirect.html', dict(url='/index.py'))
og = values.copy() def show_add_product(): # get_form_data might return None so switch that to '' for printing for k, v in values.items(): if not v: values[k] = '' print_main('add_product.html', values) reason = "No reason" valid = False if has_form_data(): title = get_form_data("title") location = get_form_data("location") description = get_form_data("description") date = get_form_data("date") comments = get_form_data("comments") result, new_id = addProduct(title, description, location, comments=comments, expiry_date=date) og['result'] = date if new_id == -1: new_id = '' print_main('add_product.html', {'result':result, 'id': new_id}) valid = True if not valid: show_add_product()
#!/usr/bin/python3 from python.webpage_functions import print_main from python.user import get_user from python.databases.databaseQueries import select_all_with_conditions # Get the users email address, the key of the database user_email = get_user().email # use this key to search for the users info and get a dictionary of info user_info = select_all_with_conditions("users", "email", user_email)[0] roles = {1: "Admin", 0: "Normal User"} if user_info["image"] is None: if user_info["role"] == 0: user_info["image"] = "/assets/images/default_user.png" elif user_info["role"] == 1: user_info["image"] = "/assets/images/default_manager.png" # Print the html page with users info print_main('profile.html', {"image": user_info["image"], "firstName": user_info["fname"], "secondName": user_info["lname"], "email": user_info["email"], "role": roles[user_info["role"]]})
#!/usr/bin/python3 from python.webpage_functions import print_main from python.databases.databaseQueries import select_all items = select_all("products") items_html = """<section id='header'> <span><b>ID</b></span> <span><b>Title</b></span> <!-- <span><b>Dessscription</b></span> --> </section> """ for i in items: item = """<span>%d</span> <span>%s</span> <!-- <span>%s</span> -->""" % (i['id'], i['title'], i['description']) items_html += """<section class='item' onclick="getInfo(id=%s);"> %s </section>""" % (i['id'], str(item)) print_main('view_product.html', dict(items_html=items_html))
} og = values.copy() def showUsers(): # get_form_data might return None so switch that to '' for printing for k, v in values.items(): if not v: values[k] = '' print_main('addUser.html', values) reason = "No reason" valid = False if has_form_data(): email = get_form_data("email") username = get_form_data("username") fname = get_form_data("fname") lname = get_form_data("lname") password = get_form_data("password") role = get_form_data("role") image = get_form_data("image") result = addUser(email,username,fname,lname,password,role,image) og['result'] = email print_main('addUser.html', {'result':result}) valid = True if not valid: showUsers()
#!/usr/bin/python3 from python.webpage_functions import print_main from python.stockInfo.graphing_functions.graphing_functions import * create_graph_of_product_history() create_graph_of_times_all_locations_have_been_used() create_graph_of_how_full_locations_are() print_main("analytics.html")