本文整理汇总了Python中sys2do.model.DBSession.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.rollback方法的具体用法?Python DBSession.rollback怎么用?Python DBSession.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys2do.model.DBSession
的用法示例。
在下文中一共展示了DBSession.rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: out_note_delete
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [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"))
示例2: save_update
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def save_update(self):
id = _g('id', None)
if not id :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
return redirect(url_for('.view'))
obj = DBSession.query(Customer).get(id)
if not obj :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view'))
try:
fields = ['no', 'name', 'display_name', 'province_id', 'city_id',
'address', 'contact_person', 'mobile', 'phone', 'email', 'note_id', 'remark']
old_info = obj.serialize(fields) # to used for the history log
for f in fields:
setattr(obj, f, _g(f))
#handle the file upload
old_attachment_ids = map(lambda (k, v) : v, _gp("old_attachment_"))
old_attachment_ids.extend(multiupload())
obj.attachment = old_attachment_ids
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
# return redirect(url_for('.view',id=obj.id))
new_info = obj.serialize(fields)
change_result = obj.compare(old_info, new_info)
obj.insert_system_logs(change_result)
except:
_error(traceback.print_exc())
DBSession.rollback()
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(url_for('.view', action = "view", id = obj.id))
示例3: save_new
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def save_new(self):
params = {
"name" : _g('name'),
"address" : _g('address'),
"manager" : _g('manager'),
"remark" : _g('remark'),
"parent_id" : _g('parent_id'),
}
try:
obj = InventoryLocation(**params)
DBSession.add(obj)
DBSession.flush()
if params['parent_id']:
parent = DBSession.query(InventoryLocation).get(obj.parent_id)
obj.full_path = "%s%s" % (parent.full_path or '', params['name'])
obj.full_path_ids = "%s|%s" % (parent.full_path_ids, obj.id)
else:
obj.full_path = params['name']
obj.full_path_ids = obj.id
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
except:
DBSession.rollback()
_error(traceback.print_exc())
return redirect(self.default())
示例4: init
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def init():
try:
print "create tables"
metadata.drop_all(engine, checkfirst = True)
metadata.create_all(engine)
print "insert default value"
DBSession.add(User(name = 'demo', password = 'demo'))
for code in range(9121, 9140):
DBSession.add(NFCData(authcode = unicode(code), company = 'RoyalDragonVodka',
serial = code - 9000,
))
f = open('country.txt', 'r')
cs = f.readlines()
f.close()
for c in cs:
n, c, iso = c.split('|')
DBSession.add(MLocation(name = n, iso_code = iso, code = c))
DBSession.commit()
print "finish init!"
except:
traceback.print_exc()
DBSession.rollback()
示例5: save_new
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def save_new(self):
try:
obj = Customer(
no = _g('no'),
name = _g('name'),
display_name = _g('display_name'),
province_id = _g('province_id'),
city_id = _g('city_id'),
address = _g('address'),
contact_person = _g('contact_person'),
mobile = _g('mobile'),
phone = _g('phone'),
email = _g('email'),
remark = _g('remark'),
note_id = _g('note_id'),
# payment_id = _g('payment_id'),
)
DBSession.add(obj)
obj.attachment = multiupload()
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'view', id = obj.id))
except:
_error(traceback.print_exc())
DBSession.rollback()
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(url_for('.view'))
示例6: save_events
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def save_events():
uid = request.values.get("uid", None)
did = request.values.get("did", None)
d = request.values.get("d", None)
t = request.values.get("t", None)
if not uid or not did or not d or not t:
return jsonify({"success": False, "message": "The required info is not supplied !"})
format_date = lambda v: "-".join([v[:4], v[4:6], v[-2:]])
try:
e = Events(user_id=uid, doctor_id=did, date=d, time=t, remark=request.values.get("remark", None))
DBSession.add(e)
doctor = DBSession.query(DoctorProfile).get(did).getUserProfile()
m = Message(
subject=u"Booking request submit",
user_id=session["user_profile"]["id"],
content=u"%s make a booking with doctor %s at %s , %s."
% (session["user_profile"]["name"], doctor["name"], t, format_date(d)),
)
DBSession.add(m)
DBSession.commit()
return jsonify({"success": True, "message": "Save your request successfully !", "event_time": e.time})
except:
DBSession.rollback()
app.logger.error(traceback.format_exc())
return jsonify({"success": False, "message": "Error occur when submiting the request !"})
示例7: upload
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def upload(self, file_name):
try:
f = self.request.files[file_name][0]
original_fname = f['filename']
extension = os.path.splitext(original_fname)[1].lower()
fname = Date2Text(dateTimeFormat = "%Y%m%d%H%M%S", defaultNow = True) + ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))
final_filename = fname + extension
d = os.path.join(self.application.settings.get("static_path"),
self.application.settings.get("upload_relative_path"))
if not os.path.exists(d):
os.makedirs(d)
full_path = os.path.join(d, final_filename)
output_file = open(full_path, 'wb')
output_file.write(f['body'])
output_file.close()
DBSession.add(Attachment(name = final_filename, path = full_path, original_name = original_fname,
url = self.static_url("/".join([self.application.settings.get("upload_relative_path"), final_filename]))))
DBSession.commit()
return (0, original_fname, final_filename, full_path)
except:
DBSession.rollback()
logging.error(traceback.print_exc())
return (1, None, None, None)
示例8: saveNewArticle
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def saveNewArticle(self):
appid, title, sub_title, validate_date, desc, content = _gs('appid', 'title', 'sub_title', 'validate_date', 'desc', 'content')
if not appid :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_WARNING)
return redirect(url_for('.view'))
if not title:
flash(MSG_NO_ENOUGH_PARAMS, MESSAGE_WARNING)
return redirect(url_for('.view', action = 'createArticle', appid = appid))
try:
article = AppArticle(
app_id = appid,
title = title,
sub_title = sub_title,
desc = desc,
content = content,
validate_date = validate_date,
)
DBSession.add(article)
DBSession.flush()
article.seq = article.id
DBSession.commit()
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for(".view", action = "listArticle", appid = appid))
except:
DBSession.rollback()
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
traceback.print_exc()
return redirect(url_for(".view", action = "listArticle", appid = appid))
示例9: saveNewApp
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [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'))
示例10: _save_new
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def _save_new(self):
try:
result = self.dbObj.save_new(self)
DBSession.commit()
self.flash("Save the record successfully!")
except Exception as e:
DBSession.rollback()
self.flash(getattr(e, "msg", None) or "This operation is not available now!")
self._new()
self.redirect("%s?action=view&id=%d" % (self.url_prefix, result.id))
示例11: ajax_change_flag
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def ajax_change_flag(self):
try:
ids = _g('order_ids', '').split("|")
flag = _g('flag')
type = _g('type')
for r in DBSession.query(OrderHeader).filter(OrderHeader.id.in_(ids)).order_by(OrderHeader.create_time):
if type == 'APPROVE':
r.approve = flag
if flag == '1': # approve
remark = u'%s 审核通过该订单。' % session['user_profile']['name']
else: # disapprove
remark = u'%s 审核不通过该订单。' % session['user_profile']['name']
elif type == 'PAID':
r.paid = flag
if flag == '1':
remark = u'%s 确认该订单为客户已付款。' % session['user_profile']['name']
else:
remark = u'%s 确认该订单为客户未付款。' % session['user_profile']['name']
elif type == 'SUPLLIER_PAID':
r.supplier_paid = flag
if flag == '1':
remark = u'%s 确认该订单为已付款予承运商。' % session['user_profile']['name']
else:
remark = u'%s 确认该订单为未付款予承运商。' % session['user_profile']['name']
elif type == 'ORDER_RETURN':
r.is_return_note = flag
if flag == '1':
remark = u'%s 确认该订单为客户已返回单。' % session['user_profile']['name']
else:
remark = u'%s 确认该订单为客户未返回单。' % session['user_profile']['name']
elif type == 'EXCEPTION':
r.is_exception = flag
if flag == '1':
remark = u'%s 标记该订单为异常。' % session['user_profile']['name']
else:
remark = u'%s 取消该订单的异常标记。' % session['user_profile']['name']
elif type == 'LESS_QTY':
r.is_less_qty = flag
if flag == '1':
remark = u'%s 标记该订单为少货。' % session['user_profile']['name']
else:
remark = u'%s 取消该订单的少货标记。' % session['user_profile']['name']
DBSession.add(SystemLog(
type = r.__class__.__name__,
ref_id = r.id,
remark = remark
))
DBSession.commit()
return jsonify({'code' : 0 , 'msg' : MSG_UPDATE_SUCC})
except:
_error(traceback.print_exc())
DBSession.rollback()
return jsonify({'code' : 1, 'msg' : MSG_SERVER_ERROR})
示例12: insert_system_logs
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def insert_system_logs(self, comare_result):
try:
_remark = [u"[%s]'%s' 修改为 '%s'" % (name, ov, nv) for (name, ov, nv) in comare_result['update']]
DBSession.add(SystemLog(
type = self.__class__.__name__,
ref_id = self.id,
remark = u"%s 修改该记录。%s" % (session['user_profile']['name'], ";".join(_remark))
))
DBSession.commit()
except:
DBSession.rollback()
_error(traceback.print_exc())
示例13: init
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def init():
try:
print "create tables"
metadata.drop_all(engine, checkfirst = True)
metadata.create_all(engine)
DBSession.add(User(email = '[email protected]', password = 'test'))
DBSession.add(User(email = '[email protected]', password = 'admin'))
DBSession.commit()
print "finish init!"
except:
traceback.print_exc()
DBSession.rollback()
示例14: vendor_input_save
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def vendor_input_save(self):
if not session.get('supplier_profile', None) or not session['supplier_profile'].get('id', None):
flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR)
return redirect(url_for('bpRoot.view', action = "index"))
header = DeliverHeader.get(_g('id'))
if not header :
flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'vendor_select'))
elif header.supplier_id != session['supplier_profile']['id']:
flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR)
return redirect(url_for('bpRoot.view', action = "index"))
if _g('type') == "IN_TRAVEL" :
new_status = IN_TRAVEL[0]
remark = u'货物在途。备注 :%s' % _g('remark')
elif _g('type') == "GOODS_ARRIVED" :
new_status = GOODS_ARRIVED[0]
remark = u'货物到达。备注 :%s' % _g('remark')
elif _g('type') == "GOODS_SIGNED" :
new_status = GOODS_SIGNED[0]
remark = u'货物签收。备注 :%s' % _g('remark')
else:
flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'vendor_select'))
try:
header.update_status(new_status)
for d in header.details:
d.order_detail.update_status(new_status)
# log = DeliverLog(deliver_header_id = header.id, remark = _g('remark'))
# DBSession.add(log)
DBSession.add(TransferLog(
refer_id = header.id,
transfer_date = dt.now().strftime(SYSTEM_DATETIME_FORMAT),
type = 1,
remark = remark
))
DBSession.commit()
except:
DBSession.rollback()
_error(traceback.print_exc())
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'vendor_select'))
else:
flash(MSG_SAVE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'vendor_select'))
示例15: delArticle
# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import rollback [as 别名]
def delArticle(self):
aid = _g('id')
if not aid :
flash(MSG_NO_ID_SUPPLIED, MESSAGE_WARNING)
return redirect(url_for('.view'))
try:
article = DBSession.query(AppArticle).get(aid)
article.active = 1
DBSession.commit()
flash(MSG_DELETE_SUCC, MESSAGE_INFO)
return redirect(url_for('.view', action = 'listArticle', appid = article.app_id))
except:
DBSession.rollback()
flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
return redirect(url_for('.view', action = 'updateArticle', id = aid))