当前位置: 首页>>代码示例>>Python>>正文


Python ICurrentDraftManagement.draftName方法代码示例

本文整理汇总了Python中plone.app.drafts.interfaces.ICurrentDraftManagement.draftName方法的典型用法代码示例。如果您正苦于以下问题:Python ICurrentDraftManagement.draftName方法的具体用法?Python ICurrentDraftManagement.draftName怎么用?Python ICurrentDraftManagement.draftName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plone.app.drafts.interfaces.ICurrentDraftManagement的用法示例。


在下文中一共展示了ICurrentDraftManagement.draftName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_save

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [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'])
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:37,代码来源:tests.py

示例2: beginDrafting

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [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()
开发者ID:plone,项目名称:plone.app.drafts,代码行数:33,代码来源:lifecycle.py

示例3: test_draft

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [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)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:24,代码来源:tests.py

示例4: test_draftName

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [as 别名]
 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,代码行数:15,代码来源:tests.py

示例5: test_getCurrentDraft_draft_details_set_not_in_storage

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [as 别名]
 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,代码行数:16,代码来源:tests.py

示例6: test_getCurrentDraft_draft_details_set_in_storage_create

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [as 别名]
 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,代码行数:18,代码来源:tests.py

示例7: test_getCurrentDraft_draft_details_set_not_in_storage_create

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [as 别名]
 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,代码行数:21,代码来源:tests.py

示例8: getCurrentDraft

# 需要导入模块: from plone.app.drafts.interfaces import ICurrentDraftManagement [as 别名]
# 或者: from plone.app.drafts.interfaces.ICurrentDraftManagement import draftName [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
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:38,代码来源:utils.py


注:本文中的plone.app.drafts.interfaces.ICurrentDraftManagement.draftName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。