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


Python models.DBSession类代码示例

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


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

示例1: activate_iteration

def activate_iteration(context, request):
    docid = request.params.get('docid')
    if not docid:
        return view_iterations(context, request, validation_error=u'Missing document_id')

    #query = gdata.spreadsheet.service.CellQuery()

    #first take project names
    #query['min-col'] = '3'
    #query['max-col'] = '3'
    #query['min-row'] = '5'
    #cr_raw = get_cell_values(request, query)

    session = DBSession()

    #deactivate all CR
    #for cr in session.query(CustomerRequest):
    #    cr.active = False

    #activate selected CR
    #cr_ids = set([item for sublist in [a.split(',') for a in cr_raw] for item in sublist])
    #crs = session.query(CustomerRequest).filter(CustomerRequest.id.in_(cr_ids))
    #for cr in crs:
    #    cr.active = True

    gc = session.query(GlobalConfig).get(1)
    gc.active_iteration_url = docid

    return manage_iterations(context,request)
开发者ID:getpenelope,项目名称:por.gdata,代码行数:29,代码来源:views.py

示例2: password_reset

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,代码行数:28,代码来源:views.py

示例3: create_initial_application_acl

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,代码行数:27,代码来源:dashboard.py

示例4: get_user_by_email

def get_user_by_email(request, email):
    """
    This method search for user using his email address
    """
    session = DBSession()
    if not isinstance(email, basestring):
        return {
                'status:': False,
                'message': u'Email parameter must be a string!',
                }
    try:
        user = session.query(User).filter_by(email=email).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No user found in db for %s mail address' % email,
                }

    return {
            'status': True,
            'message': u'User found.',
            'email': user.email,
            'login': user.login,
            'openids': [x.openid for x in user.openids]
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:25,代码来源:api.py

示例5: get_user_by_openid

def get_user_by_openid(request, openid):
    """
    This method search for user using one of the possible user openids
    """
    session = DBSession()

    if not isinstance(openid, basestring):
        return {
                'status:': False,
                'message': u'Openid parameter must be a string!',
                }

    try:
        user = session.query(User).join('openids').filter_by(openid=openid).one()
    except orm_exc.NoResultFound:

        return {
                'status': False,
                'message': u'No user found in db for %s openid' % openid,
                }

    return {
            'status': True,
            'message': u'User found.',
            'email': user.email,
            'login': user.login,
            'openids': [x.openid for x in user.openids],
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:28,代码来源:api.py

示例6: get_project_by_name

def get_project_by_name(request, project_name):
    """
    This method search for project by name
    """
    session = DBSession()

    if not isinstance(project_name, basestring):
        return {
                'status:': False,
                'message': u'Project name parameter must be a string!',
                }

    try:
        project = session.query(Project).filter_by(name=project_name).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No project found in db for %s name' % project_name,
                }

    return {
            'status': True,
            'message': u'Project found.',
            'name': project.name,
            'id': project.id,
            'customer': project.customer.name,
            'applications': [x.name for x in project.applications],
            'customer_requests': [(x.id, x.name,) for x in project.customer_requests],
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:29,代码来源:api.py

示例7: get_customer_by_name

def get_customer_by_name(request, customer_name):
    """
    This method search for customer by name
    """
    session = DBSession()

    if not isinstance(customer_name, basestring):
        return {
                'status:': False,
                'message': u'Customer name parameter must be a string!',
                }

    try:
        customer = session.query(Customer).filter_by(name=customer_name).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No customer found in db for %s name' % customer_name,
                }

    return {
            'status': True,
            'message': u'Customer found.',
            'name': customer.name,
            'projects': [x.name for x in customer.projects],
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:26,代码来源:api.py

示例8: test_add_project

 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,代码行数:7,代码来源:test_tp.py

示例9: test_add_application_with_sa_to_project

 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,代码行数:8,代码来源:test_dashboard.py

示例10: test_project_creation_date

 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,代码行数:8,代码来源:test_dashboard.py

示例11: test_add_application_to_project

 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,代码行数:8,代码来源:test_dashboard.py

示例12: test_get_user_by_attribute

 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,代码行数:8,代码来源:test_api.py

示例13: test_get_user_by_openid

    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,代码行数:9,代码来源:test_api.py

示例14: test_get_customer_by_name

    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,代码行数:9,代码来源:test_api.py

示例15: autoregister

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,代码行数:10,代码来源:views.py


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