当前位置: 首页>>代码示例>>Python>>正文


Python Session.merge方法代码示例

本文整理汇总了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
开发者ID:v-makarenko,项目名称:vtoolsmq,代码行数:12,代码来源:assay_group.py

示例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
开发者ID:v-makarenko,项目名称:vtoolsmq,代码行数:57,代码来源:box2.py


注:本文中的qtools.model.Session.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。