本文整理汇总了Python中sys2do.model.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys2do.model.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compute_ratio
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def _compute_ratio(self, customer_id, province_id, city_id):
qty_ratio = ''
weight_ratio = ''
vol_ratio = ''
q1 = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0,
CustomerDiquRatio.customer_id == customer_id,
CustomerDiquRatio.province_id == province_id,
CustomerDiquRatio.city_id == city_id,
))
if q1.count() == 1:
t = q1.one()
qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio
else:
q2 = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0,
CustomerDiquRatio.customer_id == customer_id,
CustomerDiquRatio.province_id == province_id,
CustomerDiquRatio.city_id == None,
))
if q2.count() == 1:
t = q2.one()
qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio
else:
q3 = DBSession.query(City).filter(and_(City.active == 0, City.id == city_id))
if q3.count() == 1:
t = q3.one()
qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio
else:
q4 = DBSession.query(Province).filter(and_(Province.active == 0, Province.id == province_id))
if q4.count() == 1:
t = q4.one()
qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio
# try:
# t = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0,
# CustomerDiquRatio.customer_id == customer_id,
# CustomerDiquRatio.province_id == province_id,
# CustomerDiquRatio.city_id == city_id,
# )).one()
# qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio
# except:
# try:
# t = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0,
# CustomerDiquRatio.customer_id == customer_id,
# CustomerDiquRatio.province_id == province_id,
# CustomerDiquRatio.city_id == None,
# )).one()
# qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio
# except:
# try:
# c = DBSession.query(City).filter(and_(City.active == 0, City.id == city_id)).one()
# qty_ratio, weight_ratio, vol_ratio = c.qty_ratio, c.weight_ratio, c.vol_ratio
# except:
# try:
# p = DBSession.query(Province).filter(and_(Province.active == 0, Province.id == province_id)).one()
# qty_ratio, weight_ratio, vol_ratio = p.qty_ratio, p.weight_ratio, p.vol_ratio
# except: pass
return {'qty_ratio' : qty_ratio, 'weight_ratio' : weight_ratio, 'vol_ratio' : vol_ratio}
示例2: saveNewApp
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def saveNewApp(self):
appName, appDesc = _gs('appName', 'appDesc')
if not appName:
flash(MSG_NO_APP_NAME, MESSAGE_WARNING)
return redirect(url_for('.view', action = 'createApp'))
try:
DBSession.query(AppObject).filter(and_(AppObject.active == 0,
AppObject.name == appName)).one()
except:
try:
app = AppObject(name = appName, desc = appDesc)
DBSession.add(app)
DBSession.flush()
url = createApp(session['user_profile']['id'],
APP_FOLDER, APP_PACKAGE,
'app%s' % app.id, app.name)
if not url : raise Exception('App generation error!')
url = '%s%s' % (WEBSITE_ROOT, url)
imgFile = createQR(url)
if not imgFile : raise Exception('QR code generation error!')
DBSession.add(imgFile)
app.appfile = imgFile
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
self._updateAppInSession()
return redirect(url_for('.view'))
except:
DBSession.rollback()
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(url_for('.view'))
else:
flash(MSG_APP_NAME_DUPLICATED, MESSAGE_WARNING)
return redirect(url_for('.view', action = 'createApp'))
示例3: review
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def review(self):
id = _g('id') or None
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(self.default())
try:
header = DBSession.query(OrderHeader).get(id)
logs = []
logs.extend(header.get_logs())
try:
deliver_detail = DBSession.query(DeliverDetail).filter(and_(DeliverDetail.active == 0, DeliverDetail.order_header_id == header.id)).one()
deliver_heaer = deliver_detail.header
# for f in deliver_heaer.get_logs() : _info(f.remark)
logs.extend(deliver_heaer.get_logs())
except:
pass
logs = sorted(logs, cmp = lambda x, y: cmp(x.transfer_date, y.transfer_date))
return {
'header' : header ,
'transit_logs' : logs,
}
except:
_error(traceback.print_exc())
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(self.default())
示例4: permission
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def permission(self):
method = _g('m', 'LIST')
if method not in ['LIST', 'NEW', 'UPDATE', 'DELETE', 'SAVE_NEW', 'SAVE_UPDATE']:
flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR);
return redirect(url_for('.view', action = 'index'))
if method == 'LIST':
page = _g('page') or 1
objs = DBSession.query(Permission).filter(Permission.active == 0).order_by(Permission.name).all()
def url_for_page(**params): return url_for('bpAdmin.view', action = 'permission', m = 'LIST', page = params['page'])
records = paginate.Page(objs, page, show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page)
return render_template('admin/permission_index.html', records = records)
elif method == 'NEW':
groups = Group.all()
return render_template('admin/permission_new.html', groups = groups)
elif method == 'UPDATE':
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj = Permission.get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
gids = map(lambda v:v.id, obj.groups)
all_groups = Group.all()
return render_template('admin/permission_update.html', v = obj.populate(), gids = gids, all_groups = all_groups)
elif method == 'DELETE':
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj = Permission.get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj.active = 1
obj.groups = []
DBSession.commit()
flash(MSG_DELETE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'permission'))
elif method == 'SAVE_NEW':
obj = Permission.saveAsNew(request.values)
obj.groups = DBSession.query(Group).filter(Group.id.in_(_gl("gids"))).all()
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'permission'))
elif method == 'SAVE_UPDATE':
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj = Permission.get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'permission'))
obj.saveAsUpdate(request.values)
obj.groups = DBSession.query(Group).filter(Group.id.in_(_gl('gids'))).all()
obj.commit()
flash(MSG_UPDATE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'permission'))
示例5: out_note_delete
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def out_note_delete(self):
id = _g("id")
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for(".view", action = "out_note"))
try:
note = DBSession.query(InventoryOutNote).get(id)
note.active = 1
for d in note.details:
location_item = DBSession.query(InventoryLocationItem).filter(and_(InventoryLocationItem.active == 0,
InventoryLocationItem.location_id == d.location_id,
InventoryLocationItem.item_id == d.item_id)).with_lockmode("update").one()
if note.status == 1 : # the record is not approved
location_item.qty += d.qty
location_item.area += d.area
location_item.weight += d.weight
location_item.exp_qty += d.qty
location_item.exp_area += d.area
location_item.exp_weight += d.weight
DBSession.add(SystemLog(
type = InventoryOutNote.__class__.__name__,
ref_id = note.id,
remark = u"%s 删除该记录。" % (session['user_profile']['name'])
))
DBSession.commit()
flash(MSG_DELETE_SUCC, MESSAGE_INFO)
except:
_error(traceback.print_exc())
DBSession.rollback()
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(url_for(".view", action = "out_note"))
示例6: getDoctorDetail
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def getDoctorDetail():
fields = ["lang", "doctorID", "clinicID"]
if _check_params(fields) != 0:
return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING})
lang = _g("lang")
dp = DBSession.query(DoctorProfile).get(_g("doctorID"))
base_info = dp.getUserProfile()
c = DBSession.query(Clinic).get(_g("clinicID"))
latitude = longtitude = None
if c.coordinate:
latitude, longtitude = c.coordinate.split(",")
return jsonify(
{
"result": 1,
"data": {
"doctorID": dp.id,
"name": {"zh_HK": base_info["display_name_tc"], "zh_CN": base_info["display_name_sc"]}.get(
lang, base_info["display_name"]
),
"desc": dp.desc,
"tel": c.tel,
"address": {"zh_HK": c.address_tc, "zh_CN": c.address_sc}.get(lang, c.address),
"image": base_info["image_url"],
"mapLocationX": longtitude,
"mapLocationY": latitude,
"rating": dp.rating,
},
}
)
示例7: register
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def register():
fields = ["email", "password", "repassword"]
if _check_params(fields) != 0:
return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING})
email = _g("email")
password = _g("password")
repassword = _g("repassword")
if not email:
return jsonify({"result": 0, "msg": MSG_EMAIL_BLANK_ERROR})
if not password:
return jsonify({"result": 0, "msg": MSG_PASSWORD_BLANK_ERROR})
if password != repassword:
return jsonify({"result": 0, "msg": MSG_PASSWORD_NOT_MATCH})
try:
DBSession.query(User).filter(and_(User.active == 0, func.upper(User.email) == email.upper())).one()
return jsonify({"result": 0, "msg": MSG_EMAIL_EXIST})
except:
traceback.print_exc()
pass
display_name = _g("display_name") or email
try:
u = User(email=email, password=password, display_name=display_name)
DBSession.add(u)
DBSession.commit()
return jsonify({"result": 1, "msg": MSG_SAVE_SUCCESS, "id": u.id, "point": u.point})
except:
traceback.print_exc()
return jsonify({"result": 0, "msg": MSG_SERVER_ERROR})
示例8: barcode
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def barcode(self):
method = _g('m', 'LIST')
if method not in ['LIST', 'NEW', 'PRINT', 'SAVE_NEW']:
flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR);
return redirect(url_for('.view', action = 'index'))
DBObj = Barcode
index_page = 'admin/barcode_index.html'
new_page = 'admin/barcode_new.html'
print_page = 'admin/barcode_print.html'
action = 'barcode'
if method == 'LIST':
if _g('SEARCH_SUBMIT'): # come from search
values = {'page' : 1}
for f in ['value', 'ref_no', 'status', 'create_time_from', 'create_time_to'] :
values[f] = _g(f)
values['field'] = _g('field', None) or 'create_time'
values['direction'] = _g('direction', None) or 'desc'
else: #come from paginate or return
values = session.get('master_barcode_values', {})
if _g('page') : values['page'] = int(_g('page'))
elif 'page' not in values : values['page'] = 1
session['master_barcode_values'] = values
conditions = [DBObj.active == 0]
if values.get('value', None): conditions.append(DBObj.value.op('like')('%%%s%%' % values['value']))
if values.get('ref_no', None): conditions.append(DBObj.ref_no.op('like')('%%%s%%' % values['ref_no']))
if values.get('status', None): conditions.append(DBObj.status == values['status'])
if values.get('create_time_from', None): conditions.append(DBObj.create_time > values['create_time_from'])
if values.get('create_time_to', None): conditions.append(DBObj.create_time < '%s 23:59' % values['create_time_to'])
field = values.get('field', 'create_time')
if values.get('direction', 'desc') == 'desc':
result = DBSession.query(DBObj).filter(and_(*conditions)).order_by(desc(getattr(DBObj, field)))
else:
result = DBSession.query(DBObj).filter(and_(*conditions)).order_by(getattr(DBObj, field))
def url_for_page(**params): return url_for('bpAdmin.view', action = action, m = 'LIST', page = params['page'])
records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = 100, url = url_for_page)
return render_template(index_page, records = records, action = action, values = values)
elif method == 'NEW':
return render_template(new_page, action = action)
elif method == 'PRINT':
ids = _gl('ids')
records = DBSession.query(DBObj).filter(DBObj.id.in_(ids)).order_by(desc(DBObj.create_time))
return render_template(print_page, records = records)
elif method == 'SAVE_NEW':
qty = _g('qty')
records = [DBObj.getOrCreate(None, None, status = 1) for i in range(int(qty))]
DBSession.commit()
if _g('type') == 'CREATE':
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = action))
else:
return render_template(print_page, records = records)
示例9: profit
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def profit(self):
if _g('SEARCH_SUBMIT'): # come from search
values = {'page' : 1}
for f in [
'no', 'create_time_from', 'create_time_to', 'destination_province_id', 'destination_city_id',
'ref_no', 'deliver_no', 'supplier_id', 'payment_id', 'is_discount_return'
] :
values[f] = _g(f)
values['field'] = _g('field', None) or 'create_time'
values['direction'] = _g('direction', None) or 'desc'
else: # come from paginate or return
values = session.get('fin_profit_values', {})
if _g('page') : values['page'] = int(_g('page'))
elif 'page' not in values : values['page'] = 1
if not values.get('create_time_from', None) and not values.get('create_time_to', None):
values['create_time_to'] = dt.now().strftime("%Y-%m-%d")
values['create_time_from'] = (dt.now() - timedelta(days = 30)).strftime("%Y-%m-%d")
session['fin_profit_values'] = values
conditions = [OrderHeader.active == 0,
DeliverHeader.active == 0 , DeliverDetail.active == 0, DeliverHeader.id == DeliverDetail.header_id,
OrderHeader.id == DeliverDetail.order_header_id,
]
if values.get('create_time_from', None): conditions.append(OrderHeader.order_time > values['create_time_from'])
if values.get('create_time_to', None): conditions.append(OrderHeader.order_time < '%s 23:59' % values['create_time_to'])
if values.get('ref_no', None): conditions.append(OrderHeader.ref_no.op('like')('%%%s%%' % values['ref_no']))
if values.get('deliver_no', None): conditions.append(DeliverHeader.no.op('like')('%%%s%%' % values['deliver_no']))
if values.get('destination_province_id', None):
conditions.append(OrderHeader.destination_province_id == values['destination_province_id'])
dp = DBSession.query(Province).get(values['destination_province_id'])
destination_cites = dp.children()
else: destination_cites = []
if values.get('destination_city_id', None): conditions.append(OrderHeader.destination_city_id == values['destination_city_id'])
if values.get('supplier_id', None): conditions.append(DeliverHeader.supplier_id == values['supplier_id'])
if values.get('payment_id', None): conditions.append(OrderHeader.payment_id == values['payment_id'])
if values.get('is_discount_return', None): conditions.append(OrderHeader.is_discount_return == values['is_discount_return'])
# for the sort function
field = values.get('field', 'create_time')
if values.get('direction', 'desc') == 'desc':
result = DBSession.query(OrderHeader, DeliverHeader).filter(and_(*conditions))
else:
result = DBSession.query(OrderHeader, DeliverHeader).filter(and_(*conditions))
def url_for_page(**params): return url_for('bpFin.view', action = "profit", page = params['page'])
records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page)
return {
'values' : values ,
'records' : records,
'destination_cites' : destination_cites,
}
示例10: view_items
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def view_items(self):
id = _g('id')
w = DBSession.query(InventoryLocation).get(id)
ids = w.full_path_ids.split("|")
result = DBSession.query(InventoryItem, InventoryLocation).filter(and_(
InventoryItem.active == 0,
InventoryItem.location_id.in_(ids),
InventoryLocation.active == 0,
InventoryItem.location_id == InventoryLocation,
)).order_by(InventoryItem.create_time).all()
return {'result' : result , 'location' : w}
示例11: list_doctors
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def list_doctors():
id = request.values.get("id", None)
if not id:
dps = DBSession.query(DoctorProfile).filter(DoctorProfile.active == 0)
# dps = connection.DoctorProfile.find({'active':0})
data = [dp.populate() for dp in dps]
else:
c = DBSession.query(Clinic).get(id)
# c = connection.Clinic.one({'active':0, 'id':int(id)})
# data = [connection.DoctorProfile.one({'id':i}).populate() for i in c.doctors]
data = [i.populate() for i in c.doctors]
return {"doctors": data}
示例12: in_note
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def in_note(self):
if _g('SEARCH_SUBMIT'): # come from search
values = {'page' : 1}
for f in ['no', 'create_time_from', 'create_time_to', 'customer_id', 'location_id' ] :
values[f] = _g(f)
values['field'] = _g('field', None) or 'create_time'
values['direction'] = _g('direction', None) or 'desc'
else: # come from paginate or return
values = session.get('inventory_in_note_values', {})
if _g('page') : values['page'] = int(_g('page'))
elif 'page' not in values : values['page'] = 1
if not values.get('create_time_from', None) and not values.get('create_time_to', None):
values['create_time_to'] = dt.now().strftime("%Y-%m-%d")
values['create_time_from'] = (dt.now() - timedelta(days = 30)).strftime("%Y-%m-%d")
session['inventory_in_note_values'] = values
conditions = [InventoryInNote.active == 0]
if values.get('create_time_from', None): conditions.append(InventoryInNote.create_time > values['create_time_from'])
if values.get('create_time_to', None): conditions.append(InventoryInNote.create_time < '%s 23:59' % values['create_time_to'])
if values.get('no', None): conditions.append(InventoryInNote.no.op('like')('%%%s%%' % values['no']))
if values.get('customer_id', None):
conditions.append(InventoryInNote.customer_id == values['customer_id'])
if values.get('location_id', None):
conditions.extend([
InventoryNoteDetail.active == 0,
InventoryNoteDetail.type == 'IN',
InventoryNoteDetail.header_id == InventoryInNote.id,
InventoryNoteDetail.location_id == values['location_id'],
])
# for the sort function
field = values.get('field', 'create_time')
if values.get('direction', 'desc') == 'desc':
result = DBSession.query(InventoryInNote).filter(and_(*conditions)).order_by(desc(getattr(InventoryInNote, field)))
else:
result = DBSession.query(InventoryInNote).filter(and_(*conditions)).order_by(getattr(InventoryInNote, field))
def url_for_page(**params): return url_for('.view', action = "in_note", page = params['page'])
records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page)
root_locations = DBSession.query(InventoryLocation).filter(and_(InventoryLocation.active == 0,
InventoryLocation.parent_id == None)).order_by(InventoryLocation.name)
return {
'values' : values ,
'records' : records,
'locations' : root_locations,
}
示例13: out_note_save_update
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def out_note_save_update(self):
id = _g('id')
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for(".view", action = "out_note"))
obj = DBSession.query(InventoryOutNote).get(id)
for f in ['customer_id', 'so', 'po', 'dn', 'ref', 'remark' ] : setattr(obj, f, _g(f))
total_qty = total_weight = total_area = 0
details_mapping = {}
for d in obj.details : details_mapping['%s' % d.id] = d
for qk, qv in _gp("qty_"):
id = qk.split("_")[1]
if id not in details_mapping : continue
d = details_mapping[id]
qty = self._p(_g('qty_%s' % id), int, 0)
weight = self._p(_g('weight_%s' % id), float, 0)
area = self._p(_g('area_%s' % id), float, 0)
total_qty += qty
total_area += area
total_weight += weight
if obj.status != 2:
# update the locaion-item relation
t = DBSession.query(InventoryLocationItem).filter(and_(InventoryLocationItem.location_id == d.location_id,
InventoryLocationItem.item_id == d.item_id)).with_lockmode("update").one()
if obj.status == 1: # if the record is approved,update the real qty/weight/area
t.qty -= qty - d.qty
t.weight -= weight - d.weight
t.area -= area - d.area
t.exp_qty -= qty - d.qty
t.exp_weight -= weight - d.weight
t.exp_area -= area - d.area
d.qty = qty
d.weight = weight
d.area = area
obj.qty = total_qty
obj.area = total_area
obj.weight = total_weight
DBSession.commit()
flash(MSG_UPDATE_SUCC, MESSAGE_INFO)
return redirect(url_for(".view", action = "out_note_review", id = obj.id))
示例14: isHoliday
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def isHoliday(clz, d):
if isinstance(d, (str, unicode)):
try:
year, month, day = d[:10].split('-')
DBSession.query(clz).filter(and_(clz.year == year, clz.month == month, clz.day == day)).one()
return True
except:
pass
elif isinstance(d, (datetime.datetime, datetime.date)):
try:
DBSession.query(clz).filter(and_(clz.year == d.year, clz.month == d.month, clz.day == d.day)).one()
return True
except:
pass
return False
示例15: _compute_day
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import query [as 别名]
def _compute_day(self, province_id, city_id):
estimate_day = ''
if city_id:
c = DBSession.query(City).get(city_id)
if c.shixiao:
estimate_day = (dt.now() + timedelta(days = c.shixiao)).strftime(SYSTEM_DATE_FORMAT)
else:
p = DBSession.query(Province).get(province_id)
if p.shixiao:
estimate_day = (dt.now() + timedelta(days = p.shixiao)).strftime(SYSTEM_DATE_FORMAT)
elif province_id:
p = DBSession.query(Province).get(province_id)
if p.shixiao:
estimate_day = (dt.now() + timedelta(days = p.shixiao)).strftime(SYSTEM_DATE_FORMAT)
return {'day' : estimate_day}