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


Python interfaces.ICurrentDraftManagement類代碼示例

本文整理匯總了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
開發者ID:datakurre,項目名稱:plone.app.drafts,代碼行數:26,代碼來源:dexterity.py

示例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)
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:8,代碼來源:tests.py

示例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)
開發者ID:Vinsurya,項目名稱:Plone,代碼行數:8,代碼來源:tests.py

示例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()
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:13,代碼來源:base.py

示例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'))
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:13,代碼來源:tests.py

示例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'))
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:13,代碼來源:tests.py

示例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'))
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:13,代碼來源:tests.py

示例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()
開發者ID:plone,項目名稱:plone.app.drafts,代碼行數:31,代碼來源:lifecycle.py

示例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)
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:14,代碼來源:tests.py

示例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)
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:16,代碼來源:tests.py

示例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'])
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:19,代碼來源:tests.py

示例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()
開發者ID:plone,項目名稱:plone.app.drafts,代碼行數:19,代碼來源:lifecycle.py

示例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()
開發者ID:plone,項目名稱:plone.app.drafts,代碼行數:22,代碼來源:lifecycle.py

示例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()
開發者ID:davisagli,項目名稱:plone.app.tiles,代碼行數:39,代碼來源:delete.py

示例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
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:36,代碼來源:utils.py


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