示例#1
0
文件: widget.py 项目: eleddy/z3c.form
def addFieldClass(widget):
    """Add a class to the widget that is based on the field type name.

    If the widget does not have field, then nothing is done.
    """
    if IFieldWidget.providedBy(widget):
        klass = unicode(widget.field.__class__.__name__.lower() + '-field')
        widget.addClass(klass)
示例#2
0
文件: widget.py 项目: bendavis78/zope
def addFieldClass(widget):
    """Add a class to the widget that is based on the field type name.

    If the widget does not have field, then nothing is done.
    """
    if IFieldWidget.providedBy(widget):
        klass = unicode(widget.field.__class__.__name__.lower() + '-field')
        widget.addClass(klass)
示例#3
0
文件: select.py 项目: PMR2/pmr2.app
    def update(self):
        """\
        Customized update method.
        """

        # Since we are interested in acquring what the context had first
        # before we are interested in what was submitted in the request,
        # we forcibly set ignoreRequest on and continue as normal.  Once
        # that is done, process the request as normal.

        ignoreRequest = self.ignoreRequest
        self.ignoreRequest = True
        super(StorageFileSelectWidget, self).update()
        # Restore original value.
        self.ignoreRequest = ignoreRequest

        if not ignoreRequest:
            # Extract the request value like how the parent would have 
            # done
            widget_value = self.extract()

            if widget_value not in (NO_VALUE, INVALID_VALUE):
                # Only set the widget with the value from request that
                # is valid
                self.value = widget_value
                # As this deferred self.value assignment from request
                # is complete, with everything else done, return here.
                return

        # The follow are steps that should also have been done inside
        # step 1.2 in that method.  To begin validate that the
        # applicable conditions are available.
        if not IFieldWidget.providedBy(self):
            return

        # Always set errors, since context could provide an invalid
        # value due to changing conditions.
        self.setErrors = True

        # Now verify that the current widget value (which is extracted
        # by the data manager) is valid, attempt the conversion back to
        # the field value using toFieldValue as the reverse method
        # toWidgetValue does not and cannot raise exceptions due to
        # how and where it is used by the parent update method.

        converter = IDataConverter(self)
        try:
            converter.toFieldValue(self.value)
        except (zope.interface.Invalid, ValueError), error:
            # We have an exception, so we adapt and set the error view.
            view = zope.component.getMultiAdapter(
                (error, self.request, self, self.field,
                 self.form, self.context), IErrorViewSnippet)
            view.update()
            self.error = view
示例#4
0
    def get_type(self, item):
        """differ the object typ and return the type as string"""

        if isinstance(item, dict):
            return 'dict'
        elif ICatalogBrain.providedBy(item):
            return 'brain'
        elif IContentListingObject.providedBy(item):
            return 'contentlistingobject'
        elif IFieldWidget.providedBy(item):
            return 'widget'
        elif isinstance(item, Task):
            return 'globalindex_task'
        else:
            raise ValueError("Unknown item type: {!r}".format(item))
    def get_type(self, item):
        """differ the object typ and return the type as string"""

        if isinstance(item, dict):
            return 'dict'
        elif ICatalogBrain.providedBy(item):
            return 'brain'
        elif IContentListingObject.providedBy(item):
            return 'contentlistingobject'
        elif IFieldWidget.providedBy(item):
            return 'widget'
        elif isinstance(item, Task):
            return 'globalindex_task'
        else:
            raise ValueError("Unknown item type: {!r}".format(item))
示例#6
0
    def test_widget(self):
        """ """
        with open(os.path.join(FHIR_FIXTURE_PATH, 'Organization.json'), 'r') as f:
            json_object_str = f.read()

        request = TestRequest(form={'resource': json_object_str})
        json_widget = widget.JSONWidget(request)
        json_widget.name = 'resource'

        self.assertTrue(widget.IJSONWidget.providedBy(json_widget))
        self.assertIsNone(json_widget.value)
        json_widget.update()

        self.assertEqual(json_widget.value, json_object_str)
        json_field = getFields(ITestToken)['resource']

        field_widget = widget.JSONFieldWidget(json_field, request)
        self.assertTrue(IFieldWidget.providedBy(field_widget))