Exemplo n.º 1
0
    def show(self):
        context = aq_inner(self.context)
        tinymce = queryUtility(ITinyMCE, context=context)

        if tinymce is None:
            return False

        if HAS_DX:
            form = self.__parent__
            if IFormWrapper.providedBy(form):
                form = form.form_instance

        # Case 1: Dexterity and z3c.form
        if HAS_DX and z3cform.IForm.providedBy(form):
            rtfields = [
                widget.field.__name__ for widget
                in form.widgets.values() if IRichTextWidget.providedBy(
                    widget)
                ]

            if not rtfields:
                return False

            prefix = (form.prefix + form.widgets.prefix).replace(
                '.', '\\\\.'
                )

        # Case 2: Archetypes
        elif HAS_AT and IBaseObject.providedBy(context):
            rtfields = self.getATRichTextFieldNames()
            prefix = ''

        # Case 3: Formlib
        elif formlib.IForm.providedBy(self.view):
            rtfields = [field.__name__ for field in self.view.form_fields
                        if field.custom_widget == WYSIWYGWidget]
            prefix = 'form\\\\.'

        # Case 4: Everything else!
        else:
            return False

        self.suffix = self.buildsuffix(rtfields, prefix)

        # Handle Archetypes factory pages.
        if not prefix:
            factory = getToolByName(context, 'portal_factory', None)
            if factory is not None and factory.isTemporary(context):
                # Always include TinyMCE on temporary pages These are
                # meant for editing and get false positives with
                # the `showEditableBorder` method.
                return True

            plone_view = getMultiAdapter((context, self.request), name="plone")
            return plone_view.showEditableBorder() and rtfields

        return rtfields
Exemplo n.º 2
0
    def show(self):
        context = aq_inner(self.context)
        tinymce = queryUtility(ITinyMCE, context=context)

        if tinymce is None:
            return False

        if HAS_DX:
            form = self.__parent__
            if IFormWrapper.providedBy(form):
                form = form.form_instance

        # Case 1: Dexterity and z3c.form
        if HAS_DX and z3cform.IForm.providedBy(form):
            rtfields = [
                widget.field.__name__ for widget
                in form.widgets.values() if IRichTextWidget.providedBy(
                    widget)
                ]

            if not rtfields:
                return False

            prefix = (form.prefix + form.widgets.prefix).replace(
                '.', '\\\\.'
                )

        # Case 2: Archetypes
        elif HAS_AT and IBaseObject.providedBy(context):
            rtfields = self.getATRichTextFieldNames()
            prefix = ''

        # Case 3: Formlib
        elif formlib.IForm.providedBy(self.view) and hasattr(self.view,'form_fields'):
            rtfields = [field.__name__ for field in self.view.form_fields
                        if field.custom_widget == WYSIWYGWidget]
            prefix = 'form\\\\.'

        # Case 4: Everything else!
        else:
            return False

        self.suffix = self.buildsuffix(rtfields, prefix)

        # Handle Archetypes factory pages.
        if not prefix:
            factory = getToolByName(context, 'portal_factory', None)
            if factory is not None and factory.isTemporary(context):
                # Always include TinyMCE on temporary pages These are
                # meant for editing and get false positives with
                # the `showEditableBorder` method.
                return True

            plone_view = getMultiAdapter((context, self.request), name="plone")
            return plone_view.showEditableBorder() and rtfields

        return rtfields
Exemplo n.º 3
0
    def validate_input(self, formname, fieldname, fieldset=None, value=None,
                       warning_only=True):
        """Given a form (view) name, a field name and the submitted
        value, validate the given field.
        """

        # Abort if there was no value changed. Note that the actual value
        # comes along the submitted form, since a widget may require more than
        # a single form field to validate properly.
        if value is None:
            return

        context = aq_inner(self.context)
        request = aq_inner(self.request)
        alsoProvides(request, IFormLayer)

        # Find the form, the field and the widget
        form = request.traverseName(context, formname)
        if IFormWrapper.providedBy(form):
            formWrapper = form
            form = form.form_instance
            if not z2.IFixedUpRequest.providedBy(request):
                z2.switch_on(form, request_layer=formWrapper.request_layer)

        if not IForm.providedBy(form):
            return

        form.update()
        
        if getattr(form, "extractData", None):
            data, errors = form.extractData()
        else:
            return

        #if we validate a field in a group we operate on the group
        if fieldset is not None:
            fieldset = int(fieldset)
            form = form.groups[fieldset]

        index = len(form.prefix) + len(form.widgets.prefix)
        raw_fieldname = fieldname[index:]
        validationError = None
        for error in errors:
            if error.widget == form.widgets.get(raw_fieldname, None):
                validationError = error.message
                break

        if isinstance(validationError, Message):
            validationError = translate(validationError, context=self.request)

        # Attempt to convert the value - this will trigger validation
        ksscore = self.getCommandSet('core')
        kssplone = self.getCommandSet('plone')
        validate_and_issue_message(ksscore, validationError, fieldname,
                                   fieldset, kssplone, warning_only)
Exemplo n.º 4
0
    def update(self):
        form = self.__parent__

        if IFormWrapper.providedBy(form):
            form = form.form_instance

        if not IAddForm.providedBy(form):
            return

        uuid = self.request.form.get('translation')
        language = self.request.form.get('language')
        if not uuid or not language:
            return

        obj = getObjectByuuid(self.context, uuid)

        context_state = getMultiAdapter(
            (obj, self.request), name=u"plone_context_state"
            )

        # This is now the parent of the item that we're trying to
        # create a new translation for!
        obj = context_state.parent()

        # If it's the site root, then we're done.
        if IPloneSiteRoot.providedBy(obj):
            return

        # Now we just need to check if the parent has already been
        # translated into the required language in which case we're
        # also done.
        translations = ITranslationGraph(obj).getTranslations()
        if language in dict(translations):
            return

        # Okay, we'll show the notice.
        self.available = True
        self.folder = obj
        self.language = self.request.locale.displayNames.languages.\
                        get(language)
Exemplo n.º 5
0
    def update(self):
        form = self.__parent__

        if IFormWrapper.providedBy(form):
            form = form.form_instance

        if not IAddForm.providedBy(form):
            return

        uuid = self.request.form.get('translation')
        language = self.request.form.get('language')
        if not uuid or not language:
            return

        obj = getObjectByuuid(self.context, uuid)

        context_state = getMultiAdapter((obj, self.request),
                                        name=u"plone_context_state")

        # This is now the parent of the item that we're trying to
        # create a new translation for!
        obj = context_state.parent()

        # If it's the site root, then we're done.
        if IPloneSiteRoot.providedBy(obj):
            return

        # Now we just need to check if the parent has already been
        # translated into the required language in which case we're
        # also done.
        translations = ITranslationGraph(obj).getTranslations()
        if language in dict(translations):
            return

        # Okay, we'll show the notice.
        self.available = True
        self.folder = obj
        self.language = self.request.locale.displayNames.languages.\
                        get(language)