def addRestaurantEditModel(self): rem = RestaurantEditModel(key_name= users.get_current_user().user_id()) rem.current_model_edit_id = '0' rem.current_model_name = '0' rem.current_model_menu_id = '0' rem.current_model_menu_name = '0' rem.current_cat_id = '0' rem.current_cat_name = '0' x = memcache.get("rem") #set the mc_error hack memcache.add("mc_error",False) if x is not None: if not memcache.replace("rem",rem) : memcache.replace("cache_error_occured",True) memcache.replace("mc_error",True) else : if not memcache.add("rem",rem) : memcache.replace("cache_error_occured",True) memcache.replace("mc_error",True) rem.put()
def GET(self): user = users.get_current_user() isadmin = users.is_current_user_admin() r = Restaurant() latest_restaurants = r.getLatestRestaurants() hasprofile = 0 if user: hasprofile = users.get_current_user().user_id() greeting = ("Welcome, %s! (<a href=\"%s\">sign out</a>)" % (user.nickname(), users.create_logout_url("/"))) p = Profile() profile = p.getProfile() if not profile: p.add() rem = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) if not rem : re = RestaurantEdit() re.addRestaurantEditModel() else: greeting = ("<a href=\"%s\">Sign in or register</a>." % users.create_login_url("/")) return main_view.index("Grasshopper",greeting,hasprofile, sorted(latest_restaurants.iteritems()))
def getCatName(self): rem = memcache.get("rem") if rem is not None and not RestaurantEdit.mc_err(self) : return rem.current_cat_name else: r = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) return r.current_cat_name
def getMenuId(self): rem = memcache.get("rem") if rem is not None and not RestaurantEdit.mc_err(self) : return rem.current_model_menu_id else : m = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) if m : return m.current_model_menu_id
def addMenuId(self,id): rem = memcache.get("rem") if rem is not None : rem.current_model_menu_id = id if not memcache.add("rem",rem): memcache.replace("mc_error",True) m = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) m.current_model_menu_id = id m.put()
def getRestaurantEditModel(self): rem = memcache.get("rem") if rem is not None and not RestaurantEdit.mc_err(self): return rem else: r = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) if not memcache.add("rem", r): memcache.replace("mc_error",True) return r
def addCatName(self,name): rem = memcache.get("rem") if rem is not None : rem.current_cat_name = name if not memcache.add("rem",rem) : memcache.replace("mc_error",True) m = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) m.current_cat_name = name m.put()
def getRestaurantIdNameList(self): out = {} rem = memcache.get("rem") if rem is not None and not RestaurantEdit.mc_err(self) : out[rem.current_model_edit_id] = rem.current_model_name else : r = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) if r : out[r.current_model_edit_id] = r.current_model_name return out
def resetMenuName(self): rem = memcache.get("rem") if rem is not None and not RestaurantEdit.mc_err(self) : rem.current_model_menu_name = '0' if not memcache.replace("rem",rem) : memcache.replace("mc_error",True) m = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) if m: m.current_model_menu_name = '0' m.put()
def isRestaurantSelected(self): rem = memcache.get("rem") result = True if rem is not None and not RestaurantEdit.mc_err(self) : if str(rem.current_model_edit_id) == '0' : result = False else : r = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) if r : if str(r.current_model_edit_id) == '0' : result = False return result
def addRestaurantNameId(self,id): r = RestaurantModel.get_by_id(int(id)) r_name = r.name rem = memcache.get("rem") if rem is not None : rem.current_model_edit_id = id rem.current_model_name = r_name if not memcache.add("rem",rem) : memcache.replace("mc_error",True) m = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) m.current_model_edit_id = id m.current_model_name = r_name m.put()
def resetRestaurantEditModel(self): rem = memcache.get("rem") if rem is not None : rem.current_model_edit_id = '0' rem.current_model_name = '0' rem.current_model_menu_id= '0' rem.current_model_menu_name = '0' rem.current_cat_id = '0' rem.current_cat_name = '0' if not memcache.replace("rem",rem) : memcache.replace("mc_error",True) r = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id()) if r : r.current_model_edit_id = '0' r.current_model_name = '0' r.current_model_menu_id= '0' r.current_model_menu_name = '0' r.current_cat_id = '0' r.current_cat_name = '0' r.put()