本文整理汇总了Python中plone.app.drafts.interfaces.ICurrentDraftManagement.draft方法的典型用法代码示例。如果您正苦于以下问题:Python ICurrentDraftManagement.draft方法的具体用法?Python ICurrentDraftManagement.draft怎么用?Python ICurrentDraftManagement.draft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.app.drafts.interfaces.ICurrentDraftManagement
的用法示例。
在下文中一共展示了ICurrentDraftManagement.draft方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_draft
# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draft [as 别名]
def test_draft(self):
request = self.request
current = ICurrentDraftManagement(request)
self.assertEquals(None, current.draft)
current.userId = u"user1"
current.targetKey = u"123"
current.draftName = u"draft"
self.assertEquals(None, current.draft)
storage = getUtility(IDraftStorage)
created = storage.createDraft(u"user1", u"123")
current.draftName = created.__name__
self.assertEquals(created, current.draft)
newDraft = storage.createDraft(u"user1", u"123")
current.draft = newDraft
self.assertEquals(newDraft, current.draft)
示例2: getCurrentDraft
# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draft [as 别名]
def getCurrentDraft(request, create=False):
"""Get the current draft as stored in the request.
The request must have been set up via an ``ICurrentDraftManagement``
adapter. This should happen in the integration layer between the drafts
storage and the draft edit form.
If no draft is available, but a user id and target key have been given,
a new draft will be created if ``create`` is True.
If not found, return None.
"""
current = ICurrentDraftManagement(request, None)
if current is None:
return None
draft = current.draft
if draft is not None:
return draft
if create and current.userId and current.targetKey:
storage = queryUtility(IDraftStorage)
if storage is None:
return None
draft = storage.createDraft(current.userId, current.targetKey)
current.draft = draft
current.draftName = draft.__name__
current.save()
return draft
return None