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


Python DBSession.add方法代码示例

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


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

示例1: create_initial_application_acl

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
def create_initial_application_acl(mapper, connection, target):
    if target.application_type == SVN:
        acl_rules = [
            ("internal_developer", "edit"),
            ("internal_developer", "view"),
            ("external_developer", "edit"),
            ("external_developer", "view"),
        ]
    else:
        acl_rules = [
            ("internal_developer", "view"),
            ("external_developer", "view"),
            ("secretary", "view"),
            ("secretary", "edit"),
        ]

    if target.application_type == "trac":
        acl_rules.append(("customer", "view"))

    for role_id, permission_name in acl_rules:
        acl = DBSession.query(ApplicationACL).get((target.id, role_id, permission_name))
        if not acl:
            acl = ApplicationACL(application_id=target.id, role_id=role_id, permission_name=permission_name)
            DBSession.add(acl)
        else:
            # XXX this should not happen.
            pass
开发者ID:getpenelope,项目名称:por.models,代码行数:29,代码来源:dashboard.py

示例2: test_add_project

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
 def test_add_project(self):
     project_name = u'A project'
     session = DBSession()
     project = Project(name=project_name)
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project).filter_by(name=project_name).first().name, 'A project')
开发者ID:getpenelope,项目名称:por.models,代码行数:9,代码来源:test_tp.py

示例3: password_reset

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
def password_reset(request):
    email = request.params.get('email')
    try:
        session = DBSession()
        user = DBSession.query(User).filter_by(email=email).one()
        ptoken = DBSession.query(PasswordResetToken).get(user.id)
        if not ptoken:
            ptoken = PasswordResetToken(user_id=user.id)
        token = str(uuid4())
        ptoken.token = token 
        session.add(ptoken)
    except NoResultFound:
        token = None

    if token:
#        settings = request.registry.settings
        mailer = get_mailer(request)
        headers = {"header": u'Password reset',
                   "message": u'Please click on the link bellow to reset your penelope account\'s password.',
                   "link": '%s/change_password?token=%s' % (request.application_url, token),
                   "action": 'Reset password'}
        message = Message(subject=u"Password reset request",
                          recipients=[email],
                          body=u'Password reset',
                          extra_headers={'X-MC-Template': 'general',
                                         'X-MC-MergeVars': json.dumps(headers)})
        mailer.send(message)
    return {'request': request, 'token': token}
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:30,代码来源:views.py

示例4: test_add_application_with_sa_to_project

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
 def test_add_application_with_sa_to_project(self):
     session = DBSession()
     project = Project(name=u'My project 1')
     application = Application(name=u'Trac')
     project.add_application(application)
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project).filter_by(name=u'My project 1').first().applications[0].name, u'Trac')
开发者ID:getpenelope,项目名称:por.models,代码行数:10,代码来源:test_dashboard.py

示例5: test_project_creation_date

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
 def test_project_creation_date(self):
     session = DBSession()
     project = Project(name=u'My first project A')
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project)\
                             .filter_by(name=u'My first project A')\
                             .first().creation_date.strftime('%Y%m%d'), datetime.now().strftime('%Y%m%d'))
开发者ID:getpenelope,项目名称:por.models,代码行数:10,代码来源:test_dashboard.py

示例6: test_get_user_by_attribute

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
 def test_get_user_by_attribute(self):
     session = DBSession()
     user = User(email=u'[email protected]')
     session.add(user)
     transaction.commit()
     #Get the user by email
     resp = self.proxy.get_user_by_email('[email protected]')
     self.assertEqual(resp['email'], u'[email protected]')
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:10,代码来源:test_api.py

示例7: test_add_duplicated_project

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
 def test_add_duplicated_project(self):
     session = DBSession()
     project = Project(name=u'My project A')
     session.add(project)
     project = Project(name=u'My project A')
     session.add(project)
     self.assertRaises(IntegrityError, transaction.commit)
     session.rollback()
开发者ID:getpenelope,项目名称:por.models,代码行数:10,代码来源:test_dashboard.py

示例8: test_add_application_to_project

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
 def test_add_application_to_project(self):
     session = DBSession()
     project = Project(name=u'My project 2')
     application = Application(name=u'Trac', api_uri='http://simple.api.uri')
     project.add_application(application)
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project).filter_by(name=u'My project 2').first().applications[0].name, u'Trac')
开发者ID:getpenelope,项目名称:por.models,代码行数:10,代码来源:test_dashboard.py

示例9: test_get_user_by_openid

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
    def test_get_user_by_openid(self):
        session = DBSession()
        user = User(email=u'[email protected]')
        user.add_openid(u'[email protected]')
        session.add(user)
        transaction.commit()

        resp = self.proxy.get_user_by_openid('[email protected]')
        self.assertTrue(u'[email protected]' in resp['openids'])
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:11,代码来源:test_api.py

示例10: test_get_customer_by_name

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
    def test_get_customer_by_name(self):
        customer_name = u'A rich customer'
        session = DBSession()
        customer = Customer(name=customer_name)
        session.add(customer)
        transaction.commit()

        resp = self.proxy.get_customer_by_name(customer_name)
        self.assertEqual(resp['name'], customer_name)
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:11,代码来源:test_api.py

示例11: autoregister

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
def autoregister(profile):
    session = DBSession()
    chars = string.letters + string.digits
    password = ''.join(choice(chars) for _ in range(9))
    user = User(fullname = profile.get('displayName'),
                email = profile.get('emails')[0])
    user.set_password(password)
    user.add_openid(profile.get('accounts')[0].get('username'))
    session.add(user)
    return user
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:12,代码来源:views.py

示例12: smartadd_submit

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
    def smartadd_submit(self):
        """
        Receives a line of smart-add and performs validation/insertion.
        """
        projects = dict(
                ('%s - %s' % (p.name, p.customer.name), p.id)
                for p in self.request.filter_viewables(DBSession.query(Project).filter(Project.active))
                )

        def ticket_provider(project_id):
            if project_id:
                project = DBSession.query(Project).get(project_id)
                return [
                        t['id']
                        for t in ticket_store.get_tickets_for_project(project=project,
                                                                      not_invoiced=True,
                                                                      request=self.request)
                        ]

        parser = SmartAddParser(unicode(self.request.body, 'utf8', 'ignore'),
                                projects=projects,
                                available_tickets=ticket_provider,
                                request=self.request)

        errors = parser.validation_errors()
        if errors:
            # XXX register appropriate exception handler
            return Response(' - '.join(errors), status_int=400)

        pte = parser.parsed_time_entry
        parsed_tickets = pte['tickets']
        ticket_summaries = []

        entry_durations = list(time_chunks(pte['hours'], len(parsed_tickets)))

        for parsed_ticket, duration in zip(parsed_tickets, entry_durations):
            date = pte.get('date') or datetime.date.today()

            te = TimeEntry(date = date,
                           start = pte['start'],
                           end = pte['start'],
                           description = pte['description'],
                           ticket = parsed_ticket,
                           project_id = pte['project_id'],
                           hours = duration,
                           )
            te.request = self.request #bind for user calculation
            DBSession.add(te)
            # retrieve ticket descriptions (another trip to the store..)
            ticket_summaries.append(
                    '#%s (%s)' % (te.ticket, ticket_store.get_ticket(self.request, te.project_id, te.ticket)[3]['summary'])
                )

        return Response(u'Added to ticket(s) %s' % ', '.join(ticket_summaries))
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:56,代码来源:smartadd.py

示例13: test_get_project_by_name

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
    def test_get_project_by_name(self):
        project_name = u'A nice project'
        customer_name = u'A good customer'
        session = DBSession()
        project = Project(name=project_name)
        customer = Customer(name=customer_name)
        customer.add_project(project)
        session.add(customer)
        transaction.commit()

        resp = self.proxy.get_project_by_name(project_name)
        self.assertEqual(resp['name'], project_name)
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:14,代码来源:test_api.py

示例14: test_project_modification_date

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
 def test_project_modification_date(self):
     project_name = u'C project'
     session = DBSession()
     project = Project(name=project_name)
     session.add(project)
     transaction.commit()
     project = session.query(Project).filter_by(name=project_name).first()
     old_date = project.modification_date
     project.name = u'A modified project'
     time.sleep(0.1)
     transaction.commit()
     project = session.query(Project).filter_by(name=u'A modified project').first()
     new_date = project.modification_date
     self.assertNotEqual(old_date, new_date)
开发者ID:getpenelope,项目名称:por.models,代码行数:16,代码来源:test_tp.py

示例15: security_save

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import add [as 别名]
    def security_save(self):
        context = self.context.get_instance()

        for acl in context.acl:
            DBSession.delete(acl)

        for checkbox_name in self.request.POST:
            role_id, permission_name = checkbox_name.split('.')
            acl = ApplicationACL(application_id=context.id,
                                 role_id=role_id,
                                 permission_name=permission_name)
            DBSession.add(acl)

        request = self.request
        return HTTPFound(location=request.fa_url(request.model_name, request.model_id, 'security'))
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:17,代码来源:application.py


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