當前位置: 首頁>>代碼示例>>Python>>正文


Python ICurrentDraftManagement.discard方法代碼示例

本文整理匯總了Python中plone.app.drafts.interfaces.ICurrentDraftManagement.discard方法的典型用法代碼示例。如果您正苦於以下問題:Python ICurrentDraftManagement.discard方法的具體用法?Python ICurrentDraftManagement.discard怎麽用?Python ICurrentDraftManagement.discard使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在plone.app.drafts.interfaces.ICurrentDraftManagement的用法示例。


在下文中一共展示了ICurrentDraftManagement.discard方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_discard

# 需要導入模塊: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 別名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import discard [as 別名]
    def test_discard(self):
        request = self.request
        response = request.response

        current = ICurrentDraftManagement(request)
        current.discard()

        expires = 'Wed, 31-Dec-97 23:59:59 GMT'

        try:
            # expires date changed in ZPublisher.HTTPResponse
            # see https://github.com/zopefoundation/Zope/commit/77f483a22d6b0cb00883006cf38928cda77b75f9  # noqa
            zope_version = pkg_resources.get_distribution('Zope').version
            if parse_version(zope_version) >= parse_version('4.0b8'):
                expires = 'Wed, 31 Dec 1997 23:59:59 GMT'
        except Exception:
            pass

        deletedToken = {'expires': expires,
                        'max_age': 0, 'path': '/', 'quoted': True,
                        'value': 'deleted'}

        self.assertEqual(
            deletedToken,
            response.cookies['plone.app.drafts.targetKey'],
        )
        self.assertEqual(
            deletedToken,
            response.cookies['plone.app.drafts.draftName'],
        )
        self.assertEqual(
            deletedToken,
            response.cookies['plone.app.drafts.path'],
        )

        current.path = '/test'
        current.discard()

        deletedToken['path'] = '/test'

        self.assertEqual(
            deletedToken,
            response.cookies['plone.app.drafts.targetKey'],
        )
        self.assertEqual(
            deletedToken,
            response.cookies['plone.app.drafts.draftName'],
        )
        self.assertEqual(
            deletedToken,
            response.cookies['plone.app.drafts.path'],
        )
開發者ID:plone,項目名稱:plone.app.drafts,代碼行數:54,代碼來源:tests.py

示例2: discardDraftsOnCancel

# 需要導入模塊: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 別名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import discard [as 別名]
def discardDraftsOnCancel(context, event):
    """When the edit form is cancelled, discard any unused drafts and
    remove the drafting cookies.
    """

    storage = queryUtility(IDraftStorage)
    if storage is None or not storage.enabled:
        return

    request = getattr(context, 'REQUEST', None)
    if request is None:
        return

    current = ICurrentDraftManagement(request)

    if current.userId and current.targetKey:
        storage.discardDrafts(current.userId, current.targetKey)

    current.discard()
開發者ID:plone,項目名稱:plone.app.drafts,代碼行數:21,代碼來源:lifecycle.py

示例3: syncDraftOnSave

# 需要導入模塊: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 別名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import discard [as 別名]
def syncDraftOnSave(context, event):
    """When the edit form is saved, sync the draft (if set) and discard it.
    Also discard the drafting cookies.
    """

    storage = queryUtility(IDraftStorage)
    if storage is None or not storage.enabled:
        return

    request = getattr(context, 'REQUEST', None)
    if request is None:
        return

    draft = getCurrentDraft(request)
    if draft is not None:
        syncDraft(draft, context)

    current = ICurrentDraftManagement(request)
    if current.userId and current.targetKey:
        storage.discardDrafts(current.userId, current.targetKey)

    current.discard()
開發者ID:plone,項目名稱:plone.app.drafts,代碼行數:24,代碼來源:lifecycle.py


注:本文中的plone.app.drafts.interfaces.ICurrentDraftManagement.discard方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。