def test_mark(self): request = self.request current = ICurrentDraftManagement(request) current.mark() self.failIf(IDrafting.providedBy(request)) current.targetKey = u"123" current.mark() self.failUnless(IDrafting.providedBy(request))
def test_mark(self): request = self.request current = ICurrentDraftManagement(request) current.mark() self.assertFalse(IDrafting.providedBy(request)) current.targetKey = u'123' current.mark() self.assertTrue(IDrafting.providedBy(request))
def draftingTileDataContext(context, request, tile): """If we are drafting a content item, record tile data information to the draft, but read existing data from the underlying object. """ # When drafted content with tiles is saved, IDrafting is provided if IDrafting.providedBy(request): if request.method == 'POST': draft = getCurrentDraft(request, create=True) else: draft = getCurrentDraft(request, create=False) if draft is None: return context # When tile is previewed during drafted content is edited, heuristics... else: # Manually configure draft user id, if we are still in traverse if getattr(request, 'PUBLISHED', None) is None: IAnnotations(request)[USERID_KEY] = request.cookies.get(USERID_KEY) # No active draft for the request draft = getCurrentDraft(request) if draft is None: return context # Not referring from an edit form referrer = request.get('HTTP_REFERER', '') path = urlparse(referrer).path if all((not path.endswith('/edit'), not path.endswith('/@@edit'), not path.split('/')[-1].startswith('++add++'))): return context ICurrentDraftManagement(request).mark() return DraftProxy(draft, context)
def cancel(event): if not IDrafting.providedBy(event.action.request): return if event.action.name != 'form.buttons.cancel': return discardDraftsOnCancel(event.action.form.context, event)
def save(event): if not IDrafting.providedBy(event.action.request): return if event.action.name != 'form.buttons.save': return data, errors = event.action.form.extractData() if errors: return if IAddForm.providedBy(event.action.form): draft = getCurrentDraft(event.action.form.request) target = getattr(draft, '_draftAddFormTarget') if target: syncDraftOnSave(target, event) else: syncDraftOnSave(event.action.form.context, event)
def save(event): if not IDrafting.providedBy(event.action.request): return if event.action.name != 'form.buttons.save': return data, errors = event.action.form.extractData() if errors: return if IAddForm.providedBy(event.action.form): draft = getCurrentDraft(event.action.form.request) target = getattr(draft, '_draftAddFormTarget', None) if target: syncDraftOnSave(target, event) else: discardDraftsOnCancel(event.action.form.context, event) else: syncDraftOnSave(event.action.form.context, event)
def subscriber(event): # Only listen to ObjectModifiedEvent if not isinstance(event, ObjectModifiedEvent): return # Only listen when we are drafting request = getRequest() if not IDrafting.providedBy(request): return # Only listen if its our drafting target, which has been modified drafting = ICurrentDraftManagement(request, None) if drafting is None: return source = IUUID(event.object, None) if source is None or source != drafting.targetKey: return # Sync draft now before indexers are called syncDraftOnSave(event.object, event)