def send_signup_email(self, email, password, firstName, lastName, role, phone_number, host_site): roles = {1:"Site Admin", 2:"GFB Admin", 3:"Host Site Coordinator", 4:"Client"} db = DB() if (role == "3"): pickupSiteName = db.getHostSite(host_site)['name'] roleTitle = roles.get(int(role)) # to_send = 'curl -s --user \'api:key-5bc79fc3330ac42bf29e1b2f89bb1209\' \\\ # https://api.mailgun.net/v2/sandboxf445b5fad6f649ffa60875af1df80dee.mailgun.org/messages \\\ # -F from=\'Garden Fresh Box <*****@*****.**>\' \\\ # -F to=\'' + firstName +'<' + email +'>\'\\\ # -F subject=\'Welcome ' + firstName +'!\' \\\ # -F text=\'Welcome to Garden Fresh Box ' + firstName +'! \n\nYou just joined the Garden Fresh Box program! Thank you for your patronage, please email the sysadmin at [email protected] if you have any questions or concerns about anything on this site. Here are your personal details which may be edited by logging into the Garden Fresh Box site \n\n\ # ' + firstName +' ' + lastName + '\n\ # Email: ' + email +'\n \ # Password: '******'\n \ # Role: ' + roleTitle +'\n \ # Phone Number: ' + phone_number +'\n ' # # if (role == "3"): # to_send = to_send + '\tThe host site you administer: ' + pickupSiteName # # to_send = to_send + '\'' # os.system(to_send) return
def dist(self): db = DB() if (request.method == "GET"): hostSite = db.getHostSiteByName(request.params['hostSiteName']) orderList = db.getAllOrdersByHostSite(hostSite.get('id'), request.params['sortid']) return Sale.toDistList(orderList, request.params['hostSiteName'])
def toTable(users): db = DB() roles = {1:"Site Admin", 2:"GFB Admin", 3:"Host Site Coordinator", 4:"Client"} tableStr = "<div class=\"input-group\" style=\"padding-top: 0;margin-bottom: 5px; margin-top: 0; padding-left: 0\"><span class=\"input-group-addon\">Filter</span><input id=\"filterbox\" type=\"text\" class=\"form-control\" placeholder=\"Type here to filter the table (by sites, dates, names, etc.)\"></div>" tableStr += "<table class=\"table table-hover\" id=\"usersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>First Name</th><th>Last Name</th><th>Phone</th><th>Email</th><th>Host Site</th><th>Role</th></tr></thread><tbody class=\"searchable\">" #This for loop loops through the list of dictionaries and selects certain values to add to the table for user in users: hostsite_name = "None"; if (user.get('fk_credentials') == 1 or user.get('fk_credentials') == 2): hostsite_name = "All" if (user.get('fk_hostsite_id') != None): hsInfo = db.getHostSite(user.get('fk_hostsite_id')) if (hsInfo != None): hostsite_name = hsInfo['name'] tableStr += "<tr id=\"" + str(user.get('id')) + "\" style=\"cursor:pointer;\">" tableStr += "<td>" + str(user.get('first_name')) +"</td>" tableStr += "<td>" + str(user.get('last_name')) +"</td>" tableStr += "<td>" + str(user.get('phone_number')) +"</td>" tableStr += "<td>" + str(user.get('email')) + "</td>" tableStr += "<td>" + hostsite_name + "</td>" tableStr += "<td>" + str(roles.get(user.get('fk_credentials'),'')) + "</td>" tableStr += "<td><button id=\"delete_" + str(user.get('id')) + "\" type=\"button\" class=\"btn btn-danger\" onclick=\"deleteClicked(event);\">Delete</button></td></tr>" tableStr += "</tbody></table>" return tableStr
def usersales(self): db = DB() if (request.method == "GET"): user = db.getUser(request.params['email']) orderList = db.sortOrdersModel(user['id'], request.params['sortid']) return Sale.toUserSaleList(orderList)
def send_signup_email(self, email, password, firstName, lastName, role, phone_number, host_site): roles = { 1: "Site Admin", 2: "GFB Admin", 3: "Host Site Coordinator", 4: "Client" } db = DB() if (role == "3"): pickupSiteName = db.getHostSite(host_site)['name'] roleTitle = roles.get(int(role)) # to_send = 'curl -s --user \'api:key-5bc79fc3330ac42bf29e1b2f89bb1209\' \\\ # https://api.mailgun.net/v2/sandboxf445b5fad6f649ffa60875af1df80dee.mailgun.org/messages \\\ # -F from=\'Garden Fresh Box <*****@*****.**>\' \\\ # -F to=\'' + firstName +'<' + email +'>\'\\\ # -F subject=\'Welcome ' + firstName +'!\' \\\ # -F text=\'Welcome to Garden Fresh Box ' + firstName +'! \n\nYou just joined the Garden Fresh Box program! Thank you for your patronage, please email the sysadmin at [email protected] if you have any questions or concerns about anything on this site. Here are your personal details which may be edited by logging into the Garden Fresh Box site \n\n\ # ' + firstName +' ' + lastName + '\n\ # Email: ' + email +'\n \ # Password: '******'\n \ # Role: ' + roleTitle +'\n \ # Phone Number: ' + phone_number +'\n ' # # if (role == "3"): # to_send = to_send + '\tThe host site you administer: ' + pickupSiteName # # to_send = to_send + '\'' # os.system(to_send) return
def changepassword(self): db = DB() if (request.method == "PUT"): # Check if user's email and password are matched success = db.changePassword(request.params['email'], request.params['oldPassword'], request.params['newPassword']) if(success): return self.trueString else: return "{\"success\" : \"false\", \"message\" : \"Unable to login: bad username or password\"}" else: return "{\"success\" : \"false\", \"message\" : \"Bad request.\"}"
def changepassword(self): db = DB() if (request.method == "PUT"): # Check if user's email and password are matched success = db.changePassword(request.params['email'], request.params['oldPassword'], request.params['newPassword']) if (success): return self.trueString else: return "{\"success\" : \"false\", \"message\" : \"Unable to login: bad username or password\"}" else: return "{\"success\" : \"false\", \"message\" : \"Bad request.\"}"
def donors(self): cookie = request.cookies.get("GFB_Cookie") if cookie == None: response.status_int = 404 return else: creds = Cookie.decryptCookie(cookie) if creds.get("role") == "1" or creds.get("role") == "2": db = DB() donorList = db.getDonationOrders() return Sale.toTableDonations(donorList) else: response.status_int = 404 return
def customers(self): cookie = request.cookies.get("GFB_Cookie") if (cookie == None): response.status_int = 404 return else: creds = Cookie.decryptCookie(cookie) if (creds.get('role') == '2') or (creds.get('role') == '1'): db = DB() customerList = db.getAllCustomers() return Sale.toTableMasterCustomerList(customerList) else: response.status_int = 404 return
def customers(self): cookie = request.cookies.get("GFB_Cookie") if cookie == None: response.status_int = 404 return else: creds = Cookie.decryptCookie(cookie) if (creds.get("role") == "2") or (creds.get("role") == "1"): db = DB() customerList = db.getAllCustomers() return Sale.toTableMasterCustomerList(customerList) else: response.status_int = 404 return
def donors(self): cookie = request.cookies.get("GFB_Cookie") if (cookie == None): response.status_int = 404 return else: creds = Cookie.decryptCookie(cookie) if (creds.get('role') == '1' or creds.get('role') == '2'): db = DB() donorList = db.getDonationOrders() return Sale.toTableDonations(donorList) else: response.status_int = 404 return
def toCashSaleList(orders, hostSiteName): tableStr = "<table class=\"table\" id=\"usersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>Pickup Site</th><th>Pickup Date</th><th>Customer</th><th>Phone</th><th>Email</th><th>No. Small</th><th>No. Large</th><th>Paid</th><th>Donation</th><th>Ordered On</th></tr></thread><tbody>" #calls to database is made to get the name of the hostsite db = DB() hostSite = db.getHostSiteByName(hostSiteName) #This for loop loops through the list of dictionaries and selects certain values to add to the table for order in orders: if str(order.get('hostsitecreated_idFK', '')) != str( hostSite.get('id')): continue tableStr += "<tr id=\"" + str(order.get('id')) + "\">" tableStr += "<td>" + hostSiteName + "</td>" tableStr += "<td>" + str(order.get('distribution_date')) + "</td>" tableStr += "<td>" + str( order.get('customer_first_name')) + " " + str( order.get('customer_last_name')) + "</td>" tableStr += "<td>" + str(order.get('customer_phone')) + "</td>" tableStr += "<td>" + str(order.get('customer_email')) if str(order.get('email_notifications')) == "1": tableStr += " (Notifications)</td>" else: tableStr += "</td>" tableStr += "<td>" + str(order.get('small_quantity')) + "</td>" tableStr += "<td>" + str(order.get('large_quantity')) + "</td>" tableStr += "<td>" + str(order.get('total_paid')) + "</td>" cost = 20.0 * float(order.get('large_quantity', 0)) + 15.0 * float( order.get('small_quantity', 0)) owe = cost - float(order.get('total_paid', 0.00)) tableStr += "<td>" + str(order.get('donation')) if str(order.get('donation_receipt')) == "1": tableStr += " (Reciept)</td>" else: tableStr += "</td>" tableStr += "<td>" + str(order.get('creation_date')) + "</td>" tableStr += "</td></tr>" tableStr += "</tbody></table>" return tableStr
def send_confirmation_email(self, dateCreated, dateToDistribute, firstName, lastName, email, phoneNumber, smallBoxQuantity, largeBoxQuantity, donations, totalPaid, hostSitePickupID, hostSiteOrderID): if (smallBoxQuantity == "" and largeBoxQuantity == ""): to_send = 'curl -s --user \'api:key-5bc79fc3330ac42bf29e1b2f89bb1209\' \\\ https://api.mailgun.net/v2/sandboxf445b5fad6f649ffa60875af1df80dee.mailgun.org/messages \\\ -F from=\'Garden Fresh Box <*****@*****.**>\' \\\ -F to=\'' + firstName + '<' + email + '>\'\\\ -F subject=\'Donation by ' + firstName + '\' \\\ -F text=\'Thank you ' + firstName + '!\n\nYou just made a donation to the Garden Fresh Box program and we really appreciate it! Please email the sysadmin at [email protected] if you have any questions or concerns about this order Here are some of the details:\n\n \ Date: ' + dateCreated + '\n \ ' + firstName + ' ' + lastName + '\n \ Donation amount: $' + donations + '\n \'' else: db = DB() pickupSiteName = db.getHostSite(hostSitePickupID)['name'] totalCost = 0 if (smallBoxQuantity != "" and int(smallBoxQuantity) > 0): totalCost += int(smallBoxQuantity) * 15 if (largeBoxQuantity != "" and int(largeBoxQuantity) > 0): totalCost += int(largeBoxQuantity) * 20 if (totalPaid == ""): totalPaid = 0 else: totalPaid = int(totalPaid) amount_owed = totalCost - totalPaid # to_send = 'curl -s --user \'api:key-5bc79fc3330ac42bf29e1b2f89bb1209\' \\\ # https://api.mailgun.net/v2/sandboxf445b5fad6f649ffa60875af1df80dee.mailgun.org/messages \\\ # -F from=\'Garden Fresh Box <*****@*****.**>\' \\\ # -F to=\'' + firstName +'<' + email +'>\'\\\ # -F subject=\'Order by ' + firstName +'\' \\\ # -F text=\'Thank you ' + firstName +'! \n\nYou just made a purchase on the Garden Fresh Box program! Thank you for your patronage, please email the sysadmin at [email protected] if you have any questions or concerns about this order. Here are the details of the purchase: \n\n\ # Date created: ' + dateCreated +'\n \ # Date of distribution: ' + dateToDistribute +'\n \ # ' + firstName +' ' + lastName + '\n \ # Number of small boxes: ' + smallBoxQuantity +'\n \ # Number of large boxes: ' + largeBoxQuantity +'\n \ # Host site for pickup: ' + pickupSiteName +'\n \ # Total: $' + str(totalCost) +'\n \ # Amount Paid: $' + str(totalPaid) +'\n \ # Amount Owed: $' + str(amount_owed) +'\'' # os.system(to_send) return
def auth(self): db = DB() if (request.method == "GET"): # Check if user's email and password are matched success = db.authUser(request.params['email'], request.params['password']) if(success): # Setup the cookie (encrypted) with useful information user = db.getUser(request.params['email']) cookie = Cookie(user.get('first_name'), user.get('email'), user.get('fk_credentials'), user.get('fk_hostsite_id')) response.set_cookie("GFB_Cookie", cookie.encryptCookie(), max_age=180*24*3600) return self.trueString else: return "{\"success\" : \"false\", \"message\" : \"Unable to login: bad username or password\"}" else: return "{\"success\" : \"false\", \"message\" : \"Bad request.\"}"
def user(self): db = DB() # this method will return either one or all users based on id # if id == * all users are returned if (request.method == "GET"): email = request.params['email'] if email == '*': # users = db.getUsers() # check output # return json.dumps(users) return "returns all users" else: # user = db.getUser(email) # check output # return json.dumps(user) return "returns user with email " + email # this method works for real - just need to figure out host site links to people in the database # should this return the user's ID? elif (request.method == "PUT"): email = request.params['email'] if (db.userExists(email)): # Update user # db.updateUser(request.params['email'], request.params['new_email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number']) return "update user" # unimplemented until db is ready else: # TODO check for errors from database # Add new user user = User(request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number']) db.addUserModel(user) return "{\"success\":\"true\"}" # we might not implement this elif (request.method == "DELETE"): return "{\"success\":\"false\", \"message\":\"Unimplemented method\"}" else: return "{\"success\":\"false\",\"message\":\"Bad request method\"}"
def toCashSaleList(orders, hostSiteName): tableStr = "<table class=\"table\" id=\"usersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>Pickup Site</th><th>Pickup Date</th><th>Customer</th><th>Phone</th><th>Email</th><th>No. Small</th><th>No. Large</th><th>Paid</th><th>Donation</th><th>Ordered On</th></tr></thread><tbody>" #calls to database is made to get the name of the hostsite db = DB() hostSite = db.getHostSiteByName(hostSiteName) #This for loop loops through the list of dictionaries and selects certain values to add to the table for order in orders: if str(order.get('hostsitecreated_idFK','')) != str(hostSite.get('id')): continue; tableStr += "<tr id=\"" + str(order.get('id')) + "\">" tableStr += "<td>" + hostSiteName +"</td>" tableStr += "<td>" + str(order.get('distribution_date')) +"</td>" tableStr += "<td>" + str(order.get('customer_first_name')) + " " + str(order.get('customer_last_name')) +"</td>" tableStr += "<td>" + str(order.get('customer_phone')) +"</td>" tableStr += "<td>" + str(order.get('customer_email')) if str(order.get('email_notifications')) == "1": tableStr += " (Notifications)</td>" else: tableStr += "</td>" tableStr += "<td>" + str(order.get('small_quantity')) +"</td>" tableStr += "<td>" + str(order.get('large_quantity')) +"</td>" tableStr += "<td>" + str(order.get('total_paid')) +"</td>" cost = 20.0 * float(order.get('large_quantity', 0)) + 15.0 * float(order.get('small_quantity', 0)) owe = cost - float(order.get('total_paid', 0.00)) tableStr += "<td>" + str(order.get('donation')) if str(order.get('donation_receipt')) == "1": tableStr += " (Reciept)</td>" else: tableStr += "</td>" tableStr += "<td>" + str(order.get('creation_date')) +"</td>" tableStr += "</td></tr>" tableStr += "</tbody></table>" return tableStr
def toTableMasterOrderList(orders): tableStr = "<div class=\"input-group\" style=\"padding-top: 0;margin-bottom: 5px; margin-top: 0; padding-left: 0\"><span class=\"input-group-addon\">Filter</span><input id=\"filterbox\" type=\"text\" class=\"form-control\" placeholder=\"Type here to filter the table (by sites, dates, names, etc.)\"></div>" tableStr += "<table class=\"table\" id=\"ordersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>Host Site</th><th>Small Boxes</th><th>Large Boxes</th></tr></thread><tbody class=\"searchable\">" #A database object is created db = DB() ''' The first loop is used to scan the list of orders and find all the orders from each hostsite it creates a new dictionary with the total number of boxes in it. ''' ords = {} ids = [] for site in orders: currId = site.get('hostsitepickup_idFK') if currId in ids: ords[currId]['small_quantity'] += int( site.get('small_quantity')) ords[currId]['large_quantity'] += int( site.get('large_quantity')) else: ids.append(currId) ords[currId] = {} ords[currId]['small_quantity'] = int( site.get('small_quantity')) ords[currId]['large_quantity'] = int( site.get('large_quantity')) #This for loop goes through the dictionary and selects values to be added to the table for key in ords.keys(): site = ords.get(key) dic = db.getHostSite(key) if dic == None: continue tableStr += "<tr id=\"" + str(key) + "\">" tableStr += "<td>" + str(dic['name']) + "</td>" tableStr += "<td>" + str(site.get('small_quantity')) + "</td>" tableStr += "<td>" + str(site.get('large_quantity')) + "</td></tr>" tableStr += "</tbody></table>" return tableStr
def toTableMasterOrderList(orders): tableStr = "<div class=\"input-group\" style=\"padding-top: 0;margin-bottom: 5px; margin-top: 0; padding-left: 0\"><span class=\"input-group-addon\">Filter</span><input id=\"filterbox\" type=\"text\" class=\"form-control\" placeholder=\"Type here to filter the table (by sites, dates, names, etc.)\"></div>" tableStr += "<table class=\"table\" id=\"ordersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>Host Site</th><th>Small Boxes</th><th>Large Boxes</th></tr></thread><tbody class=\"searchable\">" #A database object is created db = DB() ''' The first loop is used to scan the list of orders and find all the orders from each hostsite it creates a new dictionary with the total number of boxes in it. ''' ords = {} ids = [] for site in orders: currId = site.get('hostsitepickup_idFK') if currId in ids: ords[currId]['small_quantity'] += int(site.get('small_quantity')) ords[currId]['large_quantity'] += int(site.get('large_quantity')) else: ids.append(currId) ords[currId] = {} ords[currId]['small_quantity'] = int(site.get('small_quantity')) ords[currId]['large_quantity'] = int(site.get('large_quantity')) #This for loop goes through the dictionary and selects values to be added to the table for key in ords.keys(): site = ords.get(key) dic = db.getHostSite(key) if dic == None: continue tableStr += "<tr id=\"" + str(key) + "\">" tableStr += "<td>" + str(dic['name']) +"</td>" tableStr += "<td>" + str(site.get('small_quantity')) +"</td>" tableStr += "<td>" + str(site.get('large_quantity')) +"</td></tr>" tableStr += "</tbody></table>" return tableStr
def auth(self): db = DB() if (request.method == "GET"): # Check if user's email and password are matched success = db.authUser(request.params['email'], request.params['password']) if (success): # Setup the cookie (encrypted) with useful information user = db.getUser(request.params['email']) cookie = Cookie(user.get('first_name'), user.get('email'), user.get('fk_credentials'), user.get('fk_hostsite_id')) response.set_cookie("GFB_Cookie", cookie.encryptCookie(), max_age=180 * 24 * 3600) return self.trueString else: return "{\"success\" : \"false\", \"message\" : \"Unable to login: bad username or password\"}" else: return "{\"success\" : \"false\", \"message\" : \"Bad request.\"}"
def host_site(self): db = DB() # Get request - if hostSiteId is *, all host sites are returned, else only the host site matching given hostSiteID if (request.method == "GET"): hostSiteID = request.params['hostSiteID'] if hostSiteID == '*': hs = db.getAllHostSites(request.params['sortid']) return HostSite.toTable( hs, request.params['staticTable'] == "true") else: hs = db.getHostSite(hostSiteID) return json.dumps(hs) # Put request - if hostSiteID is empty string, a new host site is added, else the host with with hostSiteID is updated elif (request.method == "PUT"): hostSiteID = request.params['hostSiteID'] if (request.params['hostSiteID'] != "" and request.params['name'] == ""): # Delete existing host site success = db.removeHostSite(hostSiteID) if success: return self.trueStr else: return "{\"success\":\"false\", \"message\":\"Unable to delete new host site\"}" elif (hostSiteID == ""): # New host site hs = HostSite(request.params['name'], request.params['address'], request.params['city'], request.params['province'], request.params['postalCode'], request.params['hoursOfOperation'], request.params['phone'], request.params['email']) success = db.addHostSiteModel(hs) if success: return self.trueStr else: return "{\"success\":\"false\", \"message\":\"Unable to add new host site\"}" else: # Update existing host site hs = HostSite(request.params['name'], request.params['address'], request.params['city'], request.params['province'], request.params['postalCode'], request.params['hoursOfOperation'], request.params['phone'], request.params['email']) hs.id = hostSiteID success = db.updateHostSiteModel(hs) if success: return self.trueStr else: return "{\"success\":\"false\", \"message\":\"Unable to update host site\"}" # Delete request - not supported elif (request.method == "DELETE"): return "{\"success\":\"false\", \"message\":\"Unimplemented\"}"
def samples(self): db = DB() if request.method == "GET": if request.params["id"] == "*": smallitems, largeitems = db.getSampleBoxItems() return Sale.toTableSampleBoxes(smallitems, largeitems, request.params["staticTable"]) else: date = db.getSampleItem(request.params["id"]) return json.dumps(date) elif request.method == "PUT": # Edit Date if request.params["id"] != "" and request.params["item"] != "" and request.params["is_small_box"] != "": success = db.updateSampleItem( request.params["id"], request.params["item"], request.params["is_small_box"] ) if success: return self.trueString else: return '{"success":"false","message":"Failed to enter new order."}' elif request.params["id"] == "" and request.params["item"] != "" and request.params["is_small_box"] != "": # New Date success = db.addNewSampleItem(request.params["item"], request.params["is_small_box"]) if success: return self.trueString else: return '{"success":"false","message":"Failed to new item."}' # Delete Date else: success = db.deleteSampleItem(request.params["id"]) if success: return self.trueString else: return '{"success":"false","message":"Failed to delete item."}'
def user(self): db = DB() # this method will return either one or all users based on id # if id == * all users are returned if (request.method == "GET"): email = request.params['email'] if email == '*': # users = db.getUsers() # check output # return json.dumps(users) return "returns all users" else: # user = db.getUser(email) # check output # return json.dumps(user) return "returns user with email " + email # this method works for real - just need to figure out host site links to people in the database # should this return the user's ID? elif (request.method == "PUT"): email = request.params['email'] if(db.userExists(email)): # Update user # db.updateUser(request.params['email'], request.params['new_email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number']) return "update user" # unimplemented until db is ready else: # TODO check for errors from database # Add new user user = User(request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number']) db.addUserModel(user) return "{\"success\":\"true\"}" # we might not implement this elif (request.method == "DELETE"): return "{\"success\":\"false\", \"message\":\"Unimplemented method\"}" else: return "{\"success\":\"false\",\"message\":\"Bad request method\"}"
def toTable(users): db = DB() roles = { 1: "Site Admin", 2: "GFB Admin", 3: "Host Site Coordinator", 4: "Client" } tableStr = "<div class=\"input-group\" style=\"padding-top: 0;margin-bottom: 5px; margin-top: 0; padding-left: 0\"><span class=\"input-group-addon\">Filter</span><input id=\"filterbox\" type=\"text\" class=\"form-control\" placeholder=\"Type here to filter the table (by sites, dates, names, etc.)\"></div>" tableStr += "<table class=\"table table-hover\" id=\"usersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>First Name</th><th>Last Name</th><th>Phone</th><th>Email</th><th>Host Site</th><th>Role</th></tr></thread><tbody class=\"searchable\">" #This for loop loops through the list of dictionaries and selects certain values to add to the table for user in users: hostsite_name = "None" if (user.get('fk_credentials') == 1 or user.get('fk_credentials') == 2): hostsite_name = "All" if (user.get('fk_hostsite_id') != None): hsInfo = db.getHostSite(user.get('fk_hostsite_id')) if (hsInfo != None): hostsite_name = hsInfo['name'] tableStr += "<tr id=\"" + str( user.get('id')) + "\" style=\"cursor:pointer;\">" tableStr += "<td>" + str(user.get('first_name')) + "</td>" tableStr += "<td>" + str(user.get('last_name')) + "</td>" tableStr += "<td>" + str(user.get('phone_number')) + "</td>" tableStr += "<td>" + str(user.get('email')) + "</td>" tableStr += "<td>" + hostsite_name + "</td>" tableStr += "<td>" + str(roles.get(user.get('fk_credentials'), '')) + "</td>" tableStr += "<td><button id=\"delete_" + str( user.get('id') ) + "\" type=\"button\" class=\"btn btn-danger\" onclick=\"deleteClicked(event);\">Delete</button></td></tr>" tableStr += "</tbody></table>" return tableStr
def user(self): db = DB() # for all users send email : * # otherwise user with email will be returned if (request.method == "GET"): email = request.params['email'] if email == '*': users = db.getUsers(request.params['sortid']) return User.toTable(users) else: try: user = db.getUser(email) return json.dumps(user) except: return "free" elif (request.method == "PUT"): email = request.params['email'] if(db.userExists(email)): # If the user already exists, update them user = User(request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number'], request.params['host_site']) success = db.updateUserModel(user, request.params['new_email']) if success: return self.trueString else : return "{\"success\":\"false\", \"message\":\"Unable to update user. Ensure email address is correct.\"}" elif (request.params['email'] != ""): # Add new user user = User(request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number'], request.params['host_site']) success = db.addUserModel(user) if success: self.send_signup_email(request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number'], request.params['host_site']) return self.trueString else: return "{\"success\":\"false\", \"message\":\"Unable to add user.\"}" else: # Delete request success = db.removeUser(request.params['id']) if success: return "{\"success\":\"true\", \"message\":\"Deleted new host site\"}" else: return "{\"success\":\"fasle\", \"message\":\"Unable to add new host site\"}" elif (request.method == "DELETE"): return "{\"success\":\"false\", \"message\":\"Unimplemented method\"}" else: return "{\"success\":\"false\",\"message\":\"Bad request method\"}"
def host_site(self): db = DB() # Get request - if hostSiteId is *, all host sites are returned, else only the host site matching given hostSiteID if (request.method == "GET"): hostSiteID = request.params['hostSiteID'] if hostSiteID == '*': hs = db.getAllHostSites(request.params['sortid']) return HostSite.toTable(hs, request.params['staticTable'] == "true") else: hs = db.getHostSite(hostSiteID) return json.dumps(hs) # Put request - if hostSiteID is empty string, a new host site is added, else the host with with hostSiteID is updated elif (request.method == "PUT"): hostSiteID = request.params['hostSiteID'] if (request.params['hostSiteID'] != "" and request.params['name'] == ""): # Delete existing host site success = db.removeHostSite(hostSiteID) if success: return self.trueStr else: return "{\"success\":\"false\", \"message\":\"Unable to delete new host site\"}" elif(hostSiteID == ""): # New host site hs = HostSite(request.params['name'], request.params['address'], request.params['city'], request.params['province'], request.params['postalCode'], request.params['hoursOfOperation'], request.params['phone'], request.params['email']) success = db.addHostSiteModel(hs) if success: return self.trueStr else: return "{\"success\":\"false\", \"message\":\"Unable to add new host site\"}" else: # Update existing host site hs = HostSite(request.params['name'], request.params['address'], request.params['city'], request.params['province'], request.params['postalCode'], request.params['hoursOfOperation'], request.params['phone'], request.params['email']) hs.id = hostSiteID success = db.updateHostSiteModel(hs) if success: return self.trueStr else: return "{\"success\":\"false\", \"message\":\"Unable to update host site\"}" # Delete request - not supported elif (request.method == "DELETE"): return "{\"success\":\"false\", \"message\":\"Unimplemented\"}"
def dates(self): db = DB() if request.method == "GET": if request.params["dateID"] == "*": dates = db.getAllPickupDates() return Sale.toTableDates(dates, request.params["staticTable"]) else: date = db.getDate(request.params["dateID"]) return json.dumps(date) elif request.method == "PUT": # Edit Date if ( request.params["dateID"] != "" and request.params["orderDate"] != "" and request.params["pickupDate"] != "" ): success = db.updateDate( request.params["dateID"], request.params["pickupDate"], request.params["orderDate"] ) if success: return self.trueString else: return '{"success":"false","message":"Failed to enter new order."}' elif ( request.params["dateID"] == "" and request.params["orderDate"] != "" and request.params["pickupDate"] != "" ): # New Date success = db.addNewDate(request.params["pickupDate"], request.params["orderDate"]) if success: return self.trueString else: return '{"success":"false","message":"Failed to enter new order."}' # Delete Date else: success = db.deleteDate(request.params["dateID"]) if success: return self.trueString else: return '{"success":"false","message":"Failed to enter new order."}'
def dates(self): db = DB() if (request.method == "GET"): if (request.params['dateID'] == '*'): dates = db.getAllPickupDates() return Sale.toTableDates(dates, request.params['staticTable']) else: date = db.getDate(request.params['dateID']) return json.dumps(date) elif (request.method == "PUT"): #Edit Date if (request.params['dateID'] != '' and request.params['orderDate'] != '' and request.params['pickupDate'] != ''): success = db.updateDate(request.params['dateID'], request.params['pickupDate'], request.params['orderDate']) if success: return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to enter new order.\"}" elif (request.params['dateID'] == '' and request.params['orderDate'] != '' and request.params['pickupDate'] != ''): #New Date success = db.addNewDate(request.params['pickupDate'], request.params['orderDate']) if success: return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to enter new order.\"}" #Delete Date else: success = db.deleteDate(request.params['dateID']) if success: return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to enter new order.\"}"
def samples(self): db = DB() if (request.method == "GET"): if (request.params['id'] == '*'): smallitems, largeitems = db.getSampleBoxItems() return Sale.toTableSampleBoxes(smallitems, largeitems, request.params['staticTable']) else: date = db.getSampleItem(request.params['id']) return json.dumps(date) elif (request.method == "PUT"): #Edit Date if (request.params['id'] != '' and request.params['item'] != '' and request.params['is_small_box'] != ''): success = db.updateSampleItem(request.params['id'], request.params['item'], request.params['is_small_box']) if success: return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to enter new order.\"}" elif (request.params['id'] == '' and request.params['item'] != '' and request.params['is_small_box'] != ''): #New Date success = db.addNewSampleItem(request.params['item'], request.params['is_small_box']) if success: return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to new item.\"}" #Delete Date else: success = db.deleteSampleItem(request.params['id']) if success: return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to delete item.\"}"
def sales(self): db = DB() # for all sales (regardless of host site) send hostSiteName : * if request.method == "GET": if request.params["hostSiteName"] == "*": orderList = db.getAllOrders() return Sale.toTableMasterOrderList(orderList) elif request.params["hostSiteName"] != "" and request.params["orderID"] == "": orderList = db.getAllOrders() return Sale.toCashSaleList(orderList, request.params["hostSiteName"]) else: order = db.getOrdersByOrderID(request.params["orderID"]) return json.dumps(order) # uses orderID as a key, if it is sent as "" a new order is added # updating orders was not implemented elif request.method == "PUT": if request.params["orderID"] == "": # if (self.validate_new_order_inputs(request.params)): order = Sale( None, request.params["dateCreated"], request.params["dateToDistribute"], request.params["firstName"], request.params["lastName"], request.params["email"], request.params["phoneNumber"], request.params["shouldSendNotifications"], request.params["smallBoxQuantity"], request.params["largeBoxQuantity"], request.params["donations"], request.params["donationReceipt"], request.params["totalPaid"], request.params["hostSitePickupID"], request.params["hostSiteOrderID"], request.params["customerID"], ) success = db.createNewOrderModel(order) if success: self.send_confirmation_email( request.params["dateCreated"], request.params["dateToDistribute"], request.params["firstName"], request.params["lastName"], request.params["email"], request.params["phoneNumber"], request.params["smallBoxQuantity"], request.params["largeBoxQuantity"], request.params["donations"], request.params["totalPaid"], request.params["hostSitePickupID"], request.params["hostSiteOrderID"], ) return self.trueString else: return '{"success":"false","message":"Failed to enter new order."}' # else: # return "{\"success\":\"false\",\"message\":\"Please fix inputs.\"}" else: if request.params["smallBoxQuantity"] == "" and request.params["largeBoxQuantity"] == "": # Delete success = db.deleteOrder(request.params["orderID"]) if success: self.send_confirmation_email( request.params["dateCreated"], request.params["dateToDistribute"], request.params["firstName"], request.params["lastName"], request.params["email"], request.params["phoneNumber"], request.params["smallBoxQuantity"], request.params["largeBoxQuantity"], request.params["donations"], request.params["totalPaid"], request.params["hostSitePickupID"], request.params["hostSiteOrderID"], ) return self.trueString else: return '{"success":"false","message":"Failed to enter new order."}' else: # Edit order = Sale( request.params["orderID"], request.params["dateCreated"], request.params["dateToDistribute"], request.params["firstName"], request.params["lastName"], request.params["email"], request.params["phoneNumber"], request.params["shouldSendNotifications"], request.params["smallBoxQuantity"], request.params["largeBoxQuantity"], request.params["donations"], request.params["donationReceipt"], request.params["totalPaid"], request.params["hostSitePickupID"], request.params["hostSiteOrderID"], request.params["customerID"], ) success = db.createEditOrderModel(order) if success: self.send_confirmation_email( request.params["dateCreated"], request.params["dateToDistribute"], request.params["firstName"], request.params["lastName"], request.params["email"], request.params["phoneNumber"], request.params["smallBoxQuantity"], request.params["largeBoxQuantity"], request.params["donations"], request.params["totalPaid"], request.params["hostSitePickupID"], request.params["hostSiteOrderID"], ) return self.trueString else: return '{"success":"false","message":"Failed to enter new order."}'
def hsJSON(self): db = DB() if (request.method == "GET"): return json.dumps(db.getAllHostSites("Name"))
def datesJSON(self): db = DB() if request.method == "GET": return json.dumps(db.getAllPickupDates())
def __init__(self, orderId, creationDate, distributionDate, customerFirstName, customerLastName, customerEmail, customerPhone, emailNotifications, smallQuantity, largeQuantity, donation, donationReceipt, totalPaid, hostsitepickupIdFK, hostsitecreatedIdFK, customerID): values = [None, ''] #basic error checking is done. If a parameter is an empty string or None it is set to a default vaule if orderId in values: self.orderId = None else: self.orderId = orderId if distributionDate in values: self.distributionDate = None else: # mm/dd/yyyy parts = distributionDate.split('-') d = datetime.date(int(parts[0]), int(parts[1]), int(parts[2])) self.distributionDate = d if creationDate in values: self.creationDate = None else: # mm/dd/yyyy parts = creationDate.split('-') d = datetime.date(int(parts[0]), int(parts[1]), int(parts[2])) self.creationDate = d if customerFirstName in values: self.customerFirstName = None else: self.customerFirstName = customerFirstName if customerLastName in values: self.customerLastName = None else: self.customerLastName = customerLastName if customerEmail in values: self.customerEmail = '' else: self.customerEmail = customerEmail if customerPhone in values: self.customerPhone = '' else: self.customerPhone = customerPhone if emailNotifications in values: self.emailNotifications = 0 else: self.emailNotifications = emailNotifications if smallQuantity in values: self.smallQuantity = 0 else: self.smallQuantity = smallQuantity if largeQuantity in values: self.largeQuantity = 0 else: self.largeQuantity = largeQuantity if donation in values: self.donation = 0 else: self.donation = donation if donationReceipt in values: self.donationReceipt = 0 else: self.donationReceipt = donationReceipt if totalPaid in values: self.totalPaid = 0 else: self.totalPaid = totalPaid if customerID in values: self.customerID = None else: self.customerID = customerID if hostsitepickupIdFK in values: self.hostsitepickupIdFK = None else: self.hostsitepickupIdFK = hostsitepickupIdFK if hostsitecreatedIdFK in values: self.hostsitecreatedIdFK = None elif hostsitecreatedIdFK == "-99": # this order was placed online db = DB() hostSite = db.getHostSiteByName("Online") self.hostsitecreatedIdFK = hostSite.get('id') else: self.hostsitecreatedIdFK = hostsitecreatedIdFK self.dict = {}
def dist(self): db = DB() if request.method == "GET": hostSite = db.getHostSiteByName(request.params["hostSiteName"]) orderList = db.getAllOrdersByHostSite(hostSite.get("id"), request.params["sortid"]) return Sale.toDistList(orderList, request.params["hostSiteName"])
def toUserSaleList(orders): tableStr = "<div class=\"input-group\" style=\"padding-top: 0;margin-bottom: 5px; margin-top: 0; padding-left: 0\"><span class=\"input-group-addon\">Filter</span><input id=\"filterbox\" type=\"text\" class=\"form-control\" placeholder=\"Type here to filter the table (by sites, dates, names, etc.)\"></div>" tableStr += "<table class=\"table table-hover\" id=\"ordersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>Pickup Site</th><th>Pickup Date</th><th>Customer</th><th>Phone</th><th>Email</th><th>No. Small</th><th>No. Large</th><th>Paid</th><th>Ordered On</th></tr></thread><tbody class=\"searchable\">" #calls to database is made to get the name of the hostsite db = DB() #This for loop loops through the list of dictionaries and selects certain values to add to the table for order in orders: is_not_overdue = False d_date = datetime.datetime.strptime( order.get('distribution_date'), '%Y-%m-%d') - datetime.timedelta(days=12) current_date = datetime.datetime.today() if (current_date < d_date): is_not_overdue = True ordered_from_name = "None" if (order.get('hostsitepickup_idFK') != None): hsInfo = db.getHostSite(order.get('hostsitepickup_idFK')) if (hsInfo != None): ordered_from_name = hsInfo['name'] tableStr += "<tr id=\"" + str(order.get('id')) + "\">" tableStr += "<td>" + ordered_from_name + "</td>" tableStr += "<td>" + str(order.get('distribution_date')) + "</td>" tableStr += "<td>" + str( order.get('customer_first_name')) + " " + str( order.get('customer_last_name')) + "</td>" tableStr += "<td>" + str(order.get('customer_phone')) + "</td>" tableStr += "<td>" + str(order.get('customer_email')) if str(order.get('email_notifications')) == "1": tableStr += " (Notifications)</td>" else: tableStr += "</td>" tableStr += "<td>" + str(order.get('small_quantity')) + "</td>" tableStr += "<td>" + str(order.get('large_quantity')) + "</td>" if float(order.get('total_paid')) > 0.0: isPaid = "Paid" buttonType = "success" else: isPaid = "Unpaid" if (is_not_overdue): buttonType = "primary" else: buttonType = "warning" tableStr += "<td><button id=\"paid_" + str( order.get('id') ) + "\" type=\"button\" class=\"label label-" + buttonType + "\">" + isPaid + "</td>" cost = 20.0 * float(order.get('large_quantity', 0)) + 15.0 * float( order.get('small_quantity', 0)) owe = cost - float(order.get('total_paid', 0.00)) tableStr += "<td>" + str(order.get('creation_date')) + "</td>" if (is_not_overdue and order.get('total_paid') == "0.00"): tableStr += "<td><button id=\"delete_" + str( order.get('id') ) + "\" type=\"button\" class=\"btn btn-danger\" onclick=\"deleteClicked(event);\">Delete</button></td>" tableStr += "</tr>" tableStr += "</tbody></table>" return tableStr
def send_confirmation_email( self, dateCreated, dateToDistribute, firstName, lastName, email, phoneNumber, smallBoxQuantity, largeBoxQuantity, donations, totalPaid, hostSitePickupID, hostSiteOrderID, ): if smallBoxQuantity == "" and largeBoxQuantity == "": to_send = ( "curl -s --user 'api:key-5bc79fc3330ac42bf29e1b2f89bb1209' \\\ https://api.mailgun.net/v2/sandboxf445b5fad6f649ffa60875af1df80dee.mailgun.org/messages \\\ -F from='Garden Fresh Box <*****@*****.**>' \\\ -F to='" + firstName + "<" + email + ">'\\\ -F subject='Donation by " + firstName + "' \\\ -F text='Thank you " + firstName + "!\n\nYou just made a donation to the Garden Fresh Box program and we really appreciate it! Please email the sysadmin at [email protected] if you have any questions or concerns about this order Here are some of the details:\n\n \ Date: " + dateCreated + "\n \ " + firstName + " " + lastName + "\n \ Donation amount: $" + donations + "\n '" ) else: db = DB() pickupSiteName = db.getHostSite(hostSitePickupID)["name"] totalCost = 0 if smallBoxQuantity != "" and int(smallBoxQuantity) > 0: totalCost += int(smallBoxQuantity) * 15 if largeBoxQuantity != "" and int(largeBoxQuantity) > 0: totalCost += int(largeBoxQuantity) * 20 if totalPaid == "": totalPaid = 0 else: totalPaid = int(totalPaid) amount_owed = totalCost - totalPaid # to_send = 'curl -s --user \'api:key-5bc79fc3330ac42bf29e1b2f89bb1209\' \\\ # https://api.mailgun.net/v2/sandboxf445b5fad6f649ffa60875af1df80dee.mailgun.org/messages \\\ # -F from=\'Garden Fresh Box <*****@*****.**>\' \\\ # -F to=\'' + firstName +'<' + email +'>\'\\\ # -F subject=\'Order by ' + firstName +'\' \\\ # -F text=\'Thank you ' + firstName +'! \n\nYou just made a purchase on the Garden Fresh Box program! Thank you for your patronage, please email the sysadmin at [email protected] if you have any questions or concerns about this order. Here are the details of the purchase: \n\n\ # Date created: ' + dateCreated +'\n \ # Date of distribution: ' + dateToDistribute +'\n \ # ' + firstName +' ' + lastName + '\n \ # Number of small boxes: ' + smallBoxQuantity +'\n \ # Number of large boxes: ' + largeBoxQuantity +'\n \ # Host site for pickup: ' + pickupSiteName +'\n \ # Total: $' + str(totalCost) +'\n \ # Amount Paid: $' + str(totalPaid) +'\n \ # Amount Owed: $' + str(amount_owed) +'\'' # os.system(to_send) return
def toUserSaleList(orders): tableStr = "<div class=\"input-group\" style=\"padding-top: 0;margin-bottom: 5px; margin-top: 0; padding-left: 0\"><span class=\"input-group-addon\">Filter</span><input id=\"filterbox\" type=\"text\" class=\"form-control\" placeholder=\"Type here to filter the table (by sites, dates, names, etc.)\"></div>" tableStr += "<table class=\"table table-hover\" id=\"ordersTable\" style=\"background-color:white;cursor: pointer; cursor: hand; \"><thread><tr id=\"info\"><th>Pickup Site</th><th>Pickup Date</th><th>Customer</th><th>Phone</th><th>Email</th><th>No. Small</th><th>No. Large</th><th>Paid</th><th>Ordered On</th></tr></thread><tbody class=\"searchable\">" #calls to database is made to get the name of the hostsite db = DB() #This for loop loops through the list of dictionaries and selects certain values to add to the table for order in orders: is_not_overdue = False d_date = datetime.datetime.strptime(order.get('distribution_date'), '%Y-%m-%d') - datetime.timedelta(days=12) current_date = datetime.datetime.today() if (current_date < d_date): is_not_overdue = True ordered_from_name = "None"; if (order.get('hostsitepickup_idFK') != None): hsInfo = db.getHostSite(order.get('hostsitepickup_idFK')) if (hsInfo != None): ordered_from_name = hsInfo['name'] tableStr += "<tr id=\"" + str(order.get('id')) + "\">" tableStr += "<td>" + ordered_from_name +"</td>" tableStr += "<td>" + str(order.get('distribution_date')) +"</td>" tableStr += "<td>" + str(order.get('customer_first_name')) + " " + str(order.get('customer_last_name')) +"</td>" tableStr += "<td>" + str(order.get('customer_phone')) +"</td>" tableStr += "<td>" + str(order.get('customer_email')) if str(order.get('email_notifications')) == "1": tableStr += " (Notifications)</td>" else: tableStr += "</td>" tableStr += "<td>" + str(order.get('small_quantity')) +"</td>" tableStr += "<td>" + str(order.get('large_quantity')) +"</td>" if float(order.get('total_paid')) > 0.0: isPaid = "Paid" buttonType = "success" else: isPaid = "Unpaid" if (is_not_overdue): buttonType = "primary" else: buttonType = "warning" tableStr += "<td><button id=\"paid_" + str(order.get('id')) + "\" type=\"button\" class=\"label label-"+ buttonType + "\">" + isPaid +"</td>" cost = 20.0 * float(order.get('large_quantity', 0)) + 15.0 * float(order.get('small_quantity', 0)) owe = cost - float(order.get('total_paid', 0.00)) tableStr += "<td>" + str(order.get('creation_date')) +"</td>" if (is_not_overdue and order.get('total_paid') == "0.00"): tableStr += "<td><button id=\"delete_" + str(order.get('id')) + "\" type=\"button\" class=\"btn btn-danger\" onclick=\"deleteClicked(event);\">Delete</button></td>" tableStr += "</tr>" tableStr += "</tbody></table>" return tableStr
def sales(self): db = DB() # for all sales (regardless of host site) send hostSiteName : * if (request.method == "GET"): if request.params['hostSiteName'] == "*": orderList = db.getAllOrders() return Sale.toTableMasterOrderList(orderList) elif (request.params['hostSiteName'] != "" and request.params['orderID'] == ""): orderList = db.getAllOrders() return Sale.toCashSaleList(orderList, request.params['hostSiteName']) else: order = db.getOrdersByOrderID(request.params['orderID']) return json.dumps(order) # uses orderID as a key, if it is sent as "" a new order is added # updating orders was not implemented elif (request.method == "PUT"): if request.params['orderID'] == "": # if (self.validate_new_order_inputs(request.params)): order = Sale( None, request.params['dateCreated'], request.params['dateToDistribute'], request.params['firstName'], request.params['lastName'], request.params['email'], request.params['phoneNumber'], request.params['shouldSendNotifications'], request.params['smallBoxQuantity'], request.params['largeBoxQuantity'], request.params['donations'], request.params['donationReceipt'], request.params['totalPaid'], request.params['hostSitePickupID'], request.params['hostSiteOrderID'], request.params['customerID']) success = db.createNewOrderModel(order) if success: self.send_confirmation_email( request.params['dateCreated'], request.params['dateToDistribute'], request.params['firstName'], request.params['lastName'], request.params['email'], request.params['phoneNumber'], request.params['smallBoxQuantity'], request.params['largeBoxQuantity'], request.params['donations'], request.params['totalPaid'], request.params['hostSitePickupID'], request.params['hostSiteOrderID']) return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to enter new order.\"}" # else: # return "{\"success\":\"false\",\"message\":\"Please fix inputs.\"}" else: if (request.params['smallBoxQuantity'] == "" and request.params['largeBoxQuantity'] == ""): # Delete success = db.deleteOrder(request.params['orderID']) if success: self.send_confirmation_email( request.params['dateCreated'], request.params['dateToDistribute'], request.params['firstName'], request.params['lastName'], request.params['email'], request.params['phoneNumber'], request.params['smallBoxQuantity'], request.params['largeBoxQuantity'], request.params['donations'], request.params['totalPaid'], request.params['hostSitePickupID'], request.params['hostSiteOrderID']) return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to enter new order.\"}" else: # Edit order = Sale(request.params['orderID'], request.params['dateCreated'], request.params['dateToDistribute'], request.params['firstName'], request.params['lastName'], request.params['email'], request.params['phoneNumber'], request.params['shouldSendNotifications'], request.params['smallBoxQuantity'], request.params['largeBoxQuantity'], request.params['donations'], request.params['donationReceipt'], request.params['totalPaid'], request.params['hostSitePickupID'], request.params['hostSiteOrderID'], request.params['customerID']) success = db.createEditOrderModel(order) if success: self.send_confirmation_email( request.params['dateCreated'], request.params['dateToDistribute'], request.params['firstName'], request.params['lastName'], request.params['email'], request.params['phoneNumber'], request.params['smallBoxQuantity'], request.params['largeBoxQuantity'], request.params['donations'], request.params['totalPaid'], request.params['hostSitePickupID'], request.params['hostSiteOrderID']) return self.trueString else: return "{\"success\":\"false\",\"message\":\"Failed to enter new order.\"}"
def userdonations(self): db = DB() if (request.method == "GET"): user = db.getUser(request.params['email']) orderList = db.getDonationsByUserID(user['id']) return Sale.toUserDonationList(orderList)
def __init__(self, orderId, creationDate, distributionDate, customerFirstName, customerLastName, customerEmail, customerPhone, emailNotifications, smallQuantity, largeQuantity, donation, donationReceipt, totalPaid, hostsitepickupIdFK, hostsitecreatedIdFK, customerID): values = [None,''] #basic error checking is done. If a parameter is an empty string or None it is set to a default vaule if orderId in values: self.orderId = None else: self.orderId = orderId if distributionDate in values: self.distributionDate = None else: # mm/dd/yyyy parts = distributionDate.split('-') d = datetime.date(int(parts[0]),int(parts[1]),int(parts[2])) self.distributionDate = d if creationDate in values: self.creationDate = None else: # mm/dd/yyyy parts = creationDate.split('-') d = datetime.date(int(parts[0]),int(parts[1]),int(parts[2])) self.creationDate = d if customerFirstName in values: self.customerFirstName = None else: self.customerFirstName = customerFirstName if customerLastName in values: self.customerLastName = None else: self.customerLastName = customerLastName if customerEmail in values: self.customerEmail = '' else: self.customerEmail = customerEmail if customerPhone in values: self.customerPhone = '' else: self.customerPhone = customerPhone if emailNotifications in values: self.emailNotifications = 0 else: self.emailNotifications = emailNotifications if smallQuantity in values: self.smallQuantity = 0 else: self.smallQuantity = smallQuantity if largeQuantity in values: self.largeQuantity = 0 else: self.largeQuantity = largeQuantity if donation in values: self.donation = 0 else: self.donation = donation if donationReceipt in values: self.donationReceipt = 0 else: self.donationReceipt = donationReceipt if totalPaid in values: self.totalPaid = 0 else: self.totalPaid = totalPaid if customerID in values: self.customerID = None else: self.customerID = customerID if hostsitepickupIdFK in values: self.hostsitepickupIdFK = None else: self.hostsitepickupIdFK = hostsitepickupIdFK if hostsitecreatedIdFK in values: self.hostsitecreatedIdFK = None elif hostsitecreatedIdFK == "-99": # this order was placed online db = DB() hostSite = db.getHostSiteByName("Online") self.hostsitecreatedIdFK = hostSite.get('id') else: self.hostsitecreatedIdFK = hostsitecreatedIdFK self.dict = {}
def user(self): db = DB() # for all users send email : * # otherwise user with email will be returned if (request.method == "GET"): email = request.params['email'] if email == '*': users = db.getUsers(request.params['sortid']) return User.toTable(users) else: try: user = db.getUser(email) return json.dumps(user) except: return "free" elif (request.method == "PUT"): email = request.params['email'] if (db.userExists(email)): # If the user already exists, update them user = User( request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number'], request.params['host_site']) success = db.updateUserModel(user, request.params['new_email']) if success: return self.trueString else: return "{\"success\":\"false\", \"message\":\"Unable to update user. Ensure email address is correct.\"}" elif (request.params['email'] != ""): # Add new user user = User( request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number'], request.params['host_site']) success = db.addUserModel(user) if success: self.send_signup_email(request.params['email'], request.params['password'], request.params['first_name'], request.params['last_name'], request.params['role'], request.params['phone_number'], request.params['host_site']) return self.trueString else: return "{\"success\":\"false\", \"message\":\"Unable to add user.\"}" else: # Delete request success = db.removeUser(request.params['id']) if success: return "{\"success\":\"true\", \"message\":\"Deleted new host site\"}" else: return "{\"success\":\"fasle\", \"message\":\"Unable to add new host site\"}" elif (request.method == "DELETE"): return "{\"success\":\"false\", \"message\":\"Unimplemented method\"}" else: return "{\"success\":\"false\",\"message\":\"Bad request method\"}"
def usersales(self): db = DB() if request.method == "GET": user = db.getUser(request.params["email"]) orderList = db.sortOrdersModel(user["id"], request.params["sortid"]) return Sale.toUserSaleList(orderList)
def datesJSON(self): db = DB() if (request.method == "GET"): return json.dumps(db.getAllPickupDates())
def userdonations(self): db = DB() if request.method == "GET": user = db.getUser(request.params["email"]) orderList = db.getDonationsByUserID(user["id"]) return Sale.toUserDonationList(orderList)