• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyramid_basemodel.Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_playlist_get_all_empty

 def test_playlist_get_all_empty(self):
     from balistos.models.playlist import Playlist
     playlist = Playlist.get('test_playlist')
     Session.delete(playlist)
     Session.flush()
     self.assertEqual(0, Playlist.get_all().count())
     self.assertIsNone(Playlist.get('test_playlist'))
开发者ID:ferewuz,项目名称:balistos,代码行数:7,代码来源:test_models.py


示例2: test_success

    def test_success(self):
        "User can delete itself"
        self.add_user_root()

        user = self.makeUser('thruflo', 'Password')
        Session.add(user)

        self.authenticate()

        # Attempt to delete user
        res = self.app.get('/users/thruflo/delete_user')

        # Verify confirmation message
        self.assertTrue('Are you really sure' in res.body)

        # Verify that the user has not yet been deleted
        self.assertTrue(get_existing_user(username='thruflo') is not None)

        # Delete the user
        res = self.app.post('/users/thruflo/delete_user')

        # Verify that the user has now been deleted
        self.assertTrue(get_existing_user(username='thruflo') is None)

        # User should be logged out
        self.assertTrue(len(res.headers['Set-Cookie']) < 200)
开发者ID:fakdora,项目名称:pyramid_simpleauth,代码行数:26,代码来源:tests.py


示例3: handle_data

def handle_data(data_str):
    """Handle data from the Twitter Streaming API, via the redis queue."""
    
    # XXX debug only really.
    sys.stderr.write('.')
    
    # Decode into a unicode string.
    text = unicode(data_str, 'utf-8')
    
    # Try to parse the JSON text into a data dict.
    try:
        data = json.loads(text)
    except Exception as err:
        return logger.warn(err)
    
    # In a transaction.
    with transaction.manager:
        # If we're dealing with a status.
        if data.has_key('in_reply_to_status_id'):
            return handle_status(data, text)
        # If we're dealing with a deletion record.
        if data.has_key('delete'):
            return handle_deletion(data)
        # XXX more events, e.g.: handle verification.
    
    # Close the db connection.
    Session.remove()
开发者ID:kultus,项目名称:belive.at,代码行数:27,代码来源:queue.py


示例4: includeme

def includeme(config):
    registry = config.registry
    config.include('pyramid_basemodel')
    config.include('pyramid_tm')

    config.set_request_property(lib.user_property, 'user')

    if not registry.queryUtility(interfaces.IDBSession):
        registry.registerUtility(Session, interfaces.IDBSession)

    if not registry.queryUtility(interfaces.IUserClass):
        registry.registerUtility(User, interfaces.IUserClass)

    if not registry.queryUtility(interfaces.IConsumerClass):
        registry.registerUtility(Consumer, interfaces.IConsumerClass)

    if not registry.queryUtility(interfaces.IActivationClass):
        registry.registerUtility(Activation, interfaces.IActivationClass)

    settings = config.get_settings()
    key = settings['api.key']
    secret = settings.get('api.secret')
    ttl = settings.get('api.ttl', DEFAULT_TTL)

    session = Session()
    with transaction.manager:
        consumer = Consumer.get_by_key(key)
        if not consumer:
            consumer = Consumer(key=key)
        consumer.secret = secret
        consumer.ttl = ttl
        session.add(consumer)
        session.flush()

    registry.consumer = consumer
开发者ID:almereyda,项目名称:h,代码行数:35,代码来源:models.py


示例5: test_add_pclip

    def test_add_pclip(self):
        from balistos.models.clip import PlaylistClip
        from balistos.models.clip import Clip
        from balistos.models.playlist import Playlist
        from datetime import datetime

        playlist = Playlist(uri='test', title=u'Test')
        clip = Clip(
            youtube_video_id='test',
            title=u'Test',
            likes=5,
            image_url='test_url',
            duration=1
        )
        Session.add(clip)
        Session.add(playlist)
        Session.flush()

        pclip = PlaylistClip(
            playlist=playlist,
            clip=clip,
            likes=0,
            state=0,
            added=datetime.now()
        )
        Session.add(pclip)
        Session.flush()
        pclip = PlaylistClip.get_by_playlist_and_clip(playlist, clip)
        self.assertEqual(playlist, pclip.playlist)
        self.assertEqual(clip, pclip.clip)
        self.assertEqual(0, pclip.state)
        self.assertEqual(0, pclip.likes)
开发者ID:ferewuz,项目名称:balistos,代码行数:32,代码来源:test_models.py


示例6: email_change_POST

    def email_change_POST(self):
        '''
            Processes POST requests to generate change email hash
        '''
        if self.check_csrf:
            token = self.request.session.get_csrf_token()
        else:
            token = ''
        if self.check_csrf and token != self.request.POST.get('token'):
            return {'status': False,
                    'msg': self.request._('csrf-mismatch',
                                          default='CSRF token did not match.',
                                          domain='pyramid_fullauth'),
                    'token': token}
        try:
            Session.query(User).filter(User.email == self.request.POST.get('email', '')).one()
            return {'status': False,
                    'msg': self.request._('User with this email exists',
                                          domain='pyramid_fullauth'),
                    'token': token}
        except NoResultFound:
            pass

        user = self.request.user
        try:
            result = self.request.registry.notify(BeforeEmailChange(self.request, user))
        except AttributeError as e:
            return {'status': False, 'msg': e.message, 'token': token}

        try:
            user.set_new_email(self.request.POST.get('email', ''))
        except EmptyError:
            return {'status': False,
                    'msg': self.request._(
                        'E-mail is empty',
                        domain='pyramid_fullauth'),
                    'token': token}
        except EmailValidationError:
            return {'status': False,
                    'msg': self.request._(
                        'Incorrect e-mail format',
                        domain='pyramid_fullauth'),
                    'token': token}

        response_values = {'status': True,
                           'msg': self.request._('We sent you email to activate your new email address',
                                                 domain='pyramid_fullauth')}
        try:
            self.request.registry.notify(AfterEmailChange(self.request, user))
        except HTTPFound as redirect:
            if self.request.is_xhr:
                response_values['url'] = redirect.location
                return response_values
            else:
                return redirect
        else:
            if self.request.is_xhr:
                return response_values
            else:
                return HTTPFound(location='/')
开发者ID:develucas,项目名称:pyramid_fullauth,代码行数:60,代码来源:profile.py


示例7: test_user_get_all_empty

 def test_user_get_all_empty(self):
     from balistos.models.user import User
     user = User.get_by_username('test_user')
     Session.delete(user)
     Session.flush()
     self.assertEqual(0, User.get_all().count())
     self.assertIsNone(User.get_by_username('test_user'))
开发者ID:ferewuz,项目名称:balistos,代码行数:7,代码来源:test_models.py


示例8: remove_playlist_clip

def remove_playlist_clip(playlist, youtube_video_id):
    """
    Remove clip from playlist

    :param    playlist: playlist we want to delete clip from
    :type     playlist: balistos.models.Playlist
    :param    clip:     youtube video id we want to delete from playlist
    :type     clip:     [clip type]

    :returns  True if removed, False otherwise
    :rtype    boolean
    """

    pclip = PlaylistClip.get_by_playlist_and_clip(
        playlist,
        Clip.get(youtube_video_id)
    )
    if not pclip:
        return False

    state = pclip.state
    Session.delete(pclip)

    if state == 2:
        next_pclip = PlaylistClip.get_queue_playlist_clip(playlist)
        play_next_clip(playlist, pclip, next_pclip)
    elif state == 1:
        active_pclip = PlaylistClip.get_active_playlist_clip(playlist)
        set_next_in_queue(playlist, active_pclip.clip.youtube_video_id)
    return True
开发者ID:ferewuz,项目名称:balistos,代码行数:30,代码来源:playlist.py


示例9: test_sucess_logs_user_out

    def test_sucess_logs_user_out(self):
        "Changing a user password logs the user out."

        from pyramid_simpleauth.events import UserLoggedOut
        from pyramid_simpleauth.model import User
        mock_subscriber = Mock()
        self.config = config_factory()
        self.config.add_subscriber(mock_subscriber, UserLoggedOut)
        self.app = TestApp(self.config.make_wsgi_app())

        # Create a user.
        user = self.makeUser('thruflo', 'Password')
        Session.add(user)
        old_hash = user.password

        self.authenticate()

        # Attempt to change password.
        post_data = {
            'old_password': 'Password',
            'new_password': 'sworDpas',
            'new_confirm':  'sworDpas',
            'next':         '/foo/bar',
        }
        res = self.app.post('/auth/change_password', post_data)

        # Verify logged out.
        self.assertTrue(len(res.headers['Set-Cookie']) < 200)

        # Handler was called with the authentiated user as the second arg.
        self.assertTrue(mock_subscriber.called)
        event = mock_subscriber.call_args_list[0][0][0]
        self.assertTrue(isinstance(event.user, User))
开发者ID:fakdora,项目名称:pyramid_simpleauth,代码行数:33,代码来源:tests.py


示例10: makeUserWithEmail

 def makeUserWithEmail(self):
     "Helper method that creates a user with an email"
     user = self.makeUser(u'thruflo', u'Password')
     Session.add(user)
     user.emails.append(model.Email(address=u'[email protected]'))
     transaction.commit()
     Session.add(user)
     return user
开发者ID:fakdora,项目名称:pyramid_simpleauth,代码行数:8,代码来源:tests.py


示例11: delete

 def delete(self):
     # If the comment has replies it will only marked as deleted
     if len(self.replies):
         self.comment = "<DELETED>"
         self.deleted = True
     # If note it will fully deleted
     else:
         DBSession.delete(self)
开发者ID:Zitrax,项目名称:Artifakt,代码行数:8,代码来源:models.py


示例12: test_clip_get_all_empty

 def test_clip_get_all_empty(self):
     from balistos.models.clip import Clip
     clips = Clip.get_all()
     for clip in clips:
         Session.delete(clip)
     Session.flush()
     self.assertEqual(0, Clip.get_all().count())
     self.assertIsNone(Clip.get('cpV0ygkmhP4'))
开发者ID:ferewuz,项目名称:balistos,代码行数:8,代码来源:test_models.py


示例13: test_pclip_get_all_empty

 def test_pclip_get_all_empty(self):
     from balistos.models.clip import PlaylistClip
     pclips = PlaylistClip.get_all()
     for pclip in pclips:
         Session.delete(pclip)
     Session.flush()
     self.assertEqual(0, PlaylistClip.get_all().count())
     self.assertEqual(0, PlaylistClip.get_all().count())
开发者ID:ferewuz,项目名称:balistos,代码行数:8,代码来源:test_models.py


示例14: add_playlist_clip

def add_playlist_clip(
    playlist,
    title,
    image_url,
    youtube_video_id,
    duration,
    username=None,
    state=0,
):
    """
    Add clip to playlist

    :param    playlist:         playlist of which we want to get videos
    :type     playlist:         balistos.models.playlist.Playlist
    :param    title:            title of video
    :type     title:            str
    :param    image_url:        url of image used for thumbnail
    :type     image_url:        str
    :param    youtube_video_id: id of video on youtube
    :type     youtube_video_id: str
    :param    duration:         duration of video
    :type     duration:         int
    :param    username:         username of user that added this clip
    :type     username:         str
    :param    state:            state of video to be added
    :type     state:            int

    """

    clip = Clip.get(youtube_video_id)
    if not clip:
        clip = Clip(
            title=title,
            image_url=image_url,
            youtube_video_id=youtube_video_id,
            likes=0,
            duration=duration,
        )
        Session.add(clip)
    pclip = PlaylistClip.get_by_playlist_and_clip(playlist, clip)
    if not pclip:
        if state == 2:
            started = datetime.now()
        else:
            started = datetime.min
        pclip = PlaylistClip(
            added=datetime.now(),
            likes=0,
            state=state,
            clip=clip,
            playlist=playlist,
            username=username,
            started=started,
        )
        Session.add(pclip)
        return pclip
    else:
        pclip.likes += 1
开发者ID:ferewuz,项目名称:balistos,代码行数:58,代码来源:playlist.py


示例15: setUp

 def setUp(self):
     from balistos import configure
     Session.remove()
     createTestDB()
     self.config = testing.setUp()
     configure(self.config)
     app = self.config.make_wsgi_app()
     from webtest import TestApp
     self.testapp = TestApp(app)
开发者ID:ferewuz,项目名称:balistos,代码行数:9,代码来源:test_views.py


示例16: makeUser

 def makeUser(self, username, password):
     """Create and save a user with the credentials provided."""
     user = model.User()
     user.username = unicode(username)
     user.password = model.encrypt(password)
     model.save(user)
     transaction.commit()
     Session.add(user)
     return user
开发者ID:altanawealth,项目名称:pyramid_simpleauth,代码行数:9,代码来源:tests.py


示例17: test_add_playlist

    def test_add_playlist(self):
        from balistos.models.playlist import Playlist

        playlist = Playlist(uri='test', title=u'Test')
        Session.add(playlist)
        Session.flush()
        playlist = Playlist.get('test')
        self.assertEqual('test', playlist.uri)
        self.assertEqual(u'Test', playlist.title)
开发者ID:ferewuz,项目名称:balistos,代码行数:9,代码来源:test_models.py


示例18: test_add_user_username_only

 def test_add_user_username_only(self):
     from balistos.models.user import User
     user = User(username='test')
     Session.add(user)
     Session.flush()
     user = User.get_by_username('test')
     self.assertEqual('test', user.username)
     self.assertIsNone(user.email)
     self.assertIsNone(user.fullname)
开发者ID:ferewuz,项目名称:balistos,代码行数:9,代码来源:test_models.py


示例19: handle_deletion

def handle_deletion(data):
    """Handle a Twitter status."""
    
    id_ = data['delete']['status']['id']
    tweet = Tweet.query.get(id_)
    if tweet:
        Session.delete(tweet)
    
    # XXX debug.
    logger.info('Deleted %d' % id_)
开发者ID:kultus,项目名称:belive.at,代码行数:10,代码来源:handle.py


示例20: bootstrap_pyramid

def bootstrap_pyramid(signal, sender):
    import os
    from pyramid.paster import bootstrap
    sender.app.settings = \
        bootstrap(os.environ['BALISTOS_CONFIG'])['registry'].settings
    engine = engine_from_config(sender.app.settings, 'sqlalchemy.')

    register_after_fork(engine, engine.dispose)

    Session.configure(bind=engine)
开发者ID:ferewuz,项目名称:balistos,代码行数:10,代码来源:tasks.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap