本文整理汇总了Python中tinyms.core.common.Utils类的典型用法代码示例。如果您正苦于以下问题:Python Utils类的具体用法?Python Utils怎么用?Python Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: push_users_fp_to_machine
def push_users_fp_to_machine(sn, items):
"""
@param sn:
@param items: [[pin, name, fid, tpl]..]
"""
sf = SessionFactory.new()
id_ = sf.query(ValidWorkCommands.id).filter(ValidWorkCommands.sn == sn).limit(1).scalar()
cmds = list()
for item in items:
create = r"DATA DEL_USER PIN=%i\r\nDATA USER PIN=%i\tName=%s\r\n" % (item[0], item[0], item[1])
update = r"DATA FP PIN=%i\tFID=%i\tTMP=%s\r\n" % (item[0], item[2], item[3])
vwc = ValidWorkCommands()
vwc.sn = sn
vwc.validworkmachine_id = id_
vwc.cmd = create
vwc.create_date = Utils.current_datetime()
vwc1 = ValidWorkCommands()
vwc1.sn = sn
vwc1.validworkmachine_id = id_
vwc1.cmd = update
vwc1.create_date = Utils.current_datetime()
cmds += [vwc, vwc1]
sf.add_all(cmds)
sf.commit()
示例2: list
def list(self, id_):
name = DataViewModule.__view_mapping__.get(id_)
if not name:
self.set_status(403, "Error!")
self.set_header("Content-Type", "text/json;charset=utf-8")
display_start = Utils.parse_int(self.get_argument("iDisplayStart"))
display_length = Utils.parse_int(self.get_argument("iDisplayLength"))
total = 0
ds = list()
custom_data_provider = ObjectPool.dataview_provider.get(name)
if custom_data_provider:
default_search_value = self.get_argument("sSearch")
obj = custom_data_provider()
if hasattr(obj, "count"):
total = obj.count(default_search_value, self)
if hasattr(obj, "list"):
ds = obj.list(default_search_value, display_start, display_length, self)
results = dict()
results["sEcho"] = self.get_argument("sEcho")
results["iTotalRecords"] = total
results["iTotalDisplayRecords"] = total
results["aaData"] = ds
self.write(json.dumps(results, cls=JsonEncoder))
示例3: post
def post(self, *args, **kwargs):
#记录机器访问数据
params_ = self.wrap_params_to_dict()
sn = params_.get("SN")
sf = SessionFactory.new()
machine = sf.query(ValidWorkMachine).filter(ValidWorkMachine.sn == sn).limit(1).scalar()
table = params_.get("table")
if table == "OPERLOG":
op_stamp = params_.get("OpStamp")
if op_stamp and machine:
machine.opstamp = Utils.parse_int(op_stamp)
sf.commit()
self.write("OK")
elif table == "ATTLOG":
stamp = params_.get("Stamp")
if stamp and machine:
stamp = Utils.parse_int(stamp)
machine.stamp = stamp
sf.commit()
if stamp and stamp > 0:
records_text = self.request.body
if records_text:
records_text = records_text.decode("utf-8")
records = list()
for line in records_text.split("\n"):
items = line.split("\t")
if len(items) >= 2:
records.append((items[0], items[1]))
for r in records:
archives_id = r[0]
touch_time = datetime.strptime(r[1], "%Y-%m-%d %H:%M:%S")
self.detect_chkon_status(archives_id, touch_time)
self.write("OK")
示例4: finger_tpl_save
def finger_tpl_save(self):
index = Utils.parse_int(self.param("index"))
tpl = self.param("tpl")
archives_id = Utils.parse_int(self.param("archives_id"))
sf = SessionFactory.new()
obj = sf.query(ValidWorkFingerTemplate) \
.filter(ValidWorkFingerTemplate.archives_id == archives_id) \
.filter(ValidWorkFingerTemplate.finger_index == index).limit(1).scalar()
machines_sn = sf.query(ValidWorkMachine.sn).all()
machines_sn = [sn[0] for sn in machines_sn]
name = sf.query(Archives.name).filter(Archives.id == archives_id).limit(1).scalar()
for sn in machines_sn:
ValidWorkHelper.push_user_fp_to_machine(sn, archives_id, name, index, tpl)
if obj:
obj.tpl = tpl
sf.commit()
return ["success"]
else:
if archives_id:
sf = SessionFactory.new()
obj = ValidWorkFingerTemplate()
obj.card_no = ""
obj.finger_index = index
obj.tpl = tpl
obj.archives_id = archives_id
sf.add(obj)
sf.commit()
return ["success"]
return ["failure"]
示例5: post
def post(self, *args, **kwargs):
"""
do login action
:param args:
:param kwargs:
"""
login_id = self.get_argument("login_id")
login_pwd = self.get_argument("login_pwd")
if not login_id or not login_pwd:
self.redirect(self.get_login_url())
cnn = SessionFactory.new()
if Utils.is_email(Utils.trim(login_id)):
rows = cnn.query(Account.id, Archives.name).outerjoin(Archives, Account.archives_id == Archives.id) \
.filter(Archives.email == login_id).filter(Account.login_pwd == Utils.md5(login_pwd)) \
.filter(Account.enabled == 1).limit(1).all()
if len(rows) > 0:
id_ = rows[0][0]
name = rows[0][1]
self.set_secure_cookie(IRequest.__key_account_id__, "%i" % id_)
self.set_secure_cookie(IRequest.__key_account_name__, name)
Login.update_last_login_datetime(id_)
else:
rows = cnn.query(Account.id, Archives.name).outerjoin(Archives, Account.archives_id == Archives.id) \
.filter(Account.login_name == login_id).filter(Account.login_pwd == Utils.md5(login_pwd)) \
.filter(Account.enabled == 1).limit(1).all()
if len(rows) > 0:
id_ = rows[0][0]
name = rows[0][1]
self.set_secure_cookie(IRequest.__key_account_id__, "%i" % id_)
self.set_secure_cookie(IRequest.__key_account_name__, name)
Login.update_last_login_datetime(id_)
self.redirect("/workbench/dashboard")
示例6: delete
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))
示例7: list
def list(self, kw, start, limit, http_req):
sf = SessionFactory.new()
subq = sf.query(Archives.id, Archives.name).subquery()
q = sf.query(ValidWorkAskForLeave, Archives.name, subq.c.name.label("creator"))\
.join(Archives, ValidWorkAskForLeave.archives_id == Archives.id)\
.outerjoin(subq, ValidWorkAskForLeave.creator == subq.c.id)
if kw:
q = q.filter(Archives.name.contains(kw))
dataset = q.order_by(ValidWorkAskForLeave.id.desc()).offset(start).limit(limit).all()
items = list()
for row in dataset:
ot = row[0]
name = row[1]
creator = row[2]
item = dict()
item["id"] = ot.id
item["kind"] = ot.kind
item["ask_date"] = Utils.format_date(ot.ask_date)
item["start_datetime"] = Utils.format_datetime_short(ot.start_datetime)
item["end_datetime"] = Utils.format_datetime_short(ot.end_datetime)
item["create_datetime"] = Utils.format_datetime_short(ot.create_datetime)
item["name"] = name
item["creator"] = creator
items.append(item)
return items
示例8: get
def get(self, *args, **kwargs):
self.set_header("Content-Type", "text/plain;charset=utf-8")
params_ = self.wrap_params_to_dict()
sn = params_.get("SN")
ip = self.request.remote_ip
#记录当前机器信息
sf = SessionFactory.new()
obj = sf.query(ValidWorkMachine).filter(ValidWorkMachine.sn == sn).limit(1).scalar()
if not obj:
m = ValidWorkMachine()
m.sn = sn
m.ip = ip
m.last_connect_time = Utils.current_datetime()
sf.add(m)
sf.commit()
else:
obj.ip = ip
obj.last_connect_time = Utils.current_datetime()
sf.commit()
#取出一条命令下发给机器执行
cmd = sf.query(ValidWorkCommands.id, ValidWorkCommands.cmd) \
.filter(ValidWorkCommands.sn == sn) \
.order_by(asc(ValidWorkCommands.id)).limit(1).scalar()
if cmd:
self.write("C:%s:%s" % (cmd[0], cmd[1]))
pass
示例9: list_timeblocks
def list_timeblocks():
sf = SessionFactory.new()
rows = sf.query(ValidWorkTimeBlock.id, ValidWorkTimeBlock.name, ValidWorkTimeBlock.start_time,
ValidWorkTimeBlock.end_time).all()
items = list()
for row in rows:
items.append((row[0], row[1], Utils.format_time(row[2]), Utils.format_time(row[3])))
return items
示例10: before_add
def before_add(self, entity_obj, sf, req):
num = sf.query(func.count(ValidWorkTimeBlock.id)).filter(ValidWorkTimeBlock.name == entity_obj.name).scalar()
if num > 0:
return "名称已经存在!"
num = sf.query(func.count(ValidWorkTimeBlock.id)) \
.filter(cast(ValidWorkTimeBlock.start_time, Time) == Utils.format_time(entity_obj.start_time)) \
.filter(cast(ValidWorkTimeBlock.end_time, Time) == Utils.format_time(entity_obj.end_time)).scalar()
if num > 0:
return "班次/时间段已经存在!"
return ""
示例11: get
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([""]))
示例12: post
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()))
示例13: task_assign
def task_assign(self):
archives_id = Utils.parse_int(self.param("id"))
task_id = Utils.parse_int(self.param("st_id"))
if archives_id and task_id:
sf = SessionFactory.new()
usr = sf.query(Archives).get(archives_id)
if usr:
usr.validworkscheduletasks = []
task = sf.query(ValidWorkScheduleTask).get(task_id)
usr.validworkscheduletasks.append(task)
sf.commit()
return ["success"]
return ["failure"]
示例14: count
def count(self, search_text, http_req):
current_date = None
if not current_date:
current_date = Utils.format_date(Utils.current_datetime())
sf = SessionFactory.new()
subq = sf.query(Term.name.label("term_name"), TermTaxonomy.id).filter(TermTaxonomy.term_id == Term.id).subquery()
q = sf.query(func.count(ValidWorkCheckOn.id))\
.join(Archives, ValidWorkCheckOn.archives_id == Archives.id)\
.outerjoin(subq, subq.c.id == Archives.org_id)
if search_text:
q = q.filter(Archives.name.contains(search_text))
q = q.filter(cast(ValidWorkCheckOn.valid_start_time, Date) == current_date)
return q.scalar()
示例15: pack_client
def pack_client(self):
user_id = self.get_current_user()
root_path = self.get_webroot_path()
download_path = root_path + "/download/validwork/"
Utils.mkdirs(download_path)
client_zip_name = download_path + Utils.md5("%i_client" % user_id) + ".zip"
key_file_name = download_path + Utils.md5("%i_keyfile" % user_id)
ip_file_name = download_path + "ip.txt"
exe_file_name = download_path + "FingerTemplateHelper.exe"
libcurl = download_path + "libcurl.dll"
zlib1 = download_path + "zlib1.dll"
if os.path.exists(key_file_name):
os.remove(key_file_name)
key = self.kengen()
Utils.text_write(key_file_name, [key], "")
if not os.path.exists(ip_file_name):
Utils.text_write(ip_file_name, [self.request.host], "")
if os.path.exists(client_zip_name):
os.remove(client_zip_name)
f = ZipFile(client_zip_name, "w")
self.compress(f, ip_file_name, "ip.txt")
self.compress(f, key_file_name, "temp.key")
self.compress(f, exe_file_name, "指纹采集助手.exe")
self.compress(f, libcurl, "libcurl.dll")
self.compress(f, zlib1, "zlib1.dll")
f.close()
return client_zip_name