当前位置: 首页>>代码示例>>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;未经允许,请勿转载。