本文整理汇总了Python中qtools.model.Session.merge方法的典型用法代码示例。如果您正苦于以下问题:Python Session.merge方法的具体用法?Python Session.merge怎么用?Python Session.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtools.model.Session
的用法示例。
在下文中一共展示了Session.merge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __form_to_model
# 需要导入模块: from qtools.model import Session [as 别名]
# 或者: from qtools.model.Session import merge [as 别名]
def __form_to_model(self, form, model=None):
if not model:
model = SequenceGroupTag()
Session.add(model)
model.name = form['name']
model.notes = form['notes']
model.owner_id = form['owner_id']
Session.merge(model)
return model
示例2: upload_file
# 需要导入模块: from qtools.model import Session [as 别名]
# 或者: from qtools.model.Session import merge [as 别名]
def upload_file(self, id=None):
self.__setup_box2_code_context(id)
source = QLStorageSource(config)
basename = upload_basename(self.form_result['file'].filename)
errors = {}
existing_path = self.__file_name_query(c.box2.id, basename)
if existing_path and not self.form_result['file_id'] == existing_path.id:
# todo, if existing update path
errors = dict(file='File with this name already exists for this reader. Use the Update page.')
path = "%s_%s" % (int(round(time.time())), basename)
thefile = self.form_result['file'].file
filerec = self.__file_id_query(c.box2.id, self.form_result['file_id'])
new_record = False
if not filerec:
filerec = Box2File(box2_id=c.box2.id)
new_record = True
filerec.name = basename
filerec.deleted = False
filerec.path = path
filerec.updated = datetime.datetime.now()
filerec.description = self.form_result['description']
filerec.mime_type = guess_type(basename)[0] or 'text/plain'
if errors:
response = self._upload_base(id)
return h.render_bootstrap_form(response, errors=errors, error_formatters=h.tw_bootstrap_error_formatters)
try:
attachment_dir = self.__upload_file_dir(c.box2)
if not os.path.exists(attachment_dir):
os.mkdir(attachment_dir)
permanent_path = self.__upload_file_path(c.box2, path)
permanent_file = open(permanent_path, 'wb')
shutil.copyfileobj(thefile, permanent_file)
thefile.close()
permanent_file.close()
filerec.size = os.stat(permanent_path).st_size
if new_record:
Session.add(filerec)
else:
Session.merge(filerec)
Session.commit()
session['flash'] = 'File uploaded.'
write_success = True
except Exception, e:
session['flash'] = 'Could not upload file: %s' % str(e)
session['flash_class'] = 'error'
write_success = False