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


Python Session.expunge方法代码示例

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


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

示例1: fixture_add_comment_report

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_comment_report(comment=None, reported_user=None,
        reporter=None, created=None, report_content=None):
    if comment is None:
        comment = fixture_add_comment()

    if reported_user is None:
        reported_user = fixture_add_user()

    if reporter is None:
        reporter = fixture_add_user()

    if created is None:
        created=datetime.now()

    if report_content is None:
        report_content = \
            'Auto-generated test report'

    comment_report = CommentReport(comment=comment,
        reported_user = reported_user,
        reporter = reporter,
        created = created,
        report_content=report_content)

    comment_report.save()

    Session.expunge(comment_report)

    return comment_report
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:31,代码来源:tools.py

示例2: fixture_add_user

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_user(username=u'chris', password=u'toast',
                     active_user=True, wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = User.query.filter_by(username=username).first()
    if test_user is None:
        test_user = User()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    if active_user:
        test_user.email_verified = True
        test_user.status = u'active'

    test_user.wants_comment_notification = wants_comment_notification

    test_user.save()

    # Reload
    test_user = User.query.filter_by(username=username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
开发者ID:RichoHan,项目名称:MediaGoblin,代码行数:27,代码来源:tools.py

示例3: fixture_add_comment

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_comment(author=None, media_entry=None, comment=None):
    if author is None:
        author = fixture_add_user().id

    if media_entry is None:
        media_entry = fixture_media_entry()

    if comment is None:
        comment = \
            'Auto-generated test comment by user #{0} on media #{0}'.format(
                author, media_entry)

    text_comment = TextComment(
        actor=author,
        content=comment
    )
    text_comment.save()

    comment_link = Comment()
    comment_link.target = media_entry
    comment_link.comment = text_comment
    comment_link.save()

    Session.expunge(comment_link)

    return text_comment
开发者ID:ausbin,项目名称:mediagoblin,代码行数:28,代码来源:tools.py

示例4: fixture_add_collection

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_collection(name=u"My first Collection", user=None,
                           collection_type=Collection.USER_DEFINED_TYPE):
    if user is None:
        user = fixture_add_user()
    coll = Collection.query.filter_by(
        actor=user.id,
        title=name,
        type=collection_type
    ).first()
    if coll is not None:
        return coll
    coll = Collection()
    coll.actor = user.id
    coll.title = name
    coll.type = collection_type
    coll.generate_slug()
    coll.save()

    # Reload
    Session.refresh(coll)

    # ... and detach from session:
    Session.expunge(coll)

    return coll
开发者ID:ausbin,项目名称:mediagoblin,代码行数:27,代码来源:tools.py

示例5: fixture_add_user

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_user(username=u'chris', password=u'toast',
                     privileges=[], wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = LocalUser.query.filter(LocalUser.username==username).first()
    if test_user is None:
        test_user = LocalUser()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    test_user.wants_comment_notification = wants_comment_notification
    for privilege in privileges:
        query = Privilege.query.filter(Privilege.privilege_name==privilege)
        if query.count():
            test_user.all_privileges.append(query.one())

    test_user.save()

    # Reload - The `with_polymorphic` needs to be there to eagerly load
    # the attributes on the LocalUser as this can't be done post detachment.
    user_query = LocalUser.query.with_polymorphic(LocalUser)
    test_user = user_query.filter(LocalUser.username==username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
开发者ID:ausbin,项目名称:mediagoblin,代码行数:29,代码来源:tools.py

示例6: _test_authentication

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
    def _test_authentication():
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/login/',
            {'username': u'chris',
             'password': u'toast'})

        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
        register_form = context['register_form']

        assert register_form.username.data == u'chris'
        assert register_form.email.data == u'[email protected]'

        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/register/',
            {'username': u'chris',
             'email': u'[email protected]'})
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
        assert 'mediagoblin/user_pages/user.html' in template.TEMPLATE_TEST_CONTEXT

        # Try to register with same email and username
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/register/',
            {'username': u'chris',
             'email': u'[email protected]'})

        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
        register_form = context['register_form']

        assert register_form.email.errors == [u'Sorry, a user with that email address already exists.']
        assert register_form.username.errors == [u'Sorry, a user with that name already exists.']

        # Log out
        ldap_plugin_app.get('/auth/logout/')

        # Get user and detach from session
        test_user = mg_globals.database.User.query.filter_by(
            username=u'chris').first()
        Session.expunge(test_user)

        # Log back in
        template.clear_test_template_context()
        res = ldap_plugin_app.post(
            '/auth/ldap/login/',
            {'username': u'chris',
             'password': u'toast'})
        res.follow()

        assert urlparse.urlsplit(res.location)[2] == '/'
        assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

        # Make sure user is in the session
        context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
        session = context['request'].session
        assert session['user_id'] == unicode(test_user.id)
开发者ID:commonsmachinery,项目名称:mediagoblin,代码行数:61,代码来源:test_ldap.py

示例7: user_upload_limits

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
    def user_upload_limits(self, uploaded=None, upload_limit=None):
        our_user = self.our_user()

        if uploaded:
            our_user.uploaded = uploaded
        if upload_limit:
            our_user.upload_limit = upload_limit

        our_user.save()
        Session.expunge(our_user)
开发者ID:piratas,项目名称:biblioteca,代码行数:12,代码来源:test_submission.py

示例8: fixture_add_comment_notification

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_comment_notification(entry_id, subject_id, user_id,
                                     seen=False):
    cn = CommentNotification(user_id=user_id,
                             seen=seen,
                             subject_id=subject_id)
    cn.save()

    cn = CommentNotification.query.filter_by(id=cn.id).first()

    Session.expunge(cn)

    return cn
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:14,代码来源:tools.py

示例9: _test_new_user

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
        def _test_new_user():
            openid_plugin_app.post(
                '/auth/openid/login/', {
                    'openid': u'http://real.myopenid.com'})

            # Right place?
            assert 'mediagoblin/auth/register.html' in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/register.html']
            register_form = context['register_form']

            # Register User
            res = openid_plugin_app.post(
                '/auth/openid/register/', {
                    'openid': register_form.openid.data,
                    'username': u'chris',
                    'email': u'[email protected]'})
            res.follow()

            # Correct place?
            assert urlparse.urlsplit(res.location)[2] == '/u/chris/'
            assert 'mediagoblin/user_pages/user_nonactive.html' in template.TEMPLATE_TEST_CONTEXT

            # No need to test if user is in logged in and verification email
            # awaits, since openid uses the register_user function which is
            # tested in test_auth

            # Logout User
            openid_plugin_app.get('/auth/logout')

            # Get user and detach from session
            test_user = mg_globals.database.LocalUser.query.filter(
                LocalUser.username==u'chris'
            ).first()
            Session.expunge(test_user)

            # Log back in
            # Could not get it to work by 'POST'ing to /auth/openid/login/
            template.clear_test_template_context()
            res = openid_plugin_app.post(
                '/auth/openid/login/finish/', {
                    'openid': u'http://real.myopenid.com'})
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == '/'
            assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT

            # Make sure user is in the session
            context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
            session = context['request'].session
            assert session['user_id'] == six.text_type(test_user.id)
开发者ID:ausbin,项目名称:mediagoblin,代码行数:52,代码来源:test_openid.py

示例10: user_upload_limits

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
    def user_upload_limits(self, uploaded=None, upload_limit=None):
        if uploaded:
            self.test_user.uploaded = uploaded
        if upload_limit:
            self.test_user.upload_limit = upload_limit

        self.test_user.save()

        # Reload
        self.test_user = User.query.filter_by(
            username=self.test_user.username
        ).first()

        # ... and detach from session:
        Session.expunge(self.test_user)
开发者ID:commonsmachinery,项目名称:mediagoblin,代码行数:17,代码来源:test_submission.py

示例11: fixture_comment_subscription

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_comment_subscription(entry, notify=True, send_email=None):
    if send_email is None:
        uploader = User.query.filter_by(id=entry.uploader).first()
        send_email = uploader.wants_comment_notification

    cs = CommentSubscription(
        media_entry_id=entry.id,
        user_id=entry.uploader,
        notify=notify,
        send_email=send_email)

    cs.save()

    cs = CommentSubscription.query.filter_by(id=cs.id).first()

    Session.expunge(cs)

    return cs
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:20,代码来源:tools.py

示例12: _test_new_user

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
        def _test_new_user():
            openid_plugin_app.post("/auth/openid/login/", {"openid": u"http://real.myopenid.com"})

            # Right place?
            assert "mediagoblin/auth/register.html" in template.TEMPLATE_TEST_CONTEXT
            context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/auth/register.html"]
            register_form = context["register_form"]

            # Register User
            res = openid_plugin_app.post(
                "/auth/openid/register/",
                {"openid": register_form.openid.data, "username": u"chris", "email": u"[email protected]"},
            )
            res.follow()

            # Correct place?
            assert urlparse.urlsplit(res.location)[2] == "/u/chris/"
            assert "mediagoblin/user_pages/user.html" in template.TEMPLATE_TEST_CONTEXT

            # No need to test if user is in logged in and verification email
            # awaits, since openid uses the register_user function which is
            # tested in test_auth

            # Logout User
            openid_plugin_app.get("/auth/logout")

            # Get user and detach from session
            test_user = mg_globals.database.User.query.filter_by(username=u"chris").first()
            Session.expunge(test_user)

            # Log back in
            # Could not get it to work by 'POST'ing to /auth/openid/login/
            template.clear_test_template_context()
            res = openid_plugin_app.post("/auth/openid/login/finish/", {"openid": u"http://real.myopenid.com"})
            res.follow()

            assert urlparse.urlsplit(res.location)[2] == "/"
            assert "mediagoblin/root.html" in template.TEMPLATE_TEST_CONTEXT

            # Make sure user is in the session
            context = template.TEMPLATE_TEST_CONTEXT["mediagoblin/root.html"]
            session = context["request"].session
            assert session["user_id"] == unicode(test_user.id)
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:45,代码来源:test_openid.py

示例13: fixture_add_comment

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_comment(author=None, media_entry=None, comment=None):
    if author is None:
        author = fixture_add_user().id

    if media_entry is None:
        media_entry = fixture_media_entry().id

    if comment is None:
        comment = \
            'Auto-generated test comment by user #{0} on media #{0}'.format(
                author, media_entry)

    comment = MediaComment(author=author,
                      media_entry=media_entry,
                      content=comment)

    comment.save()

    Session.expunge(comment)

    return comment
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:23,代码来源:tools.py

示例14: fixture_media_entry

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_media_entry(title=u"Some title", slug=None,
                        uploader=None, save=True, gen_slug=True,
                        state=u'unprocessed', fake_upload=True,
                        expunge=True):
    """
    Add a media entry for testing purposes.

    Caution: if you're adding multiple entries with fake_upload=True,
    make sure you save between them... otherwise you'll hit an
    IntegrityError from multiple newly-added-MediaEntries adding
    FileKeynames at once.  :)
    """
    if uploader is None:
        uploader = fixture_add_user().id

    entry = MediaEntry()
    entry.title = title
    entry.slug = slug
    entry.uploader = uploader
    entry.media_type = u'image'
    entry.state = state

    if fake_upload:
        entry.media_files = {'thumb': ['a', 'b', 'c.jpg'],
                             'medium': ['d', 'e', 'f.png'],
                             'original': ['g', 'h', 'i.png']}
        entry.media_type = u'mediagoblin.media_types.image'

    if gen_slug:
        entry.generate_slug()

    if save:
        entry.save()

    if expunge:
        entry = MediaEntry.query.filter_by(id=entry.id).first()

        Session.expunge(entry)

    return entry
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:42,代码来源:tools.py

示例15: fixture_add_user

# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import expunge [as 别名]
def fixture_add_user(username=u'chris', password=u'toast',
                     privileges=[], wants_comment_notification=True):
    # Reuse existing user or create a new one
    test_user = User.query.filter_by(username=username).first()
    if test_user is None:
        test_user = User()
    test_user.username = username
    test_user.email = username + u'@example.com'
    if password is not None:
        test_user.pw_hash = gen_password_hash(password)
    test_user.wants_comment_notification = wants_comment_notification
    for privilege in privileges:
        query = Privilege.query.filter(Privilege.privilege_name==privilege)
        if query.count():
            test_user.all_privileges.append(query.one())

    test_user.save()
    # Reload
    test_user = User.query.filter_by(username=username).first()

    # ... and detach from session:
    Session.expunge(test_user)

    return test_user
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:26,代码来源:tools.py


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