Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)