def get_or_create_env_resource_fee(mapper, connect, target): logger.error("\t !!![get_or_create_env_resource_fee]") logger.error("\t target id:%s" % target.id) if target.env_id != 0: env_internet_ip_types = connect.execute( Env_Internet_Ip_Types.__table__.select().where( Env_Internet_Ip_Types.__table__.c.env_id == target.env_id)) _env_internet_ip_types = [] for internet_ip_type in env_internet_ip_types: _json_obj = dict(id=internet_ip_type.id, name=internet_ip_type.name) bandwidth_list = connect.execute( Env_Internet_Bandwidth.__table__.select().where( Env_Internet_Bandwidth.__table__.c.internet_ip_type_id == internet_ip_type.id)) _bandwidth_obj = {bw.bandwidth_id: bw.fee for bw in bandwidth_list} _json_obj.update(fee=_bandwidth_obj) _env_internet_ip_types.append(_json_obj) # env_internet_ip_types = [{"id": i.id, "name": i.name, "fee": "%.2f" % i.fee} for i in env_internet_ip_types] result = connect.execute(Env_Resource_Fee.__table__.update().where( Env_Resource_Fee.env_id == target.env_id).values( internet_ip=simplejson.dumps(_env_internet_ip_types))) logger.info(result.rowcount) # from code import interact # interact(local=locals()) if result.rowcount <= 0: if target.env_id: insert_result = connect.execute( Env_Resource_Fee.__table__.insert().values( env_id=target.env_id, internet_ip=simplejson.dumps(_env_internet_ip_types))) logger.info(insert_result.rowcount) logger.info("\t [env_internet_ip_types]: %s" % env_internet_ip_types)
def do_notice_checker(self, json_message): logger.info( "-----------------------------NOTICE CHECKER-----------------------------" ) svc = PtUserService(self) pt_users_res = svc.get_list() user_ids = [ u.id for u in pt_users_res.data if "pro_resource_apply.check" in u.get_current_perms() ] for user_id in user_ids: svc = ActHistoryService(self, {"user_id": user_id}) tasks_res = svc.get_res_tasks() data = { "tasks_res": tasks_res, "imchecker": True, "STATUS_RESOURCE": STATUS_RESOURCE } chat = { "user_id": user_id, "html": self.render_to_string("admin/notice/tasks.html", **data) } chat.update(json_message) logger.error(chat) EchoWebSocket.send_message(chat)
def prepare(self): self.expire_session() super(AuthHandler, self).prepare() if self.current_user and self.request.method == "GET" and not self.ajax: if not self.current_user.username: logger.error(u"\t 您还没有设置用户名,请设置用户名") self.add_message(u"您还没有设置用户名,请设置用户名", level="warning", url=self.reverse_url('user_profile')) if not self.current_user.email: self.add_message(u"您还没有设置邮箱,请设置邮箱", level="warning", url=self.reverse_url('user_profile'))
def del_env_internet_ip(self): env_internet_ip_ids = self.params.get("env_internet_ip_ids", []) # env_internet_ip_ids = [i for i in env_internet_ip_ids if isinstance(i, int)] or_conditions = or_() for id in env_internet_ip_ids: #if isinstance(id, int): logger.error(id) or_conditions.append(Env_Internet_Ip_Types.id == id) ips = self.db.query( Env_Internet_Ip_Types ).filter( or_conditions ) messages = [] for ip in ips.all(): messages.append(u"环境[%s]对应互联网IP类型[%s]删除成功!" % (ip.env.name, ip.name)) ips.delete() return self.success(data=messages)
def wrapper(self, *args, **kwargs): logger.info("-" * 60) logger.error("self.method: %s" % self.request.method) logger.info("self.args: %s" % self.args) logger.info("query string: %s" % dir(self.request.query)) logger.info("query string: %s" % (self.request.query, )) logger.info("self.request.headers: %s" % self.request.headers) _xget = self.request.headers.get("XGET") logger.info(_xget) # self.pjax = self.request.headers.get("X-PJAX") logger.info(method) if _xget: # from code import interact # interact(local=locals()) return self.xget(*args, **kwargs) # raise Exception('method {} not found'.format(_xmethod.lower())) # return eval(_xmethod.lower())(self, *args, **kwargs) else: return method(self, *args, **kwargs)
def wrapper(self, *args, **kwargs): logger.info("-" * 60) logger.error("self.method: %s" % self.request.method) logger.info("self.args: %s" % self.args) logger.info("query string: %s" % dir(self.request.query)) logger.info("query string: %s" % (self.request.query,)) logger.info("self.request.headers: %s" % self.request.headers) _xget = self.request.headers.get("XGET") logger.info(_xget) # self.pjax = self.request.headers.get("X-PJAX") logger.info(method) if _xget: # from code import interact # interact(local=locals()) return self.xget(*args, **kwargs) # raise Exception('method {} not found'.format(_xmethod.lower())) # return eval(_xmethod.lower())(self, *args, **kwargs) else: return method(self, *args, **kwargs)
def check_form_valid(self, param_schema): try: check_result = param_schema(self.params) logger.info(check_result) return self.success(check_result) except MultipleInvalid as e: logger.error(u"\t %s" % e.errors) ziped_errors = [(i.path[0], i) for i in e.errors] messages = [] for path, err in ziped_errors: if hasattr(ERROR, "res_%s_invalid_err" % path): column = getattr(Pro_Resource_Apply, path) column_info = column.info["name"] msg = "%s %s" % (getattr(ERROR, "res_%s_invalid_err" % path).errvalue, "'%s'%s" % (column_info, err.msg)) else: msg = err.msg messages.append(msg) # messages.append("%s %s" % (self.failure(getattr(ERROR, "res_%s_invalid_err" % path)).return_message, "'%s'%s" % (path, err.msg))) # raise Exception(u"{}".format(",".join(messages))) return self.failures(messages)
def get_or_create_env_resource_fee(mapper, connect, target): logger.error("\t !!![get_or_create_env_resource_fee]") logger.error("\t target id:%s" % target.id) if target.env_id != 0: env_internet_ip_types = connect.execute( Env_Internet_Ip_Types.__table__.select().where( Env_Internet_Ip_Types.__table__.c.env_id == target.env_id ) ) _env_internet_ip_types = [] for internet_ip_type in env_internet_ip_types: _json_obj = dict(id=internet_ip_type.id, name=internet_ip_type.name) bandwidth_list = connect.execute( Env_Internet_Bandwidth.__table__.select().where( Env_Internet_Bandwidth.__table__.c.internet_ip_type_id == internet_ip_type.id ) ) _bandwidth_obj = {bw.bandwidth_id: bw.fee for bw in bandwidth_list} _json_obj.update(fee=_bandwidth_obj) _env_internet_ip_types.append(_json_obj) # env_internet_ip_types = [{"id": i.id, "name": i.name, "fee": "%.2f" % i.fee} for i in env_internet_ip_types] result = connect.execute( Env_Resource_Fee.__table__.update().where( Env_Resource_Fee.env_id == target.env_id ).values( internet_ip = simplejson.dumps(_env_internet_ip_types) ) ) logger.info(result.rowcount) # from code import interact # interact(local=locals()) if result.rowcount <= 0: if target.env_id: insert_result = connect.execute( Env_Resource_Fee.__table__.insert().values( env_id = target.env_id, internet_ip = simplejson.dumps(_env_internet_ip_types) ) ) logger.info(insert_result.rowcount) logger.info("\t [env_internet_ip_types]: %s" % env_internet_ip_types)
def do_notice_user(self, json_message): svc = ProResourceApplyService(self, {"res_id": json_message["res_id"]}) resource_res = svc.get_resource() user_id = resource_res.data.user_id svc = ActHistoryService(self, {"user_id": user_id}) tasks_res = svc.get_res_tasks() logger.info(resource_res.data.user_id) logger.info(resource_res.data.checker_id) data = { "tasks_res": tasks_res, "imchecker": False, "STATUS_RESOURCE": STATUS_RESOURCE } chat = { "user_id": user_id, "data": resource_res.data.as_dict(), "html": self.render_to_string("admin/notice/tasks.html", **data) } logger.error(chat) chat.update(json_message) EchoWebSocket.send_message(chat)
def do_notice_checker(self, json_message): logger.info("-----------------------------NOTICE CHECKER-----------------------------") svc = PtUserService(self) pt_users_res = svc.get_list() user_ids = [u.id for u in pt_users_res.data if "pro_resource_apply.check" in u.get_current_perms()] for user_id in user_ids: svc = ActHistoryService(self, {"user_id": user_id}) tasks_res = svc.get_res_tasks() data = { "tasks_res": tasks_res, "imchecker": True, "STATUS_RESOURCE": STATUS_RESOURCE } chat = { "user_id": user_id, "html": self.render_to_string("admin/notice/tasks.html", **data) } chat.update(json_message) logger.error(chat) EchoWebSocket.send_message(chat)
def delete_env_info(mapper, connect, target): logger.error("\t [delete_env_info]") logger.error("\t target id:%s" % target.id) logger.error("\t target name:%s" % target.name) res1 = connect.execute(Env_Internet_Ip_Types.__table__.delete().where( Env_Internet_Ip_Types.__table__.c.env_id == target.id)) res2 = connect.execute(Env_Resource_Fee.__table__.delete().where( Env_Resource_Fee.__table__.c.env_id == target.id)) res3 = connect.execute(Env_Resource_Value.__table__.delete().where( Env_Resource_Value.__table__.c.env_id == target.id)) logger.info("\t res1:%s" % res1.rowcount) logger.info("\t res2:%s" % res2.rowcount) logger.info("\t res3:%s" % res3.rowcount) logger.error("\t [delete_env_info_finish]")
def on_message(self, message): logger.error("====[status onmessage]====") self.svc = DataBaseService() self.svc.__enter__() logger.error("\t WebSocket message: %s" % message) json_message = simplejson.loads(message) if json_message["action"] == "init_status": # svc = ProResourceApplyService(self, {"res_id": json_message["res_id"]}) # resource_res = svc.get_resource() # user_id = resource_res.data.user_id user_id = json_message["user_id"] svc = PtUserService(self, {"user_id": user_id}) pt_user_res = svc.get_info() if pt_user_res.return_code == 0: current_perms = pt_user_res.data.get_current_perms() if "pro_resource_apply.view" in current_perms: imchecker = False else: imchecker = True svc = ActHistoryService(self, {"user_id": user_id}) tasks_res = svc.get_res_tasks() data = { "tasks_res": tasks_res, "imchecker": imchecker, "STATUS_RESOURCE": STATUS_RESOURCE } chat = { "user_id": user_id, "task_html": self.render_to_string("admin/notice/tasks.html", **data) } chat.update(json_message) logger.error(chat) self.write_message(chat) # self.on_finish() # chat.update(json_message) # EchoWebSocket.send_message(chat) # self.write_message(u"You said: " + message) elif json_message["action"] == "offline": EchoWebSocket.users.pop(str(json_message["user_id"])) else: self.write_message(u"You said: " + message) self.svc.db.commit() self.svc.db.close() logger.error("====[status finish]====")
def delete_env_info(mapper, connect, target): logger.error("\t [delete_env_info]") logger.error("\t target id:%s" % target.id) logger.error("\t target name:%s" % target.name) res1 = connect.execute( Env_Internet_Ip_Types.__table__.delete().where( Env_Internet_Ip_Types.__table__.c.env_id == target.id ) ) res2 = connect.execute( Env_Resource_Fee.__table__.delete().where( Env_Resource_Fee.__table__.c.env_id == target.id ) ) res3 = connect.execute( Env_Resource_Value.__table__.delete().where( Env_Resource_Value.__table__.c.env_id == target.id ) ) logger.info("\t res1:%s" % res1.rowcount) logger.info("\t res2:%s" % res2.rowcount) logger.info("\t res3:%s" % res3.rowcount) logger.error("\t [delete_env_info_finish]")
def on_message(self, message): logger.error("====[index onmessage]====") self.svc = DataBaseService() self.svc.__enter__() logger.error("\t WebSocket message: %s" % message) json_message = simplejson.loads(message) if json_message["action"] == "pro_resource_apply": self.do_notice_user(json_message) elif json_message["action"] == "notice_checker": self.do_notice_checker(json_message) elif json_message["action"] == "join": self.do_online(json_message) elif json_message["action"] == "offline": EchoWebSocket.users.pop(str(json_message["user_id"])) else: self.write_message(u"You said: " + message) self.svc.db.commit() self.svc.db.close() logger.error("====[index finish]====")
def wrapper(self, *args, **kwargs): logger.info("perms: %s" % perms) sys_permissions = get_sys_group_ops() # logger.info("--------------[sys_permissions]--------------") # logger.info(sys_permissions) need_perms = [p.strip() for p in perms.split(",")] logger.info("_and = %s" % _and) logger.info("need_perms = %s" % need_perms) # for perm in need_perms: try: for perm in need_perms: try: keycode = sys_permissions[perm] except KeyError: raise PermissionDefinedError(perm) # logger.info(self.get_current_user()) # logger.info(self.current_user) if self.current_user: current_perms = self.current_user.current_perms # logger.info("--------------[current_perms]--------------") # logger.info(self.current_user.current_perms) logger.info("---------------[checking perm]------------------") # logger.info(perm) if _and: minus_result = set(need_perms) - set(current_perms.keys()) if len(minus_result) > 0: perm = list(minus_result)[0] raise PermissionError(perm) else: return method(self, *args, **kwargs) else: checking_result = [i for i in current_perms.keys() if i in need_perms] if len(checking_result) > 0: return method(self, *args, **kwargs) else: perm = need_perms[0] raise PermissionError(perm) # try: # current_keycode = current_perms[perm] # except KeyError: # raise PermissionError(perm) # if keycode == current_keycode: # return method(self, *args, **kwargs) # else: # raise PermissionError(perm) logger.info("%s check pass!" % need_perms) return method(self, *args, **kwargs) except PermissionDefinedError as e: headers = self.request.headers x_requested_with = headers.get("X-Requested-With", "") if self.pjax: raise gen.Return(self.render("admin/error/403.html", error_message=u"Oops, The permission %s is not defined" % perm)) if x_requested_with == "XMLHttpRequest": raise gen.Return(self.write(simplejson.dumps({ "return_code": -403, "return_message": u"Oops, The permission %s is not defined" % perm }))) else: raise gen.Return(self.render("admin/error/403.html", error_message=u"Oops, The permission %s is not defined" % perm)) except PermissionError as e: logger.error(e) headers = self.request.headers x_requested_with = headers.get("X-Requested-With", "") if self.pjax: raise gen.Return(self.render("admin/error/403.html", error_message=e.__unicode__())) if x_requested_with == "XMLHttpRequest": raise gen.Return(self.write(simplejson.dumps({ "return_code": -403, "return_message": u"Oops, You don't have the permission %s" % perm }))) else: raise gen.Return(self.render("admin/error/403.html", error_message=u"Oops, You don't have the permission %s" % perm)) return method(self, *args, **kwargs)
def wrapper(self, *args, **kwargs): logger.info("perms: %s" % perms) sys_permissions = get_sys_group_ops() # logger.info("--------------[sys_permissions]--------------") # logger.info(sys_permissions) need_perms = [p.strip() for p in perms.split(",")] logger.info("_and = %s" % _and) logger.info("need_perms = %s" % need_perms) # for perm in need_perms: try: for perm in need_perms: try: keycode = sys_permissions[perm] except KeyError: raise PermissionDefinedError(perm) # logger.info(self.get_current_user()) # logger.info(self.current_user) if self.current_user: current_perms = self.current_user.current_perms # logger.info("--------------[current_perms]--------------") # logger.info(self.current_user.current_perms) logger.info( "---------------[checking perm]------------------") # logger.info(perm) if _and: minus_result = set(need_perms) - set( current_perms.keys()) if len(minus_result) > 0: perm = list(minus_result)[0] raise PermissionError(perm) else: return method(self, *args, **kwargs) else: checking_result = [ i for i in current_perms.keys() if i in need_perms ] if len(checking_result) > 0: return method(self, *args, **kwargs) else: perm = need_perms[0] raise PermissionError(perm) # try: # current_keycode = current_perms[perm] # except KeyError: # raise PermissionError(perm) # if keycode == current_keycode: # return method(self, *args, **kwargs) # else: # raise PermissionError(perm) logger.info("%s check pass!" % need_perms) return method(self, *args, **kwargs) except PermissionDefinedError as e: headers = self.request.headers x_requested_with = headers.get("X-Requested-With", "") if self.pjax: raise gen.Return( self.render("admin/error/403.html", error_message= u"Oops, The permission %s is not defined" % perm)) if x_requested_with == "XMLHttpRequest": raise gen.Return( self.write( simplejson.dumps({ "return_code": -403, "return_message": u"Oops, The permission %s is not defined" % perm }))) else: raise gen.Return( self.render("admin/error/403.html", error_message= u"Oops, The permission %s is not defined" % perm)) except PermissionError as e: logger.error(e) headers = self.request.headers x_requested_with = headers.get("X-Requested-With", "") if self.pjax: raise gen.Return( self.render("admin/error/403.html", error_message=e.__unicode__())) if x_requested_with == "XMLHttpRequest": raise gen.Return( self.write( simplejson.dumps({ "return_code": -403, "return_message": u"Oops, You don't have the permission %s" % perm }))) else: raise gen.Return( self.render("admin/error/403.html", error_message= u"Oops, You don't have the permission %s" % perm)) return method(self, *args, **kwargs)