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


Python Session.add方法代码示例

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


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

示例1: includeme

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
def includeme(config):
    registry = config.registry
    settings = registry.settings

    config.include('pyramid_basemodel')
    config.include('pyramid_tm')

    models = [
        (IActivationClass, Activation),
        (IUserClass, User),
        (IUIStrings, UIStringsBase),
        (IConsumerClass, Consumer),
        (IDBSession, Session)
    ]

    for iface, imp in models:
        if not registry.queryUtility(iface):
            registry.registerUtility(imp, iface)

    if asbool(settings.get('basemodel.should_create_all', True)):
        key = settings['api.key']
        secret = settings.get('api.secret')
        ttl = settings.get('api.ttl', auth.DEFAULT_TTL)

        session = Session()
        consumer = session.query(Consumer).filter(Consumer.key == key).first()
        if not consumer:
            with transaction.manager:
                consumer = Consumer(key=key, secret=secret, ttl=ttl)
                session.add(consumer)
                session.flush()
开发者ID:RichardLitt,项目名称:h,代码行数:33,代码来源:models.py

示例2: test_wrong_old_password

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    def test_wrong_old_password(self):
        "No password change if old password is not corret"

        # 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': 'foobarbaz',
            'new_password': 'swordpas',
            'new_confirm':  'swordpas',
            'next':         '/foo/bar',
        }
        res = self.app.post('/auth/change_password', post_data)

        # Verify that password hasn't changed
        Session.add(user)
        Session.refresh(user)
        self.assertTrue("Wrong current password" in res.body)
        self.assertTrue("/foo/bar" in res.body)
        self.assertEquals(user.password, old_hash)
开发者ID:fakdora,项目名称:pyramid_simpleauth,代码行数:27,代码来源:tests.py

示例3: get_or_create_user_by_email

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
def get_or_create_user_by_email(email, cls=User):
    """Gets or creates an user given an email."""

    # If the email is in the database we just return its user.
    # First try by confirmed then just any email.
    db_email = Email.query.filter_by(address=email, is_confirmed=True).first()
    if db_email:
        return db_email.user

    # Now just by email.
    db_email = Email.query.filter_by(address=email).first()
    if db_email:
        return db_email.user

    # If we got this far it doesn't exist, create a new user...
    username = generate_random_digest(num_bytes=15)

    # Build a dict with keys that the user_cls.factory method expects.
    # Note that the raw password will be encrypted before being saved.
    data = {
        'password': '',
        'username': username,
    }

    user = cls(**data)
    Session.add(user)

    db_email = Email(user=user, address=email)
    Session.add(db_email)

    Session.flush()

    return user
开发者ID:Rygbee,项目名称:pyramid_simpleauth,代码行数:35,代码来源:model.py

示例4: includeme

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
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,代码行数:37,代码来源:models.py

示例5: test_sucess

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    def test_sucess(self):
        "If all conditions are met, change password"

        # 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 that password has changed
        Session.add(user)
        Session.refresh(user)
        self.assertNotEquals(user.password, old_hash)

        # Verify redirect
        self.assertEquals(res.headers['Location'], 'http://localhost/foo/bar')
开发者ID:fakdora,项目名称:pyramid_simpleauth,代码行数:28,代码来源:tests.py

示例6: test_success

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    def test_success(self):
        "Token is valid, email address should be confirmed"
        # Create a user
        user = self.makeUserWithEmail()

        # Sanity check
        self.assertFalse(user.emails[0].is_confirmed)

        # Get valid confirmation link
        email = user.emails[0]
        confirmation_link = self.makeConfirmationLink(email)

        # Attempt to confirm email address
        res = self.app.get(confirmation_link)
        self.assertTrue(res.location.endswith('victory_path'))

        # Now configure settings with a route that doesn't exist
        settings = {'simpleauth.after_confirm_email_route': 'success_path'}
        self.config = config_factory(**settings)
        # Not adding the route!
        self.app = TestApp(self.config.make_wsgi_app())
        res = self.app.get(confirmation_link)
        self.assertEquals(res.location, 'http://localhost/')

        # Verify that email address has been confirmed
        Session.add(email)
        Session.refresh(email)
        self.assertTrue(email.is_confirmed)
开发者ID:fakdora,项目名称:pyramid_simpleauth,代码行数:30,代码来源:tests.py

示例7: test_sucess_logs_user_out

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    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,代码行数:35,代码来源:tests.py

示例8: test_sucess

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    def test_sucess(self):
        "If all conditions are met, change password"

        # 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 that password has changed
        Session.add(user)
        Session.refresh(user)
        self.assertNotEquals(user.password, old_hash)

        # Verify redirect
        self.assertEquals(res.headers["Location"], "http://localhost/foo/bar")
开发者ID:malnoxon,项目名称:pyramid_simpleauth,代码行数:28,代码来源:tests.py

示例9: test_wrong_old_password

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    def test_wrong_old_password(self):
        "No password change if old password is not corret"

        # 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": "foobarbaz",
            "new_password": "swordpas",
            "new_confirm": "swordpas",
            "next": "/foo/bar",
        }
        res = self.app.post("/auth/change_password", post_data)

        # Verify that password hasn't changed
        Session.add(user)
        Session.refresh(user)
        self.assertTrue("Wrong current password" in res.body)
        self.assertTrue("/foo/bar" in res.body)
        self.assertEquals(user.password, old_hash)
开发者ID:malnoxon,项目名称:pyramid_simpleauth,代码行数:27,代码来源:tests.py

示例10: makeUserWithEmail

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
 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,代码行数:10,代码来源:tests.py

示例11: add_playlist_clip

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
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,代码行数:60,代码来源:playlist.py

示例12: makeUser

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
 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,代码行数:11,代码来源:tests.py

示例13: test_add_playlist

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    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,代码行数:11,代码来源:test_models.py

示例14: test_add_user_username_only

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
 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,代码行数:11,代码来源:test_models.py

示例15: setUp

# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import add [as 别名]
    def setUp(self):
        '''
            setUp test method @see unittest.TestCase.setUp
        '''
        Base.metadata.create_all(engine)

        for locale in ['pl', 'cz', 'fr']:
            locale_object = Language(name=text_type(locale),
                                     native_name=text_type(locale),
                                     language_code=text_type(locale))
            Session.add(locale_object)
开发者ID:develucas,项目名称:pyramid_localize,代码行数:13,代码来源:test_request.py


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