def new_choice(self, inv, i): # validate that a choice doesnt already exist this this # item uc = UserChoices(item=i, user=self.sos_user) uc.date = inv.date uc.quantity = "0" uc.quantity_int = 0 uc.charge = "0.00" uc.charge_float = 0.0 uc.purchased = 0 uc.id = str(uuid.uuid1()) choice_query = UserChoices.all() choice_query.filter("item = ", i) choice_query.filter("user = "******"The item %s has already been selected by user %s: stack %s" % (i.name, str(self.email), pprint.pformat(traceback.extract_stack())) ) # raise SOSException("The item %s has already been selected" % (i.name)) # could return the found choice here, but i don't think any # should be found so i want to know when this happens return why_exist[0] uc.put() return uc
def new_choice(self, inv, i): # validate that a choice doesnt already exist this this # item uc = UserChoices(item=i, user=self.sos_user) uc.date = inv.date uc.quantity = "0" uc.quantity_int = 0 uc.charge = "0.00" uc.charge_float = 0.0 uc.purchased = 0 uc.id = str(uuid.uuid1()) choice_query = UserChoices.all() choice_query.filter('item = ', i) choice_query.filter('user = '******'t think any # should be found so i want to know when this happens return why_exist[0] uc.put() return uc
def copy_inv(self, items, new_date): for old_item in items: item = Item(id=str(uuid.uuid1())) item.name = old_item.name item.anotation = old_item.anotation item.date = datetime.strptime(new_date, "%Y-%m-%d") item.quantity = old_item.quantity item.remaining = old_item.quantity item.cost = old_item.cost item.put()
def post(self): self.url = "" self.url_linktext = "" try: button_type = self.request.get('button') if button_type == "Register": fn = self.request.get('firstname') ln = self.request.get('lastname') e = self.request.get('email') a = self.request.get('address') c = self.request.get('city') z = self.request.get('zip') p = self.request.get('phone') user = UsersWaitingList2(id=str(uuid.uuid1())) user.email = e user.firstname = fn user.lastname = ln user.address = a user.phone = p user.zip = z user.put() # email to kelly message = mail.EmailMessage( sender="*****@*****.**", subject="A new user has registered") message.body = "%s %s\n%s\n%s\n%s\n%s %s\n%s" % (fn, ln, e, p, a, c, z, p) message.to = "*****@*****.**" message.cc = "*****@*****.**" message.send() template_values = { 'firstname': fn, 'lastname': ln, 'email': e, 'address': a, 'city': c, 'phone': p, 'zip': z } path = os.path.join(os.path.dirname(__file__), 'thanks.html') self.response.out.write(template.render(path, template_values)) except Exception, ex: self.error_write(ex)
def post(self): self.url = "" self.url_linktext = "" try: button_type = self.request.get("button") if button_type == "Register": fn = self.request.get("firstname") ln = self.request.get("lastname") e = self.request.get("email") a = self.request.get("address") c = self.request.get("city") z = self.request.get("zip") p = self.request.get("phone") user = UsersWaitingList2(id=str(uuid.uuid1())) user.email = e user.firstname = fn user.lastname = ln user.address = a user.phone = p user.zip = z user.put() # email to kelly message = mail.EmailMessage(sender="*****@*****.**", subject="A new user has registered") message.body = "%s %s\n%s\n%s\n%s\n%s %s\n%s" % (fn, ln, e, p, a, c, z, p) message.to = "*****@*****.**" message.cc = "*****@*****.**" message.send() template_values = { "firstname": fn, "lastname": ln, "email": e, "address": a, "city": c, "phone": p, "zip": z, } path = os.path.join(os.path.dirname(__file__), "thanks.html") self.response.out.write(template.render(path, template_values)) except Exception, ex: self.error_write(ex)
def convert_wait(self): query = UsersWaitingList.all() items = query.fetch(1000) for w in items: user = UsersWaitingList2(id=str(uuid.uuid1())) user.email = w.email user.firstname = w.firstname user.lastname = w.lastname user.address = w.address user.phone = w.phone user.zip = w.zip user.put() w.delete() print user
def post(self): try: self.verify_admin() button_type = self.request.get('button') items_all = self.get_all_items() harvest_date = self.request.get('weekof') harvest_date = self.get_harvest_date(harvest_date) harvest_date_str = harvest_date.strftime("%Y-%m-%d") if button_type == "Save": q = self.request.get('quantity') n = self.request.get('item') a = self.request.get('anotation') c = self.request.get('cost') id = self.request.get('id') if n == None or n == "": raise Exception("You must name the items you add") # do error page if q == None: # do error page raise Exception("The quantity must be an integer") try: qInt = int(q) except: raise Exception("Inventory must be an integer") try: cFloat = float(c) except: raise Exception("The cost must be a floating point") item_query = Item.all() item_query.filter('id = ', id) g_is = item_query.fetch(1) if g_is == None or len(g_is) < 1: item = Item(id=str(uuid.uuid1())) item.quantity = q item.remaining = q else: item = g_is[0] # make sure the new quantity is ok init_q = int(item.quantity) remaining_q = int(item.remaining) purchased_q = init_q - remaining_q new_qInt = int(q) new_r = new_qInt - purchased_q logging.info("admin is changing the quantity of |%s| from %d to %d" % (item.name, init_q, qInt)) if new_r < 0: # here is where i can ask who gets screwed logging.error("%d %s have already been sold. The quantity for %s must be at least %d." % (new_qInt, item.name, item.name, purchased_q)) raise Exception("%d %s have already been sold. The quantity for %s must be at least %d." % (new_qInt, item.name, item.name, purchased_q)) item.quantity = q item.remaining = str(new_r) item.date = harvest_date item.name = n item.cost = c item.anotation = a item.put() elif button_type == "New": template_values = { 'logout_url': self.url, 'url_linktext': self.url_linktext, 'harvest_date': harvest_date_str, } path = os.path.join(os.path.dirname(__file__), 'inventoryedit.html') self.response.out.write(template.render(path, template_values)) return elif button_type == "Remove": for i in items_all: v = self.request.get(i.id) if v == "on": if int(i.quantity) != 0: raise Exception("The inventory for %s was already published. You cannot delete items once it is published. Try changing the quantity to 0") else: i.delete() elif button_type == "Edit": found = False for i in items_all: v = self.request.get(i.id) if v == "on": found = True fi = i if found: template_values = { 'item': fi, 'logout_url': self.url, 'url_linktext': self.url_linktext, 'harvest_date': harvest_date_str, } path = os.path.join(os.path.dirname(__file__), 'inventoryedit.html') self.response.out.write(template.render(path, template_values)) return elif button_type == "Publish": if self.is_published(harvest_date): query = InventoryList.all() query.filter('date = ', harvest_date) g_us = query.fetch(1) if g_us == None or len(g_us) < 1: il = InventoryList() else: il = g_us[0] else: il = InventoryList() il.date = harvest_date il.item_count = len(items_all) il.put() elif button_type == "Printable": self.write_out(fname="inventoryprintable.html") return elif button_type == "CSV": self.write_out(fname="inventorycsv.html") return elif button_type == "Copy": cd = self.request.get('copy_date') if cd != None: self.copy_inv(items_all, cd) self.write_out() except Exception, ex: self.error_write(ex)
def post(self): try: self.verify_admin() button_type = self.request.get('button') if button_type == "Save": e = self.request.get('email').strip() a = self.request.get('address') p = self.request.get('phone') f = self.request.get('firstname') l = self.request.get('lastname') z = self.request.get('zip') c = self.request.get('city') id = self.request.get('id') users_query = UsersData.all() users_query.filter('email = ', e) g_us = users_query.fetch(1) if g_us != None and len(g_us) > 0 and g_us[0].id != id: raise Exception("The email address: %s is already in use" % (e)) users_query = UsersData.all() users_query.filter('id = ', id) g_us = users_query.fetch(1) if g_us == None or len(g_us) < 1: user = UsersData(id=str(uuid.uuid1()), email=e) else: user = g_us[0] user.email = e user.address = a user.phone = p user.firstname = f user.lastname = l user.zip = z user.city = c user.put() self.write_out() elif button_type == "Edit": found = False users = self.get_all_users() for i in users: v = self.request.get(i.id) if v == "on": found = True ui = i if found: template_values = { 'user': ui, 'logout_url': self.url, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), 'useredit.html') self.response.out.write(template.render(path, template_values)) else: self.write_out() elif button_type == "New": template_values = { 'logout_url': self.url, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), 'useredit.html') self.response.out.write(template.render(path, template_values)) elif button_type == "Yes": v = self.request.get('id') q = UsersData.all() q.filter('id = ', v) u = q.fetch(1) if u != None and len(u) == 1: q = UserChoices.all() q.filter('user ='******'user ='******'t done anything just delete it if ucs == None or len(ucs) == 0: i.delete() self.write_out() else: # if it has write out the right page sure_msg = "Are you sure you want to delete this user and all of its purchase order history?" template_values = { 'sos_sure_action': '/users', 'logout_url': self.url, 'ARE_YOU_SURE': sure_msg, 'id': i.id, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), 'sure.html') self.response.out.write(template.render(path, template_values)) return elif button_type == "Printable": self.write_out(fname="userprintable.html") elif button_type == "CSV": self.write_out(fname="usercsv.html") except Exception, ex: self.error_write(ex) raise
def nuke_query(self, query): items = query.fetch(1000) for i in items: i.id = str(uuid.uuid1()) i.put()
def post(self): try: self.verify_admin() button_type = self.request.get('button') items_all = self.get_all_items() harvest_date = self.request.get('weekof') harvest_date = self.get_harvest_date(harvest_date) harvest_date_str = harvest_date.strftime("%Y-%m-%d") if button_type == "Save": q = self.request.get('quantity') n = self.request.get('item') a = self.request.get('anotation') c = self.request.get('cost') id = self.request.get('id') if n == None or n == "": raise Exception("You must name the items you add") # do error page if q == None: # do error page raise Exception("The quantity must be an integer") try: qInt = int(q) except: raise Exception("Inventory must be an integer") try: cFloat = float(c) except: raise Exception("The cost must be a floating point") item_query = Item.all() item_query.filter('id = ', id) g_is = item_query.fetch(1) if g_is == None or len(g_is) < 1: item = Item(id=str(uuid.uuid1())) item.quantity = q item.remaining = q else: item = g_is[0] # make sure the new quantity is ok init_q = int(item.quantity) remaining_q = int(item.remaining) purchased_q = init_q - remaining_q new_qInt = int(q) new_r = new_qInt - purchased_q logging.info( "admin is changing the quantity of |%s| from %d to %d" % (item.name, init_q, qInt)) if new_r < 0: # here is where i can ask who gets screwed logging.error( "%d %s have already been sold. The quantity for %s must be at least %d." % (new_qInt, item.name, item.name, purchased_q)) raise Exception( "%d %s have already been sold. The quantity for %s must be at least %d." % (new_qInt, item.name, item.name, purchased_q)) item.quantity = q item.remaining = str(new_r) item.date = harvest_date item.name = n item.cost = c item.anotation = a item.put() elif button_type == "New": template_values = { 'logout_url': self.url, 'url_linktext': self.url_linktext, 'harvest_date': harvest_date_str, } path = os.path.join(os.path.dirname(__file__), 'inventoryedit.html') self.response.out.write(template.render(path, template_values)) return elif button_type == "Remove": for i in items_all: v = self.request.get(i.id) if v == "on": if int(i.quantity) != 0: raise Exception( "The inventory for %s was already published. You cannot delete items once it is published. Try changing the quantity to 0" ) else: i.delete() elif button_type == "Edit": found = False for i in items_all: v = self.request.get(i.id) if v == "on": found = True fi = i if found: template_values = { 'item': fi, 'logout_url': self.url, 'url_linktext': self.url_linktext, 'harvest_date': harvest_date_str, } path = os.path.join(os.path.dirname(__file__), 'inventoryedit.html') self.response.out.write( template.render(path, template_values)) return elif button_type == "Publish": if self.is_published(harvest_date): query = InventoryList.all() query.filter('date = ', harvest_date) g_us = query.fetch(1) if g_us == None or len(g_us) < 1: il = InventoryList() else: il = g_us[0] else: il = InventoryList() il.date = harvest_date il.item_count = len(items_all) il.put() elif button_type == "Printable": self.write_out(fname="inventoryprintable.html") return elif button_type == "CSV": self.write_out(fname="inventorycsv.html") return elif button_type == "Copy": cd = self.request.get('copy_date') if cd != None: self.copy_inv(items_all, cd) self.write_out() except Exception, ex: self.error_write(ex)
def post(self): try: self.verify_admin() button_type = self.request.get('button') if button_type == "Save": e = self.request.get('email').strip() a = self.request.get('address') p = self.request.get('phone') f = self.request.get('firstname') l = self.request.get('lastname') z = self.request.get('zip') c = self.request.get('city') id = self.request.get('id') users_query = UsersData.all() users_query.filter('email = ', e) g_us = users_query.fetch(1) if g_us != None and len(g_us) > 0 and g_us[0].id != id: raise Exception("The email address: %s is already in use" % (e)) users_query = UsersData.all() users_query.filter('id = ', id) g_us = users_query.fetch(1) if g_us == None or len(g_us) < 1: user = UsersData(id=str(uuid.uuid1()), email=e) else: user = g_us[0] user.email = e user.address = a user.phone = p user.firstname = f user.lastname = l user.zip = z user.city = c user.put() self.write_out() elif button_type == "Edit": found = False users = self.get_all_users() for i in users: v = self.request.get(i.id) if v == "on": found = True ui = i if found: template_values = { 'user': ui, 'logout_url': self.url, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), 'useredit.html') self.response.out.write( template.render(path, template_values)) else: self.write_out() elif button_type == "New": template_values = { 'logout_url': self.url, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), 'useredit.html') self.response.out.write(template.render(path, template_values)) elif button_type == "Yes": v = self.request.get('id') q = UsersData.all() q.filter('id = ', v) u = q.fetch(1) if u != None and len(u) == 1: q = UserChoices.all() q.filter('user ='******'user ='******'t done anything just delete it if ucs == None or len(ucs) == 0: i.delete() self.write_out() else: # if it has write out the right page sure_msg = "Are you sure you want to delete this user and all of its purchase order history?" template_values = { 'sos_sure_action': '/users', 'logout_url': self.url, 'ARE_YOU_SURE': sure_msg, 'id': i.id, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), 'sure.html') self.response.out.write( template.render(path, template_values)) return elif button_type == "Printable": self.write_out(fname="userprintable.html") elif button_type == "CSV": self.write_out(fname="usercsv.html") except Exception, ex: self.error_write(ex) raise