本文整理汇总了Python中plone.app.drafts.interfaces.ICurrentDraftManagement类的典型用法代码示例。如果您正苦于以下问题:Python ICurrentDraftManagement类的具体用法?Python ICurrentDraftManagement怎么用?Python ICurrentDraftManagement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ICurrentDraftManagement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, form, request, context):
fti = queryUtility(IDexterityFTI, name=form.portal_type)
if IDraftable.__identifier__ in fti.behaviors:
draft = getCurrentDraft(request, create=False)
target = getattr(draft, '_draftAddFormTarget',
createContent(form.portal_type))
if draft is None:
IMutableUUID(target).set('++add++%s' % form.portal_type)
beginDrafting(target.__of__(context), None)
draft = getCurrentDraft(request, create=True)
draft._draftAddFormTarget = target
# Disable Plone 5 implicit CSRF when no form action
if HAS_PLONE_PROTECT:
if not ([key for key in request.form
if key.startswith('form.buttons.')]):
alsoProvides(request, IDisableCSRFProtection)
else:
current = ICurrentDraftManagement(request)
current.mark()
context = DraftProxy(draft, target.__of__(context))
alsoProvides(request, IAddFormDrafting)
super(DefaultAddFormFieldWidgets, self).__init__(form, request, context) # noqa
示例2: test_userId
def test_userId(self):
request = self.request
current = ICurrentDraftManagement(request)
self.assertEquals(TEST_USER_ID, current.userId)
current.userId = u"third-user"
self.assertEquals(u"third-user", current.userId)
示例3: test_userId
def test_userId(self):
request = self.app.REQUEST
current = ICurrentDraftManagement(request)
self.assertEquals(ptc.default_user, current.userId)
current.userId = u"third-user"
self.assertEquals(u"third-user", current.userId)
示例4: update
def update(self):
# Set up draft information if required
currentDraft = ICurrentDraftManagement(self.request)
currentDraft.mark()
# Override to check the tile add/edit permission
if not IDeferSecurityCheck.providedBy(self.request):
if not checkPermission(self.tileType.add_permission, self.context):
raise Unauthorized(
"You are not allowed to add this kind of tile")
super(TileForm, self).update()
示例5: test_draftName
def test_draftName(self):
request = self.request
current = ICurrentDraftManagement(request)
self.assertEquals(None, current.draftName)
request.set('plone.app.drafts.draftName', u"draft-1")
self.assertEquals(u"draft-1", current.draftName)
current.draftName = u"draft-2"
self.assertEquals(u"draft-2", current.draftName)
self.assertEquals(u"draft-1", request.get('plone.app.drafts.draftName'))
示例6: test_path
def test_path(self):
request = self.request
current = ICurrentDraftManagement(request)
self.assertEquals(None, current.path)
request.set('plone.app.drafts.path', u"/test")
self.assertEquals(u"/test", current.path)
current.path = u"/test/test-1"
self.assertEquals(u"/test/test-1", current.path)
self.assertEquals(u"/test", request.get('plone.app.drafts.path'))
示例7: test_targetKey
def test_targetKey(self):
request = self.request
current = ICurrentDraftManagement(request)
self.assertEquals(None, current.targetKey)
request.set('plone.app.drafts.targetKey', u"123")
self.assertEquals(u"123", current.targetKey)
current.targetKey = u"234"
self.assertEquals(u"234", current.targetKey)
self.assertEquals(u"123", request.get('plone.app.drafts.targetKey'))
示例8: beginDrafting
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()
示例9: test_getCurrentDraft_draft_details_set_not_in_storage
def test_getCurrentDraft_draft_details_set_not_in_storage(self):
request = self.request
management = ICurrentDraftManagement(request)
management.userId = u"user1"
management.targetKey = u"123"
management.draftName = u"bogus"
draft = getCurrentDraft(request)
self.assertEquals(None, draft)
response = request.response
self.failIf('plone.app.drafts.targetKey' in response.cookies)
self.failIf('plone.app.drafts.draftName' in response.cookies)
示例10: test_getCurrentDraft_draft_details_set_in_storage_create
def test_getCurrentDraft_draft_details_set_in_storage_create(self):
request = self.request
inStorage = getUtility(IDraftStorage).createDraft(u"user1", u"123")
management = ICurrentDraftManagement(request)
management.userId = u"user1"
management.targetKey = u"123"
management.draftName = inStorage.__name__
draft = getCurrentDraft(request, create=True)
self.assertEquals(inStorage, draft)
response = request.response
self.failIf('plone.app.drafts.targetKey' in response.cookies)
self.failIf('plone.app.drafts.draftName' in response.cookies)
示例11: test_getCurrentDraft_draft_details_set_not_in_storage_create
def test_getCurrentDraft_draft_details_set_not_in_storage_create(self):
request = self.request
management = ICurrentDraftManagement(request)
management.userId = u"user1"
management.targetKey = u"123"
management.draftName = u"bogus"
draft = getCurrentDraft(request, create=True)
inStorage = getUtility(IDraftStorage).getDraft(u"user1", u"123", draft.__name__)
self.assertEquals(inStorage, draft)
response = request.response
self.failUnless('plone.app.drafts.targetKey' in response.cookies)
self.failUnless('plone.app.drafts.draftName' in response.cookies)
self.assertEquals('123', response.cookies['plone.app.drafts.targetKey']['value'])
self.assertEquals(draft.__name__, response.cookies['plone.app.drafts.draftName']['value'])
示例12: discardDraftsOnCancel
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()
示例13: syncDraftOnSave
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()
示例14: __call__
def __call__(self):
# Set up draft information if required
currentDraft = ICurrentDraftManagement(self.request)
currentDraft.mark()
self.request['disable_border'] = True
confirm = self.request.form.get('confirm', False)
self.tileTypeName = self.request.form.get('type', None)
self.tileId = self.request.form.get('id', None)
self.deleted = False
if confirm and self.tileTypeName and self.tileId:
tileType = getUtility(ITileType, name=self.tileTypeName)
if not checkPermission(tileType.add_permission, self.context):
raise Unauthorized("You are not allowed to modify this " + \
"tile type")
tile = self.context.restrictedTraverse(
'@@%s/%s' % (self.tileTypeName, self.tileId,))
dm = ITileDataManager(tile)
dm.delete()
notify(ObjectRemovedEvent(tile, self.context, self.tileId))
self.deleted = True
elif 'form.button.Ok' in self.request.form:
self.request.response.redirect(
self.context.absolute_url() + '/view')
return ''
return self.index()
示例15: getCurrentDraft
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