Beispiel #1
0
    def updateWidgets(self, setErrors=True):
        if self.field is None:
            raise ValueError("%r .field is None, that's a blocking point" % self)

        self.setupWidgets()

        if self._value is interfaces.NO_VALUE:
            # XXX: maybe readonly fields/widgets should be reset here to
            #      widget.mode = INPUT_MODE
            pass
            for name, widget in self.widgets.items():
                if widget.field.readonly:
                    widget.mode = interfaces.INPUT_MODE
                    widget.update()
        else:
            rawvalue = None

            for name, widget in self.widgets.items():
                if widget.mode == interfaces.DISPLAY_MODE:
                    if rawvalue is None:
                        # lazy evaluation
                        converter = zope.component.getMultiAdapter(
                            (self.field, self),
                            interfaces.IDataConverter)
                        obj = self.getObject(self._value)
                        rawvalue = converter.toWidgetValue(obj)

                    self.applyValue(widget, rawvalue[name])
                else:
                    try:
                        v = self._value[name]
                    except KeyError:
                        pass
                    else:
                        self.applyValue(widget, v)
Beispiel #2
0
    def handle_edit(self, action):
        success = _(u"Successfully updated")
        partly_success = _(u"Some of your changes could not be applied.")
        status = no_changes = _(u"No changes made.")
        for subform in self.subforms:
            # With the ``extractData()`` call, validation will occur,
            # and errors will be stored on the widgets amongst other
            # places.  After this we have to be extra careful not to
            # call (as in ``__call__``) the subform again, since
            # that'll remove the errors again.  With the results that
            # no changes are applied but also no validation error is
            # shown.
            data, errors = subform.extractData()
            if errors:
                if status is no_changes:
                    status = subform.formErrorsMessage
                elif status is success:
                    status = partly_success
                continue
            del data["select"]
            self.context.before_update(subform.content, data)
            changes = subform.applyChanges(data)
            if changes:
                if status is no_changes:
                    status = success
                elif status is subform.formErrorsMessage:
                    status = partly_success

                # If there were changes, we'll update the view widgets
                # again, so that they'll actually display the changes
                for widget in subform.widgets.values():
                    if widget.mode == DISPLAY_MODE:
                        widget.update()
                        zope.event.notify(z3c.form.widget.AfterWidgetUpdateEvent(widget))
        self.status = status
Beispiel #3
0
    def updateWidgets(self, setErrors=True):
        if self.field is None:
            raise ValueError("%r .field is None, that's a blocking point" %
                             self)

        self.setupWidgets()

        if self._value is interfaces.NO_VALUE:
            # XXX: maybe readonly fields/widgets should be reset here to
            #      widget.mode = INPUT_MODE
            pass
            for name, widget in self.widgets.items():
                if widget.field.readonly:
                    widget.mode = interfaces.INPUT_MODE
                    widget.update()
        else:
            rawvalue = None

            for name, widget in self.widgets.items():
                if widget.mode == interfaces.DISPLAY_MODE:
                    if rawvalue is None:
                        # lazy evaluation
                        converter = zope.component.getMultiAdapter(
                            (self.field, self), interfaces.IDataConverter)
                        obj = self.getObject(self._value)
                        rawvalue = converter.toWidgetValue(obj)

                    self.applyValue(widget, rawvalue[name])
                else:
                    try:
                        v = self._value[name]
                    except KeyError:
                        pass
                    else:
                        self.applyValue(widget, v)
Beispiel #4
0
    def _load_widget_data(self):
        _marker = object()
        data = aq_base(self.context).data
        groups = dict((g.__name__, g) for g in self.groups)
        groupnames = [''] + groups.keys()
        for groupname in groupnames:
            group_data = data.get(groupname, None)
            if groupname is '':
                group = self
            else:
                group = groups.get(groupname)
                fieldgroup = self.definition[groupname]
                # # plone.autoform binds groups really, really late, so
                # # we are stuck with a GroupFactory object, we need to
                # # call it to get the actual group, then replace the
                # # group factory with it once we have manipulated
                # # any widget values:
                if IGroupFactory.providedBy(group):
                    idx = self.groups.index(group)
                    actual_group = group(self.context, self.request, self)
                    self.groups[idx] = group = actual_group
                    group.update()  # will populate group.widgets
                if group_data and fieldgroup.group_usage == 'grid':
                    data_widget = group.widgets.values()[0]
                    data_widget.value = getattr(group_data, 'data', [])
                    continue

            if group_data is not None:
                for formfield in group.fields.values():
                    schema_field = formfield.field
                    widgetname = formfield.__name__
                    fieldname = schema_field.__name__
                    v = getattr(group_data, fieldname, _marker)
                    if v is not _marker:
                        widget = group.widgets.get(widgetname)
                        conv = getMultiAdapter(
                            (schema_field, widget),
                            IDataConverter,
                        )
                        if not IDataGridField.providedBy(widget):
                            v = conv.toWidgetValue(v)
                        widget.value = v
                        if hasattr(widget, 'update'):
                            # may be necessary to copy value to other state,
                            # as is the case with radio button widgets
                            widget.update()
                            # multiple collection like set/list (multi-choice)
                            # has issues where SequenceWidget wants to reset
                            # widget.value during update... so we have to
                            # check the value (ugly hack) and also re-set the
                            # value for the display widget:
                            if ICollection.providedBy(schema_field):
                                widget.value = v
                                if v:
                                    term_item = [
                                        t for t in widget.items
                                        if t.get('value') == v[0]
                                    ][0]
                                    term_item['checked'] = True
Beispiel #5
0
    def _load_widget_data(self):
        _marker = object()
        data = aq_base(self.context).data
        groups = dict((g.__name__, g) for g in self.groups)
        groupnames = [''] + groups.keys()
        for groupname in groupnames:
            group_data = data.get(groupname, None)
            if groupname is '':
                group = self
            else:
                group = groups.get(groupname)
                fieldgroup = self.definition[groupname]
                # # plone.autoform binds groups really, really late, so
                # # we are stuck with a GroupFactory object, we need to
                # # call it to get the actual group, then replace the
                # # group factory with it once we have manipulated
                # # any widget values:
                if IGroupFactory.providedBy(group):
                    idx = self.groups.index(group)
                    actual_group = group(self.context, self.request, self)
                    self.groups[idx] = group = actual_group
                    group.update()  # will populate group.widgets
                if group_data and fieldgroup.group_usage == 'grid':
                    data_widget = group.widgets.values()[0]
                    data_widget.value = getattr(group_data, 'data', [])
                    continue

            if group_data is not None:
                for formfield in group.fields.values():
                    schema_field = formfield.field
                    widgetname = formfield.__name__
                    fieldname = schema_field.__name__
                    v = getattr(group_data, fieldname, _marker)
                    if v is not _marker:
                        widget = group.widgets.get(widgetname)
                        conv = getMultiAdapter(
                            (schema_field, widget),
                            IDataConverter,
                        )
                        if not IDataGridField.providedBy(widget):
                            v = conv.toWidgetValue(v)
                        widget.value = v
                        if hasattr(widget, 'update'):
                            # may be necessary to copy value to other state,
                            # as is the case with radio button widgets
                            widget.update()
                            # multiple collection like set/list (multi-choice)
                            # has issues where SequenceWidget wants to reset
                            # widget.value during update... so we have to
                            # check the value (ugly hack) and also re-set the
                            # value for the display widget:
                            if ICollection.providedBy(schema_field):
                                widget.value = v
                                if v:
                                    term_item = [
                                        t for t in widget.items
                                        if t.get('value') == v[0]
                                    ][0]
                                    term_item['checked'] = True
    def __call__(self):
        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        widget = self.context
        context = widget.context

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        widget.update()
        source = widget.bound_source

        # Convert token from request to the path to the object
        token = self.request.form.get('href', None)
        if token is not None:
            token = urllib.unquote(token)
        directory = self.context.bound_source.tokenToPath(token)
        level = self.request.form.get('rel', 0)

        navtree_query = source.navigation_tree_query.copy()

        if widget.show_all_content_types and 'portal_type' in navtree_query:
            del navtree_query['portal_type']

        if directory is not None:
            navtree_query['path'] = {'depth': 1, 'query': directory}

        if 'is_default_page' not in navtree_query:
            navtree_query['is_default_page'] = False

        content = closest_content(context)

        strategy = getMultiAdapter((content, widget), INavtreeStrategy)
        catalog = getToolByName(content, 'portal_catalog')

        children = []
        for brain in catalog(navtree_query):
            newNode = {
                'item': brain,
                'depth': -1,  # not needed here
                'currentItem': False,
                'currentParent': False,
                'children': []
            }
            if strategy.nodeFilter(newNode):
                newNode = strategy.decoratorFactory(newNode)
                children.append(newNode)

        self.request.response.setHeader('X-Theme-Disabled', 'True')

        return self.fragment_template(children=children, level=int(level))
Beispiel #7
0
    def __call__(self):
        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        widget = self.context
        context = widget.context

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        widget.update()
        source = widget.bound_source

        # Convert token from request to the path to the object
        token = self.request.form.get('href', None)
        if token is not None:
            token = urllib.unquote(token)
        directory = self.context.bound_source.tokenToPath(token)
        level = self.request.form.get('rel', 0)

        navtree_query = source.navigation_tree_query.copy()

        if widget.show_all_content_types and 'portal_type' in navtree_query:
            del navtree_query['portal_type']

        if directory is not None:
            navtree_query['path'] = {'depth': 1, 'query': directory}

        if 'is_default_page' not in navtree_query:
            navtree_query['is_default_page'] = False

        content = closest_content(context)

        strategy = getMultiAdapter((content, widget), INavtreeStrategy)
        catalog = getToolByName(content, 'portal_catalog')

        children = []
        for brain in catalog(navtree_query):
            newNode = {'item': brain,
                       'depth': -1,  # not needed here
                       'currentItem': False,
                       'currentParent': False,
                       'children': []}
            if strategy.nodeFilter(newNode):
                newNode = strategy.decoratorFactory(newNode)
                children.append(newNode)

        self.request.response.setHeader('X-Theme-Disabled', 'True')

        return self.fragment_template(children=children, level=int(level))
    def __call__(self):
        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        widget = self.context
        context = widget.context

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        widget.update()
        source = widget.bound_source

        # Convert token from request to the path to the object
        token = self.request.form.get("href", None)
        directory = self.context.bound_source.tokenToPath(token)
        level = self.request.form.get("rel", 0)

        navtree_query = source.navigation_tree_query.copy()
        if directory is not None:
            navtree_query["path"] = {"depth": 1, "query": directory}

        if "is_default_page" not in navtree_query:
            navtree_query["is_default_page"] = False

        content = closest_content(context)

        strategy = getMultiAdapter((content, widget), INavtreeStrategy)
        catalog = getToolByName(content, "portal_catalog")

        children = []
        for brain in catalog(navtree_query):
            newNode = {
                "item": brain,
                "depth": -1,  # not needed here
                "currentItem": False,
                "currentParent": False,
                "children": [],
            }
            if strategy.nodeFilter(newNode):
                newNode = strategy.decoratorFactory(newNode)
                children.append(newNode)

        self.request.response.setHeader("X-Theme-Disabled", "True")

        return self.fragment_template(children=children, level=int(level))
    def __call__(self):

        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        widget = self.context
        context = widget.context

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        widget.update()
        source = widget.bound_source

        # Convert token from request to the path to the object
        token = self.request.form.get('href', None)
        directory = self.context.bound_source.tokenToPath(token)

        navtree_query = source.navigation_tree_query.copy()
        navtree_query['path'] = {'query': directory}

        if 'is_default_page' not in navtree_query:
            navtree_query['is_default_page'] = False
        if navtree_query['is_default_page'] in [(True,False), (False, True)]:
            del navtree_query['is_default_page']

        content = context
        if not IAcquirer.providedBy(content):
            content = closest_content(context)

        catalog = getToolByName(content, 'portal_catalog')
        results = catalog(navtree_query)

        if len(results) > 0:
            obj = results[0].getObject()

            preview = queryMultiAdapter(
                (obj, self.context), IContentTreeWidgetPreview)

            if preview is None:
                return _(u"No preview available.")

            return preview()
    def __call__(self):
        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        widget = self.context
        context = widget.context

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        widget.update()
        source = widget.bound_source

        # Convert token from request to the path to the object
        token = self.request.form.get('href', None)
        if token is not None:
            token = urllib.unquote(token)
        directory = self.context.bound_source.tokenToPath(token)
        level = self.request.form.get('rel', 0)

        navtree_query = source.navigation_tree_query.copy()

        if widget.show_all_content_types and 'portal_type' in navtree_query:
            del navtree_query['portal_type']

        if directory is not None:
            navtree_query['path'] = {'depth': 1, 'query': directory}

        if 'is_default_page' not in navtree_query:
            navtree_query['is_default_page'] = False

        children = self._children(navtree_query)

        self.request.response.setHeader('X-Theme-Disabled', 'True')

        return self.fragment_template(children=children, level=int(level))
    def __call__(self):

        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        widget = self.context
        context = widget.context

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        widget.update()
        source = widget.bound_source

        # Convert token from request to the path to the object
        token = self.request.form.get("href", None)
        directory = self.context.bound_source.tokenToPath(token)
        level = self.request.form.get("rel", 0)

        navtree_query = source.navigation_tree_query.copy()
        navtree_query["path"] = {"query": directory}

        if "is_default_page" not in navtree_query:
            navtree_query["is_default_page"] = False

        content = context
        if not IAcquirer.providedBy(content):
            content = closest_content(context)

        strategy = getMultiAdapter((content, widget), INavtreeStrategy)
        catalog = getToolByName(content, "portal_catalog")
        results = catalog(navtree_query)

        if len(results) > 0:
            return self.template(node=results[0].getObject())
Beispiel #12
0
    def handle_edit(self, action):
        success = _(u"Successfully updated")
        partly_success = _(u"Some of your changes could not be applied.")
        status = no_changes = _(u"No changes made.")
        for subform in self.subforms:
            # With the ``extractData()`` call, validation will occur,
            # and errors will be stored on the widgets amongst other
            # places.  After this we have to be extra careful not to
            # call (as in ``__call__``) the subform again, since
            # that'll remove the errors again.  With the results that
            # no changes are applied but also no validation error is
            # shown.
            data, errors = subform.extractData()
            if errors:
                if status is no_changes:
                    status = subform.formErrorsMessage
                elif status is success:
                    status = partly_success
                continue
            del data['select']
            self.context.before_update(subform.content, data)
            changes = subform.applyChanges(data)
            if changes:
                if status is no_changes:
                    status = success
                elif status is subform.formErrorsMessage:
                    status = partly_success

                # If there were changes, we'll update the view widgets
                # again, so that they'll actually display the changes
                for widget in subform.widgets.values():
                    if widget.mode == DISPLAY_MODE:
                        widget.update()
                        zope.event.notify(
                            z3c.form.widget.AfterWidgetUpdateEvent(widget))
        self.status = status