def post(self): try: self.verify_admin() button_type = self.request.get('button') all = False if button_type == "Nuke": all = True if button_type == "UserChoices" or all == True: query = UserChoices.all() self.nuke_query(query) if button_type == "UserData" or all == True: query = UsersData.all() self.nuke_query(query) if button_type == "UserWaitingList" or all == True: # query = UsersWaitingList.all() # self.nuke_query(query) self.convert_wait() if button_type == "InventoryList" or all == True: query = InventoryList.all() self.nuke_query(query) if button_type == "Item" or all == True: query = Item.all() self.nuke_query(query) self.do_page() except Exception, ex: self.error_write(ex)
def get(self): self.verify_admin() c = self.request.get('date') dt = datetime.strptime(c, "%Y-%M-%d") q = UserChoices.all() q.filter('date <', dt) ucs = q.fetch(1000) m = """ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>special</title> </head> <body>OK %s """ % (str(dt)) self.response.out.write(m) db.delete(ucs) for uc in ucs: self.response.out.write(str(uc.date) + " " + str(uc.id) + "<br>") # uc.delete() self.response.out.write("</body></html>")
def get_user_choice(self, inv, items): choice_query = UserChoices.all() choice_query.filter("date = ", inv.date) choice_query.filter("user = "******"item") user_choices = choice_query.fetch(1000) # set them all up kys = sorted(items.keys()) if user_choices == None or len(user_choices) < 1: user_choices = [] for k in kys: i = items[k] uc = self.new_choice(inv, i) user_choices.append(uc) # update tmp_remaining else: for k in kys: i = items[k] found = False for uc in user_choices: # try: # if uc.item != None: # id = uc.item.id # except datastore_errors.Error, e: # if e.args[0] == "ReferenceProperty failed to be resolved": # uc.item = None # uc.put() # else: # raise # why is uc.item ever allowed to be None? # if uc.item != None and i.id == uc.item.id: if uc.item != None and i.id == uc.item.id: found = True if found == False: logging.info( "the item %s was not found. user must have ordered, then the item was added, then they re-ordered %s." % (str(i), str(self.sos_user)) ) uc = self.new_choice(inv, i) user_choices.append(uc) user_choices = sorted(user_choices, key=lambda u: u.item.name) return user_choices
def get_user_choice(self, inv, items): choice_query = UserChoices.all() choice_query.filter('date = ', inv.date) choice_query.filter('user = '******'item') user_choices = choice_query.fetch(1000) # set them all up kys = sorted(items.keys()) if user_choices == None or len(user_choices) < 1: user_choices = [] for k in kys: i = items[k] uc = self.new_choice(inv, i) user_choices.append(uc) # update tmp_remaining else: for k in kys: i = items[k] found = False for uc in user_choices: #try: # if uc.item != None: # id = uc.item.id #except datastore_errors.Error, e: # if e.args[0] == "ReferenceProperty failed to be resolved": # uc.item = None # uc.put() # else: # raise # why is uc.item ever allowed to be None? #if uc.item != None and i.id == uc.item.id: if uc.item != None and i.id == uc.item.id: found = True if found == False: logging.info( "the item %s was not found. user must have ordered, then the item was added, then they re-ordered %s." % (str(i), str(self.sos_user))) uc = self.new_choice(inv, i) user_choices.append(uc) user_choices = sorted(user_choices, key=lambda u: u.item.name) return user_choices
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 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 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 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