예제 #1
0
파일: tests.py 프로젝트: CGTIC/Plone_SP
 def test_syncDraft(self):
     
     class Target(object):
         pass
     
     draft = Draft()
     draft.a1 = 1
     draft.a2 = 2
     
     target = Target()
     
     class Syncer1(object):
         implements(IDraftSyncer)
         adapts(Draft, Target)
         
         def __init__(self, draft, target):
             self.draft = draft
             self.target = target
         
         def __call__(self):
             self.target.a1 = self.draft.a1
     
     provideAdapter(Syncer1, name=u"s1")
     
     class Syncer2(object):
         implements(IDraftSyncer)
         adapts(Draft, Target)
         
         def __init__(self, draft, target):
             self.draft = draft
             self.target = target
         
         def __call__(self):
             self.target.a2 = self.draft.a2
     
     provideAdapter(Syncer2, name=u"s2")
     
     syncDraft(draft, target)
     
     self.assertEquals(1, target.a1)
     self.assertEquals(2, target.a2)
예제 #2
0
    def test_syncDraft(self):

        class Target(object):
            pass

        draft = Draft()
        draft.a1 = 1
        draft.a2 = 2

        target = Target()

        @adapter(Draft, Target)
        @implementer(IDraftSyncer)
        class Syncer1(object):

            def __init__(self, draft, target):
                self.draft = draft
                self.target = target

            def __call__(self):
                self.target.a1 = self.draft.a1

        provideAdapter(Syncer1, name=u's1')

        @adapter(Draft, Target)
        @implementer(IDraftSyncer)
        class Syncer2(object):

            def __init__(self, draft, target):
                self.draft = draft
                self.target = target

            def __call__(self):
                self.target.a2 = self.draft.a2

        provideAdapter(Syncer2, name=u's2')

        syncDraft(draft, target)

        self.assertEqual(1, target.a1)
        self.assertEqual(2, target.a2)
예제 #3
0
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()