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


Python DBSession.add方法代码示例

本文整理汇总了Python中dmirr.model.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dmirr.model.DBSession的用法示例。


在下文中一共展示了DBSession.add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import add [as 别名]
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     group = _h.get_group_by_name(kw.get('group_name', None))
     all_p = DBSession.query(Project).all()
     if not group:
         errors['group'] = 'Group does not exist!'
         
     s = Site()
     s.label = unicode(re.sub(' ', '_', kw['label']).lower())
     s.display_name = unicode(kw.get('display_name', None))
     s.desc = kw.get('desc', None)
     s.url = unicode(kw.get('url', None))
     s.contact_name = unicode(kw.get('contact_name', None))
     s.contact_email = unicode(kw.get('contact_email', None))
     s.sync_base_path = unicode(kw.get('sync_base_path', None))
     s.user = request.identity['user']
     s.group = group
 
     if len(errors) > 0:
         all_projects = [x for x in all_p if x not in s.projects]
         all_hosts = [x for x in request.identity['user'].hosts \
                         if x not in s.hosts]
         transaction.doom()
         return dict(page='site', errors=errors, site=s, 
                     all_projects=all_projects, all_hosts=all_hosts)
         
     DBSession.add(s)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/dashboard'))
开发者ID:jness,项目名称:dmirr,代码行数:32,代码来源:site.py

示例2: post

# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import add [as 别名]
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     project = _h.get_project_by_name(kw.get('project_label', None))
     if not project:
         errors['project'] = "Project does not exist"
     
     _h.protect_obj_modify(project)
         
     _existing_p = _h.get_product_by_name(kw.get('label', None))
     if _existing_p:
         errors['label'] = "%s already exists!" % kw.get('label', None)
         
     p = Product()
     p.label = unicode(re.sub(' ', '_', kw['label']).lower())
     p.display_name = unicode(kw.get('display_name', None))
     p.desc = kw.get('desc', None)
     
     if len(errors) > 0:
         return dict(errors=errors, project=project, product=p)
         
     p.project = project
     
     DBSession.add(p)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/product/new?project=%s' % kw['project_label']))
开发者ID:jness,项目名称:dmirr,代码行数:28,代码来源:product.py

示例3: post

# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import add [as 别名]
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     group = _h.get_group_by_name(kw.get('group_name', None))
     protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
     all_protocols = DBSession.query(SyncProtocol).all()
     
     if not group:
         errors['group'] = 'Group does not exist!'
     if not protocol:
         errors['sync_protocol'] = 'Sync Protocol does not exist!'
         
     p = Project()
     p.label = unicode(re.sub(' ', '_', kw['label']).lower())
     _label = p.label
     p.display_name = unicode(kw.get('display_name', None))
     p.desc = kw.get('desc', None)
     p.url = unicode(kw.get('url', None))
     p.user = request.identity['user']
     p.sync_base_path = unicode(kw.get('sync_base_path', None))
     p.sync_flags = unicode(kw.get('sync_flags', None))
     p.group = group
     p.sync_protocol = protocol
     
     if len(errors) > 0:
         transaction.doom()
         return dict(page="project", errors=errors, project=p,
                     all_protocols=all_protocols)
     DBSession.add(p)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/project/%s/edit' % _label))
开发者ID:jness,项目名称:dmirr,代码行数:33,代码来源:project.py

示例4: setup

# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import add [as 别名]
 def setup(self):
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
开发者ID:jness,项目名称:dmirr,代码行数:14,代码来源:__init__.py

示例5: _add_site_sync_path

# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import add [as 别名]
 def _add_site_sync_path(self, site_id, project_id, sync_path):
     s = DBSession.query(Site).filter_by(id=site_id).first()
     p = DBSession.query(Project).filter_by(id=project_id).first()
     alt = DBSession.query(SiteSyncPath).filter_by(site_id=s.id)\
           .filter_by(project_id=p.id).first()
     if alt:
         alt.sync_path = sync_path
         transaction.commit()
         return alt
 
     alt = SiteSyncPath()
     alt.site = s
     alt.project = p
     alt.sync_path = sync_path
     DBSession.add(alt)
     transaction.commit()
     return alt
开发者ID:jness,项目名称:dmirr,代码行数:19,代码来源:site.py

示例6: post

# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import add [as 别名]
 def post(self, **kw):
     if config['user_registration'] == 'closed':
         abort(500)
         
     errors = _h.get_validation_errors()
                   
     u = model.User()
     u.user_name = unicode(re.sub(' ', '_', kw['user_name']).lower())
     u.display_name = unicode(kw['display_name'])
     u.web_url = unicode(kw['web_url'])
     u.email_address = unicode(kw['email_address'])
     u.about = kw['about']
     u.agreed_to_terms = int(1)
     u.status = _h.status_by_name('PendingEmailVerification')
     u.password = kw['password']
     
     # add to the everyone group
     everyone = _h.group_by_name('dmirr_everyone')
     everyone.users.append(u)     
     
     msg = turbomail.Message(
         config['from_email'],
         u.email_address,
         "dMirr Email Verification"
         )
     u.verify_code = _h.gen_verification_code()
     _url = "%s/user/true_up?u=%s&vc=%s" % (config['base_url'], 
                                           u.user_name, u.verify_code)
     msg.plain = EMAIL_VERIFICATION_MSG % \
                 (u.display_name, _url, config['base_url'])
     
     db.add(u)
     transaction.commit()
     msg.send()
     flash(_('%s registration started, check email to complete.' \
             % kw['display_name']), 'info')
     redirect(url('/'))
开发者ID:jness,项目名称:dmirr,代码行数:39,代码来源:user.py


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