本文整理汇总了Python中tinyms.core.common.Utils.current_datetime方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.current_datetime方法的具体用法?Python Utils.current_datetime怎么用?Python Utils.current_datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinyms.core.common.Utils
的用法示例。
在下文中一共展示了Utils.current_datetime方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
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
示例2: post
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [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"]))
示例3: push_users_fp_to_machine
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
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()
示例4: push_user_fp_to_machine
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def push_user_fp_to_machine(sn, pin, name, fid, tpl):
create = r"DATA DEL_USER PIN=%i\r\nDATA USER PIN=%i\tName=%s\r\n" % (pin, pin, name)
update = r"DATA FP PIN=%i\tFID=%i\tTMP=%s\r\n" % (pin, fid, tpl)
sf = SessionFactory.new()
id_ = sf.query(ValidWorkCommands.id).filter(ValidWorkCommands.sn == sn).limit(1).scalar()
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()
sf.add_all([vwc, vwc1])
sf.commit()
示例5: add
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def add(self, http_req):
obj = ValidWorkAskForLeave()
http_req.wrap_entity(obj)
obj.creator = http_req.get_current_user()
obj.create_datetime = Utils.current_datetime()
sf = SessionFactory.new()
sf.add(obj)
sf.commit()
return obj.id
示例6: push_command_to_machine
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def push_command_to_machine(sn, cmd):
sf = SessionFactory.new()
id_ = sf.query(ValidWorkCommands.id).filter(ValidWorkCommands.sn == sn).limit(1).scalar()
vwc = ValidWorkCommands()
vwc.sn = sn
vwc.validworkmachine_id = id_
vwc.cmd = cmd
vwc.create_date = Utils.current_datetime()
sf.add(vwc)
sf.commit()
示例7: modify
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def modify(self, id_, http_req):
sf = SessionFactory.new()
obj = sf.query(ValidWorkAskForLeave).get(id_)
if obj:
http_req.wrap_entity(obj)
obj.creator = http_req.get_current_user()
obj.create_datetime = Utils.current_datetime()
sf.commit()
return ""
return "failure"
示例8: count
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
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()
示例9: list
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def list(self, search_text, start, limit, 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(ValidWorkCheckOn.id,
Archives.code,
Archives.name,
ValidWorkTimeBlock.name,
ValidWorkTimeBlock.start_time,
ValidWorkTimeBlock.end_time,
ValidWorkCheckOn.status_in,
ValidWorkCheckOn.status_out,
ValidWorkCheckOn.status_no_sign,
ValidWorkCheckOn.check_in_time,
ValidWorkCheckOn.check_out_time,
subq.c.term_name,
MinuteDiff(ValidWorkCheckOn.valid_start_time, ValidWorkCheckOn.valid_end_time).label("diff")
).select_from(ValidWorkCheckOn)\
.join(ValidWorkTimeBlock, ValidWorkCheckOn.time_block_id == ValidWorkTimeBlock.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.order_by(Archives.name).filter(cast(ValidWorkCheckOn.valid_start_time, Date) == current_date)
ds = q.offset(start).limit(limit).all()
items = list()
for row in ds:
obj = EmptyClass()
obj.id = row[0]
obj.code = row[1]
obj.name = row[2]
obj.tb_name = row[3]
obj.start_time = Utils.format_time(row[4])
obj.end_time = Utils.format_time(row[5])
obj.status_in = row[6]
obj.status_out = row[7]
obj.status_no_sign = row[8]
obj.check_in_time = Utils.format_time(row[9])
obj.check_out_time = Utils.format_time(row[10])
obj.org_name = row[11]
obj.no_work_timediff = row[12]
items.append(obj.__dict__)
return items
示例10: create
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def create(login_id, pwd, archives_id=None, enabled=0):
cnn = SessionFactory.new()
obj = Account()
obj.login_name = login_id
obj.login_pwd = Utils.md5(pwd)
obj.create_time = Utils.current_datetime()
obj.enabled = enabled
obj.archives_id = archives_id
cnn.add(obj)
cnn.flush()
default_role_id = Utils.parse_int(AppSettingHelper.get("s_usr_register_default_role_name", "0"))
if default_role_id > 0:
default_role = cnn.query(Role).get(default_role_id)
if default_role:
obj.roles.append(default_role)
cnn.commit()
return obj.id
示例11: detect_chkon_status
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def detect_chkon_status(self, archives_id, touch_time):
sf = SessionFactory.new()
obj = sf.query(ValidWorkCheckOn) \
.filter(ValidWorkCheckOn.archives_id == archives_id) \
.filter(ValidWorkCheckOn.valid_start_time <= touch_time) \
.filter(ValidWorkCheckOn.valid_end_time >= touch_time).limit(1).scalar()
if obj:
timeblock = sf.query(ValidWorkTimeBlock).get(obj.time_block_id)
if timeblock:
#探测用户状态
current_date = Utils.current_datetime().date()
#正常上班时间
work_start_time = datetime.combine(current_date, timeblock.start_time)
#正常下班时间
normal_out_time = datetime.combine(current_date, timeblock.end_time)
#正常上班打卡的开始时间(上班时间-正常上班打卡区间)
touchin_starttime = work_start_time - timedelta(minutes=timeblock.normal_in_space)
if touchin_starttime <= touch_time < work_start_time:
obj.check_in_time = touch_time
obj.status_in = 0
else:
#视为迟到的结束时间(上班时间+视为迟到打卡区间)
late_endtime = work_start_time + timedelta(minutes=timeblock.late_space)
if work_start_time <= touch_time <= late_endtime:
obj.status_in = 1
obj.check_in_time = touch_time
else:
#正常下班打卡的结束时间(下班时间+视为正常打卡区间)
touchout_endtime = normal_out_time + timedelta(minutes=timeblock.normal_out_space)
if normal_out_time < touch_time <= touchout_endtime:
obj.status_out = 0
obj.check_out_time = touch_time
else:
#视为早退的打卡开始时间(下班时间-视为早退打卡区间)
early_leave_starttime = normal_out_time - timedelta(minutes=timeblock.leave_early_space)
if early_leave_starttime <= touch_time <= normal_out_time:
obj.status_out = 1
obj.check_out_time = touch_time
pass
sf.commit()
示例12: update_last_login_datetime
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def update_last_login_datetime(id_):
cnn = SessionFactory.new()
a = cnn.query(Account).get(id_)
a.last_logon_time = Utils.current_datetime()
cnn.commit()
示例13: create
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def create(self):
account_name = self.param("account_name")
if not account_name:
return "AccountNameRequired"
email = self.param("email")
if not email:
return "EmailRequired"
pwd = self.param("pwd")
if not pwd:
return "PwdRequired"
agree = self.param("agree")
print(agree)
if not agree:
return "AgreeRequired"
re_pwd = self.param("re_pwd")
if pwd != re_pwd:
return "PwdNotSame"
sf = SessionFactory.new()
num = sf.query(func.count(Account.id)).filter(Account.login_name == account_name).scalar()
if num > 0:
return "AccountExists"
num = sf.query(func.count(Archives.id)).filter(Archives.email == email).scalar()
if num > 0:
return "EmailExists"
#create a person
length = len(str(sf.query(func.count(Archives.id)).scalar()))
max_length = AppSettingHelper.get("s_usr_code_fmt_length", "5")
prefix = AppSettingHelper.get("s_usr_code_prefix", "P")
if length > Utils.parse_int(max_length):
max_length = "%s" % (length + 1)
fmt = prefix + "%0" + max_length + "d"
p = Archives()
p.email = email
p.name = Utils.email_account_name(email)
p.join_date = Utils.current_datetime()
sf.add(p)
sf.flush()
p.code = fmt % p.id
u = Account()
u.login_name = account_name
u.login_pwd = Utils.md5(pwd)
u.create_time = Utils.current_datetime()
u.last_logon_time = Utils.current_datetime()
u.enabled = 1
u.archives_id = p.id
sf.add(u)
sf.flush()
default_role_id = Utils.parse_int(AppSettingHelper.get("s_usr_register_default_role_name", 0))
if default_role_id > 0:
default_role = sf.query(Role).get(default_role_id)
if default_role:
u.roles.append(default_role)
sf.commit()
self.request.set_secure_cookie(IRequest.__key_account_id__, "%i" % u.id)
self.request.set_secure_cookie(IRequest.__key_account_name__, email)
return "Success"
示例14: organization_of_work
# 需要导入模块: from tinyms.core.common import Utils [as 别名]
# 或者: from tinyms.core.common.Utils import current_datetime [as 别名]
def organization_of_work():
current_datetime = Utils.current_datetime()
#是否为法定节日
isholiday = ValidWorkSchedulerThread.is_holiday(Utils.format_date(current_datetime))
if isholiday:
return
sf = SessionFactory.new()
#标识-1的状态为旷工,这种情况是没有按指纹的,CheckOn 有效时间段结束时间已经过期的时候
updates = sf.query(ValidWorkCheckOn) \
.filter(or_(ValidWorkCheckOn.status_in == -1, ValidWorkCheckOn.status_out == -1)) \
.filter(ValidWorkCheckOn.valid_end_time < Utils.format_datetime(current_datetime)).all()
for row in updates:
row.status_no_sign = 1
sf.commit()
#列出所有考勤计划
tasks = sf.query(ValidWorkScheduleTask.id).all()
tasks = [task[0] for task in tasks]
for task_id in tasks:
#得到班次最小的时间点
#min_time = sf.query(ValidWorkTimeBlock.start_time) \
# .join(ValidWorkScheduleTask, ValidWorkTimeBlock.validworkscheduletasks) \
# .order_by(asc(ValidWorkTimeBlock.start_time)) \
# .filter(ValidWorkScheduleTask.id == task_id).limit(1).scalar()
#if min_time:
# #提前30分钟安排下一档工作
# min_datetime = datetime.combine(current_datetime.date(), min_time)
# start_datetime = min_datetime - timedelta(minutes=30)
# if start_datetime <= current_datetime <= min_datetime:
#当天是否已经安排完成
e = sf.query(func.count(ValidWorkCheckOn.id)) \
.filter(ValidWorkCheckOn.task_id == task_id) \
.filter(cast(ValidWorkCheckOn.valid_start_time, Date) == Utils.format_date(current_datetime)).scalar()
if e == 0:
#安排新的工作
#1,得到拥有此考勤计划的所有人员ID
usrs = sf.query(Archives.id).join(ValidWorkScheduleTask, Archives.validworkscheduletasks) \
.filter(ValidWorkScheduleTask.id == task_id).all()
usrs = [u[0] for u in usrs]
#2,得到此考勤计划的所有班次
time_blocks = sf.query(ValidWorkTimeBlock) \
.join(ValidWorkScheduleTask, ValidWorkTimeBlock.validworkscheduletasks) \
.filter(ValidWorkScheduleTask.id == task_id).all()
#3,批量插入CheckOn
workers_tb = list()
for usr_id in usrs:
for tb in time_blocks:
vwco = ValidWorkCheckOn()
vwco.archives_id = usr_id
vwco.task_id = task_id
vwco.time_block_id = tb.id
start = datetime.combine(current_datetime.date(), tb.start_time)
end = datetime.combine(current_datetime.date(), tb.end_time)
start = start - timedelta(minutes=tb.normal_in_space)
end = end + timedelta(minutes=tb.normal_out_space)
vwco.valid_start_time = start
vwco.valid_end_time = end
workers_tb.append(vwco)
pass
pass
pass
sf.add_all(workers_tb)
sf.commit()
pass
pass
pass