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


Python ptah.get_session函数代码示例

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


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

示例1: test_join_unvalidated

    def test_join_unvalidated(self):
        import ptahcrowd
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.registration import Registration

        user = CrowdUser(username='username', email='email')
        ptah.get_session().add(user)
        ptah.get_session().flush()

        CROWD = ptah.get_settings(ptahcrowd.CFG_ID_CROWD)
        CROWD['allow-unvalidated'] = False

        request = self.make_request(
            POST = {'username': 'test',
                    'email': '[email protected]',
                    'password': '12345',
                    'confirm_password': '12345'})
        form = Registration(None, request)
        form.update_form()
        res = form.register_handler()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], 'http://example.com')

        user = ptah.auth_service.get_principal_bylogin('[email protected]')
        self.assertIsInstance(user, CrowdUser)
        self.assertEqual(user.username, 'test')

        self.assertIn('Validation email has been sent.',
                      request.render_messages())
开发者ID:djedproject,项目名称:ptahcrowd,代码行数:30,代码来源:test_join.py

示例2: test_join

    def test_join(self):
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.registration import Registration

        user = CrowdUser(username='username', email='email')
        ptah.get_session().add(user)
        ptah.get_session().flush()

        request = self.make_request(
            POST = {'username': 'test',
                    'email': '[email protected]',
                    'password': '12345',
                    'confirm_password': '12345'})
        request.environ['HTTP_HOST'] = 'example.com'

        form = Registration(None, request)
        form.update_form()
        res = form.register_handler()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'],
                         'http://example.com/login-success.html')

        user = ptah.auth_service.get_principal_bylogin('[email protected]')
        self.assertIsInstance(user, CrowdUser)
        self.assertEqual(user.name, 'test')
开发者ID:djedproject,项目名称:ptahcrowd,代码行数:26,代码来源:test_join.py

示例3: test_sqla_table_editrec_remove

    def test_sqla_table_editrec_remove(self):
        from ptah.manage.sqla import SQLAModule, EditRecord

        rec = TestSqlaModuleTable()
        rec.name = 'Test record'
        ptah.get_session().add(rec)
        ptah.get_session().flush()

        rec_id = rec.id

        mod = SQLAModule(None, DummyRequest())
        table = mod['psqla-test_sqla_table']

        rec = table[rec_id]

        request = self.make_request(
            POST={'form.buttons.remove': 'Remove'})

        form = EditRecord(rec, request)
        form.csrf = False
        res = form()

        self.assertIn('Table record has been removed.',
                      request.render_messages())
        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '..')

        rec = ptah.get_session().query(TestSqlaModuleTable).filter(
            TestSqlaModuleTable.id == rec_id).first()
        self.assertIsNone(rec, None)
开发者ID:djedproject,项目名称:ptah,代码行数:30,代码来源:test_sqla.py

示例4: test_model_edit_node

    def test_model_edit_node(self):
        from ptahcms.manage.model import ModelModule, EditRecord

        content = Content2()
        content.title = 'Content test'

        Session = ptah.get_session()
        Session.add(content)
        Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content2'][rowid]

        form = EditRecord(
            model, DummyRequest(
                POST={'title': 'Content', 'form.buttons.modify': 'Modify'}))
        form.csrf = False
        form.update()

        self.assertIn("Model record has been modified.",
                      ptah.view.render_messages(form.request))
        transaction.commit()

        Session = ptah.get_session()
        content = Session.query(Content2) \
            .filter(Content2.__id__ == rowid).first()
        self.assertEqual(content.title, 'Content')
开发者ID:djedproject,项目名称:ptahcms,代码行数:30,代码来源:test_model.py

示例5: _create_content

    def _create_content(self):
        import ptahcms

        factory = ptahcms.ApplicationFactory(
            ApplicationRoot, '/test', 'root', 'Root App')
        self.factory = factory

        class MyContent(ptahcms.Content):
            __mapper_args__ = {'polymorphic_identity': 'mycontent'}
            __uri_factory__ = ptah.UriFactory('test')

        root = factory()

        folder = MyContent(
            __name__ = 'folder',
            __parent__ = root,
            __path__ = '%sfolder/'%root.__path__)
        self.folder_uri = folder.__uri__

        content = MyContent(
            __name__ = 'content',
            __parent__ = folder,
            __path__ = '%scontent/'%folder.__path__)
        self.content_uri = content.__uri__

        ptah.get_session().add(folder)
        ptah.get_session().add(content)
        transaction.commit()
开发者ID:djedproject,项目名称:ptahcms,代码行数:28,代码来源:test_traverser.py

示例6: verify_handler

    def verify_handler(self):
        data, errors = self.extract()

        if errors:
            self.message(errors, 'form-error')
            return

        entry = self.entry
        request = self.request
        new_user = False
        email = data['email']

        user = self.session.query(ptahcrowd.CrowdUser).filter(
            ptahcrowd.CrowdUser.email == email).first()
        if user is None:
            new_user = True

            # create user
            tinfo = ptahcrowd.get_user_type()

            user = tinfo.create(
                name=entry.name,
                login=email,
                email=email,
                password=entry.access_token)
            tinfo.add(user)

            # fixme: temporary
            ptah.get_session().flush()

            uri = user.__uri__
            entry.uri = uri
            entry.email = email
        else:
            uri = user.__uri__

        data = {'uri': uri,
                'email': email,
                'uid': entry.uid}

        t = ptah.token.service.generate(TOKEN_TYPE, json.dumps(data))
        template = VerifyTemplate(entry, request, email=email, token=t)
        template.send()

        # login
        if new_user:
            self.message('Email verification email has been sent.')
            cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, request.registry)
            if cfg['validation']:
                if cfg['allow-unvalidated']:
                    entry.uri = uri
                    return login(uri, request)
            else:
                entry.uri = uri
                return login(uri, request)
        else:
            self.message('User with this email already exists. '
                         'You have to verify email before you can login.')

        return HTTPFound(location=request.application_url)
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:60,代码来源:__init__.py

示例7: test_upgrade_several

    def test_upgrade_several(self):
        from ptah.migrate import revision, Version

        ptah.register_migration('test1', 'test1:path', 'Test migration')
        ptah.register_migration('test2', 'test2:path', 'Test migration')

        self.init_ptah()

        versions = dict((v.package, v.version_num)
                        for v in ptah.get_session().query(Version).all())

        rev1 = revision('test1')
        rev2 = revision('test2')

        sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'upgrade', 'test1', 'test2']

        migrate.main()

        self._reset_stdout()

        versions = dict((v.package, v.version_num)
                        for v in ptah.get_session().query(Version).all())

        self.assertIn('test1', versions)
        self.assertIn('test2', versions)
        self.assertEqual(versions['test1'], rev1)
        self.assertEqual(versions['test2'], rev2)
开发者ID:webmaven,项目名称:ptah,代码行数:27,代码来源:test_migrate.py

示例8: test_model_remove

    def test_model_remove(self):
        from ptahcms.manage.model import ModelModule, ModelView

        content = Content1()
        content.title = 'Content test'

        Session = ptah.get_session()
        Session.add(content)
        Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content1']

        form = ModelView(
            model, DummyRequest(
                POST=MultiDict(
                    list({'rowid':rowid,
                          'form.buttons.remove': 'Remove'}.items()))))
        form.csrf = False
        res = form.update()

        self.assertIsInstance(res, HTTPFound)

        transaction.commit()

        Session = ptah.get_session()
        rec = Session.query(Content1).filter(
            Content1.__id__ == rowid).first()
        self.assertIsNone(rec)
开发者ID:djedproject,项目名称:ptahcms,代码行数:32,代码来源:test_model.py

示例9: test_join_error

    def test_join_error(self):
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.registration import Registration

        user = CrowdUser(username='username', email='email')
        ptah.get_session().add(user)
        ptah.get_session().flush()

        request = self.make_request(
            POST = {'username': 'test',
                    'email': 'custom login',
                    'password': '12345',
                    'confirm_password': '123456'})

        form = Registration(None, request)
        form.update_form()

        data, errors = form.extract()
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].msg[0], 'Invalid email address')

        form.register_handler()
        self.assertIn('Please fix indicated errors.',
                      request.render_messages())

        request = self.make_request(
            POST = {'username': 'test',
                    'email': '[email protected]',
                    'password': '12345',
                    'confirm_password': '12345'})
        form = Registration(None, request)
        form.update_form()
        data, errors = form.extract()
        self.assertEqual(len(errors), 0)
开发者ID:ptahproject,项目名称:ptahcrowd,代码行数:34,代码来源:test_join.py

示例10: test_join

    def test_join(self):
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.registration import Registration

        user = CrowdUser(username='username', email='email')
        ptah.get_session().add(user)
        ptah.get_session().flush()

        class Stub(object):
            status = ''
            def send(self, frm, to, msg):
                Stub.status = 'Email has been sended'

        MAIL = ptah.get_settings(ptah.CFG_ID_PTAH)
        MAIL['mailer'] = Stub()

        request = self.make_request(
            POST = {'username': 'test',
                    'email': '[email protected]',
                    'password': '12345',
                    'confirm_password': '12345'})
        request.environ['HTTP_HOST'] = 'example.com'

        form = Registration(None, request)
        form.update_form()
        res = form.register_handler()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'],
                         'http://example.com/login-success.html')

        user = ptah.auth_service.get_principal_bylogin('[email protected]')
        self.assertIsInstance(user, CrowdUser)
        self.assertEqual(user.name, 'test')
开发者ID:ptahproject,项目名称:ptahcrowd,代码行数:34,代码来源:test_join.py

示例11: enableUser

def enableUser():
    email = sys.argv[1]
    ploud_config.initializeConfig()
    dsn = PLOUD.dsn
    models.initialize_sql(dsn)
    config = Configurator()
    config.manager.push({'registry': config.registry, 'request': None})

    conn = ploud_config.PLOUD_POOL.getconn()
    cursor = conn.cursor()

    cursor.execute("SELECT email FROM waitinglist "
                   "WHERE completed = %s and email=%s",(False,email))

    row = cursor.fetchone()
    if row is None:
        print "Can't find email: %s"%email
        return

    transaction.begin()
    password = ''.join(
        [random.choice(ALLOWED_SITE_NAME_CHARS) for i in range(8)])
    user = models.User(email, password)
    user.type = 0
    token = user.token
    ptah.get_session().add(user)
    print email, token
    signup.send_activation(email, token)

    cursor.execute("UPDATE waitinglist SET completed = %s WHERE email=%s",
                   (True, email))
    cursor.close()
    conn.commit()
    transaction.commit()
开发者ID:enfold,项目名称:ploud.frontend,代码行数:34,代码来源:waitinglist.py

示例12: test_sqla_table_editrec_basics

    def test_sqla_table_editrec_basics(self):
        from ptah.manage.sqla import SQLAModule, EditRecord

        rec = TestSqlaModuleTable()
        rec.name = 'Test record'
        ptah.get_session().add(rec)
        ptah.get_session().flush()

        rec_id = rec.id

        request = self.make_request()

        mod = SQLAModule(None, request)
        table = mod['psqla-test_sqla_table']

        rec = table[rec_id]

        form = EditRecord(rec, request)
        form.update_form()

        self.assertEqual(form.label, 'record 1')
        self.assertEqual(form.form_content(),
                         {'name': 'Test record'})

        request = DummyRequest(
            POST={'form.buttons.cancel': 'Cancel'})

        form = EditRecord(rec, request)
        res = form()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '..')
开发者ID:djedproject,项目名称:ptah,代码行数:32,代码来源:test_sqla.py

示例13: test_sqla_table_view_model_nodes

    def test_sqla_table_view_model_nodes(self):
        from ptah.manage.sqla import SQLAModule

        rec = TestSqlaModuleContent(title='test')
        ptah.get_session().add(rec)
        ptah.get_session().flush()

        #uri = rec.__uri__
        #type_uri = rec.__type__.__uri__

        request = DummyRequest(params={'batch': 1})

        mod = SQLAModule(None, request)
        table = mod['psqla-ptah_nodes']

        render_view_to_response(table, request, '', False).text
        #self.assertIn(url_quote_plus(uri), res)
        #self.assertIn(url_quote_plus(type_uri), res)

        request = DummyRequest(params={'batch': 'unknown'})
        render_view_to_response(table, request, '', False).text
        #self.assertIn(url_quote_plus(uri), res)

        request = DummyRequest(params={'batch': '0'})
        render_view_to_response(table, request, '', False).text
开发者ID:djedproject,项目名称:ptah,代码行数:25,代码来源:test_sqla.py

示例14: test_loadapi_load

    def test_loadapi_load(self):
        content = Content(title='Content')
        uri = content.__uri__

        ptah.get_session().add(content)
        transaction.commit()

        content = ptahcms.load(uri)
        self.assertEqual(content.__uri__, uri)
开发者ID:djedproject,项目名称:ptahcms,代码行数:9,代码来源:test_loadapi.py

示例15: updateAction

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return

        category = models.Category(name = data['name'])
        ptah.get_session().add(category)

        form.message('Category has been created.')
        return HTTPFound(location='/')
开发者ID:cguardia,项目名称:ptahto,代码行数:11,代码来源:views.py


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