本文整理匯總了Python中plone.app.drafts.interfaces.ICurrentDraftManagement.save方法的典型用法代碼示例。如果您正苦於以下問題:Python ICurrentDraftManagement.save方法的具體用法?Python ICurrentDraftManagement.save怎麽用?Python ICurrentDraftManagement.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plone.app.drafts.interfaces.ICurrentDraftManagement
的用法示例。
在下文中一共展示了ICurrentDraftManagement.save方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: beginDrafting
# 需要導入模塊: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 別名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import save [as 別名]
def beginDrafting(context, event):
"""When we enter the edit screen, set up the target key and draft cookie
path. If there is exactly one draft for the given user id and target key,
consider that to be the current draft. Also mark the request with
IDrafting if applicable.
"""
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)
# Update target key regardless - we could have a stale cookie
current.targetKey = getObjectKey(context)
if current.draftName is None:
drafts = storage.getDrafts(current.userId, current.targetKey)
if len(drafts) == 1:
current.draftName = tuple(drafts.keys())[0]
# Save the path now so that we can use it again later, even on URLs
# (e.g. in AJAX dialogues) that are below this path.
current.path = current.defaultPath
current.mark()
current.save()
示例2: test_save
# 需要導入模塊: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 別名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import save [as 別名]
def test_save(self):
request = self.request
response = request.response
current = ICurrentDraftManagement(request)
self.assertEquals(False, current.save())
self.failIf('plone.app.drafts.targetKey' in response.cookies)
self.failIf('plone.app.drafts.draftName' in response.cookies)
self.failIf('plone.app.drafts.userId' in response.cookies)
self.failIf('plone.app.drafts.path' in response.cookies)
current.targetKey = u"123"
self.assertEquals(True, current.save())
self.assertEquals({'value': '123', 'quoted': True, 'path': '/'}, response.cookies['plone.app.drafts.targetKey'])
self.failIf('plone.app.drafts.draftName' in response.cookies)
self.failIf('plone.app.drafts.path' in response.cookies)
current.targetKey = u"123"
current.draftName = u"draft-1"
self.assertEquals(True, current.save())
self.assertEquals({'value': '123', 'quoted': True, 'path': '/'}, response.cookies['plone.app.drafts.targetKey'])
self.assertEquals({'value': 'draft-1', 'quoted': True, 'path': '/'}, response.cookies['plone.app.drafts.draftName'])
self.failIf('plone.app.drafts.path' in response.cookies)
current.targetKey = u"123"
current.draftName = u"draft-1"
current.path = '/test'
self.assertEquals(True, current.save())
self.assertEquals({'value': '123', 'quoted': True, 'path': '/test'}, response.cookies['plone.app.drafts.targetKey'])
self.assertEquals({'value': 'draft-1', 'quoted': True, 'path': '/test'}, response.cookies['plone.app.drafts.draftName'])
self.assertEquals({'value': '/test', 'quoted': True, 'path': '/test'}, response.cookies['plone.app.drafts.path'])
示例3: getCurrentDraft
# 需要導入模塊: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 別名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import save [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