def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if IDraftable.__identifier__ in fti.behaviors:
            draft = getCurrentDraft(request, create=False)
            target = getattr(draft, '_draftAddFormTarget',
                             createContent(form.portal_type))

            if draft is None:
                IMutableUUID(target).set('++add++%s' % form.portal_type)
                beginDrafting(target.__of__(context), None)
                draft = getCurrentDraft(request, create=True)
                draft._draftAddFormTarget = target

                # Disable Plone 5 implicit CSRF when no form action
                if HAS_PLONE_PROTECT:
                    if not ([key for key in request.form
                             if key.startswith('form.buttons.')]):
                        alsoProvides(request, IDisableCSRFProtection)
            else:
                current = ICurrentDraftManagement(request)
                current.mark()

            context = DraftProxy(draft, target.__of__(context))
            alsoProvides(request, IAddFormDrafting)

        super(DefaultAddFormFieldWidgets, self).__init__(form, request, context)  # noqa
Beispiel #2
0
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey is None:
                beginDrafting(context, None)
                current.path = '/'.join(context.getPhysicalPath())
                current.targetKey = IUUID(context)
                current.save()
            else:
                current.mark()

            if current.draft:
                context = DraftProxy(current.draft, context)
                alsoProvides(request, IEditFormDrafting)

        super(DefaultEditFormFieldWidgets, self).__init__(form, request, context)  # noqa
Beispiel #3
0
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if isDraftable(fti):
            current = ICurrentDraftManagement(request)

            if current.targetKey != '++add++{0}'.format(form.portal_type):
                beginDrafting(context, None)
                current.path = '/'.join(context.getPhysicalPath())
                current.targetKey = '++add++{0}'.format(form.portal_type)
                current.save()
            else:
                current.mark()

            target = getattr(current.draft, '_draftAddFormTarget', None)
            if current.draft and target:
                context = DraftProxy(current.draft, target.__of__(context))
                alsoProvides(request, IAddFormDrafting)

        super(DefaultAddFormFieldWidgets, self).__init__(form, request, context)  # noqa
    def __init__(self, form, request, context):
        fti = queryUtility(IDexterityFTI, name=form.portal_type)
        if IDraftable.__identifier__ in fti.behaviors:
            draft = getCurrentDraft(request, create=False)

            if draft is None:
                beginDrafting(context, None)
                draft = getCurrentDraft(request, create=True)

                # Disable Plone 5 implicit CSRF when no form action
                if HAS_PLONE_PROTECT:
                    if not ([key for key in request.form
                             if key.startswith('form.buttons.')]):
                        alsoProvides(request, IDisableCSRFProtection)
            else:
                current = ICurrentDraftManagement(request)
                current.mark()

            context = DraftProxy(draft, context)
            alsoProvides(request, IEditFormDrafting)

        super(DefaultEditFormFieldWidgets, self).__init__(form, request, context)  # noqa