Exemple #1
0
    def test_draft(self):
        request = self.request

        current = ICurrentDraftManagement(request)
        self.assertEqual(None, current.draft)

        current.userId = u'user1'
        current.targetKey = u'123'
        current.draftName = u'draft'

        self.assertEqual(None, current.draft)

        storage = getUtility(IDraftStorage)
        created = storage.createDraft(u'user1', u'123')
        current.draftName = created.__name__

        self.assertEqual(created, current.draft)

        newDraft = storage.createDraft(u'user1', u'123')
        current.draft = newDraft

        self.assertEqual(newDraft, current.draft)
Exemple #2
0
 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)
Exemple #3
0
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
Exemple #4
0
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