def add_userpage(user_id, page_id, value,user_page_id=None): user_page = UserPage() if user_page_id is not None: user_page.user_page_id = user_page_id user_page.created_time = datetime.datetime.now() user_page.updated_time = datetime.datetime.now() else: user_page.updated_time = datetime.datetime.now() user_page.user_id = user_id user_page.page_id = page_id user_page.value = value user_page.persist()
def had_privilege(request, page_id, privilege_val): user = get_userinfo(request) user_page = UserPage.load(user_id=int(user.id), page_id=page_id) if not user_page: return False if user_page.value % privilege_val == 0: return True return False
def get_page_all_list(user_id): new_pages = [] pages = Page.query() for p in pages: if not p: continue user_page = UserPage.load(user_id=int(user_id), page_id=p.page_id) if user_page: p.user_page_id = user_page.user_page_id p.value = user_page.value new_pages.append(p) else : p.user_page_id = 0 p.value = 0 new_pages.append(p) return new_pages
def replace_function(*args, **kwargs): #被替换执行的函数,主要工作就在这里完成 request = args[0] #这里要求参数传进来,第一个必须是request对象 user = user_roles.get_userinfo(request) user_page = UserPage.load(user_id=int(user.id), page_id=page_id) if not user_page: response = HttpResponseRedirect("/privilege_error/") return response value = user_page.value if value == 1: response = HttpResponseRedirect("/privilege_error/") return response if operator_id and operator_id == 1 and value % 2 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 2 and value % 3 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 3 and value % 5 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 4 and value % 7 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 5 and value % 11 == 0: return input_function(*args, **kwargs) else: response = HttpResponseRedirect("/privilege_error/") return response
def replace_function(*args, **kwargs): #被替换执行的函数,主要工作就在这里完成 request = args[0]#这里要求参数传进来,第一个必须是request对象 user = user_roles.get_userinfo(request) user_page = UserPage.load(user_id=int(user.id), page_id=page_id) if not user_page: response = HttpResponseRedirect("/privilege_error/") return response value = user_page.value if value == 1: response = HttpResponseRedirect("/privilege_error/") return response if operator_id and operator_id == 1 and value % 2 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 2 and value % 3 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 3 and value % 5 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 4 and value % 7 == 0: return input_function(*args, **kwargs) if operator_id and operator_id == 5 and value % 11 == 0: return input_function(*args, **kwargs) else: response = HttpResponseRedirect("/privilege_error/") return response
def delete_userpage(user_page_id): user_page = UserPage.load(user_page_id = user_page_id) user_page.delete('user_page_id')
def delete_userpage(user_page_id): user_page = UserPage.load(user_page_id=user_page_id) user_page.delete('user_page_id')
def add_userpage(user_id, page_id, value, user_page_id=None): user_page = UserPage() if user_page_id is not None: user_page.user_page_id = user_page_id user_page.created_time = datetime.datetime.now() user_page.updated_time = datetime.datetime.now() else: user_page.updated_time = datetime.datetime.now() user_page.user_id = user_id user_page.page_id = page_id user_page.value = value user_page.persist()