本文整理汇总了Python中tinyms.core.common.Utils.encode方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.encode方法的具体用法?Python Utils.encode怎么用?Python Utils.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinyms.core.common.Utils
的用法示例。
在下文中一共展示了Utils.encode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def delete(self, id_):
self.set_header("Content-Type", "text/json;charset=utf-8")
meta = DataTableModule.__entity_mapping__.get(id_)
if not meta:
self.set_status(403, "Error!")
entity = import_object(meta["name"])
custom_filter = ObjectPool.datatable_provider.get(meta["name"])
custom_filter_obj = None
if custom_filter:
custom_filter_obj = custom_filter()
valid_msg = ""
message = dict()
message["flag"] = "delete"
rec_id = self.get_argument("id")
sf = SessionFactory.new()
cur_row = sf.query(entity).get(rec_id)
if hasattr(custom_filter_obj, "before_delete"):
valid_msg = custom_filter_obj.before_delete(cur_row, sf, self)
if not valid_msg:
sf.delete(cur_row)
sf.commit()
if hasattr(custom_filter_obj, "after_delete"):
custom_filter_obj.after_delete(cur_row, sf, self)
message["success"] = True
message["msg"] = "Deleted"
self.write(Utils.encode(message))
else:
message["success"] = False
message["msg"] = valid_msg
self.write(Utils.encode(message))
示例2: get
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def get(self, id_):
cls = ObjectPool.autocomplete_keys.get(id_)
self.set_header("Content-Type", "text/json;charset=utf-8")
if cls:
obj = cls()
if hasattr(obj, "text"):
text = obj.text(self.get_argument("id"), self)
self.write(Utils.encode([text]))
else:
self.write(Utils.encode([""]))
示例3: post
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def post(self, id_):
cls = ObjectPool.autocomplete_keys.get(id_)
self.set_header("Content-Type", "text/json;charset=utf-8")
if cls:
obj = cls()
if hasattr(obj, "data"):
search_word = self.get_argument("search_word")
data = obj.data(search_word, self)
self.write(Utils.encode(data))
else:
self.write(Utils.encode(list()))
示例4: update
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def update(self, id_):
message = dict()
self.set_header("Content-Type", "text/json;charset=utf-8")
meta = DataTableModule.__entity_mapping__.get(id_)
if not meta:
self.set_status(403, "Error!")
entity = import_object(meta["name"])
custom_filter = ObjectPool.datatable_provider.get(meta["name"])
custom_filter_obj = None
if custom_filter:
custom_filter_obj = custom_filter()
rec_id = self.get_argument("id")
valid_msg = ""
if not rec_id:
message["flag"] = "add"
sf = SessionFactory.new()
obj = self.wrap_entity(entity())
if hasattr(custom_filter_obj, "before_add"):
valid_msg = custom_filter_obj.before_add(obj, sf, self)
# 检查没有数据上的问题才执行保存动作
if not valid_msg:
sf.add(obj)
sf.commit()
if hasattr(custom_filter_obj, "after_add"):
custom_filter_obj.after_add(obj, sf, self)
message["success"] = True
message["msg"] = obj.id
self.write(Utils.encode(message))
else:
message["success"] = False
message["msg"] = valid_msg
self.write(Utils.encode(message))
else:
message["flag"] = "update"
sf = SessionFactory.new()
cur_row = sf.query(entity).get(rec_id)
self.wrap_entity(cur_row)
if hasattr(custom_filter_obj, "before_modify"):
valid_msg = custom_filter_obj.before_modify(cur_row, sf, self)
if not valid_msg:
sf.commit()
if hasattr(custom_filter_obj, "after_modify"):
custom_filter_obj.after_modify(cur_row, sf, self)
message["success"] = True
message["msg"] = "Updated"
self.write(Utils.encode(message))
else:
message["success"] = False
message["msg"] = valid_msg
self.write(Utils.encode(message))
示例5: get
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def get(self, *args, **kwargs):
insp = reflection.Inspector.from_engine(SessionFactory.__engine__)
context_data = dict()
context_data["entity_map"] = Utils.encode(SessionFactory.entitys)
table_cols = dict()
table_cols_text = dict()
for table_name in SessionFactory.entitys:
cols_def = insp.get_columns(table_name)
cols = list()
for col_def in cols_def:
cols.append(col_def["name"])
table_cols[table_name] = cols
table_cols_text[table_name] = Utils.encode(cols)
context_data["table_cols"] = table_cols
context_data["table_cols_text"] = table_cols_text
return self.render("workbench/dev.widgets.html", context=context_data)
示例6: req
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def req(self, key, method_name):
"""
Url: localhost/api/key/method
:param key: example: com.tinyms.category.v2
:return:
example:
@api("com.tinyms.category.v2")
class ApiTest():
def create():
prama1 = self.param("prama1");
req = self.request # IRequest
client side:
$.post("/api/com.tinyms.category.v2/create",params,func,"json");
"""
self.set_header("Content-Type", "text/json;charset=utf-8")
if not key:
self.write("Key require.")
else:
cls = ObjectPool.api.get(key)
if not cls:
self.write("Object not found.")
else:
obj = cls()
if hasattr(obj, method_name):
setattr(obj, "request", self)
setattr(obj, "body", self.request.body)
setattr(obj, "files", self.request.files)
setattr(obj, "__params__", self.wrap_params_to_dict())
setattr(obj, "param", lambda key: obj.__params__.get(key))
func = getattr(obj, method_name)
result = func()
self.write(Utils.encode(result))
示例7: post
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def post(self, *args, **kwargs):
self.set_header("Content-Type", "text/json;charset=utf-8")
#build path
upload_path = "/upload/%s/%s" % (Utils.format_year_month(Utils.current_datetime()),
Utils.current_datetime().date().day)
path = self.get_webroot_path() + upload_path
Utils.mkdirs(path)
files = self.request.files
items = list()
for key in files:
item = dict()
meta = files[key]
file_name = meta["filename"]
ext_name = os.path.splitext(file_name)
name_ = Utils.uniq_index()
if not ext_name:
new_file_name = name_
else:
new_file_name = "%s.%s" % (name_, ext_name)
save_path = "%s/%s" % (path, new_file_name)
with open(save_path, "wb") as uploader:
uploader.write(meta["body"])
item["local_name"] = file_name
item["ext_name"] = ext_name
item["upload_path"] = "%s/%s" % (upload_path, new_file_name)
item["archives_id"] = self.get_current_user()
items.append(item)
self.write(Utils.encode(["OK"]))
示例8: post
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def post(self, id_, act):
point = DataTableModule.__security_points__.get(id_)
print(point)
message = dict()
if act == "list":
if not self.auth({point.list}):
self.write(dict())
else:
self.list(id_)
elif act == "view":
if not self.auth({point.view}):
message["success"] = False
message["msg"] = "UnAuth"
self.write(Utils.encode(message))
else:
self.view(id_)
elif act == "save":
if not self.auth({point.update}):
message["success"] = False
message["msg"] = "UnAuth"
self.write(Utils.encode(message))
else:
self.update(id_)
elif act == "saveNext":
if not self.auth({point.update}):
message["success"] = False
message["msg"] = "UnAuth"
self.write(Utils.encode(message))
else:
self.update(id_)
elif act == "delete":
if not self.auth({point.delete}):
message["success"] = False
message["msg"] = "UnAuth"
self.write(Utils.encode(message))
else:
self.delete(id_)
示例9: view
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import encode [as 别名]
def view(self, id_):
message = dict()
message["success"] = False
self.set_header("Content-Type", "text/json;charset=utf-8")
meta = DataTableModule.__entity_mapping__.get(id_)
if not meta:
self.set_status(403, "Error!")
entity = import_object(meta["name"])
rec_id = self.get_argument("id")
if rec_id:
sf = SessionFactory.new()
item = sf.query(entity).get(rec_id)
if item:
message["success"] = True
message["msg"] = item.dict()
self.write(Utils.encode(message))
else:
item = entity()
message["msg"] = item.dict()
self.write(Utils.encode(message))
else:
item = entity()
message["msg"] = item.dict()
self.write(Utils.encode(message))