How to use the deform.widget.SelectWidget function in deform

To help you get started, we’ve selected a few deform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kotti / deform_bootstrap / deform_bootstrap / widget.py View on Github external
if (not _date and not _time):
                return null

            if not _date:
                raise Invalid(field.schema, _('Incomplete date'), "")

            if not _time:
                _time = "00:00:00"

            result = ' '.join([_date, _time])

            return result


class ChosenSingleWidget(SelectWidget):
    template = 'chosen_single'
    requirements = (('chosen', None), )


class ChosenOptGroupWidget(SelectWidget):
    template = 'chosen_optgroup'
    requirements = (('chosen', None), )

    def serialize(self, field, cstruct, readonly=False):
        if cstruct in (null, None):
            cstruct = self.null_value
        template = readonly and self.readonly_template or self.template
        return field.renderer(template, field=field, cstruct=cstruct,
                              values=_normalize_optgroup_choices(self.values))
github eea / eea.corpus / src / eea.corpus / eea / corpus / schema.py View on Github external
def pipeline_components_widget(node, kw):
    values = [('', '-Select-')]
    values += [(p.name, p.title) for p in pipeline_registry.values()]

    return deform.widget.SelectWidget(
            template="pipeline_select",
            values=values,
        )
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / sheets / localroles.py View on Github external
def widget(self, kw: dict) -> []:
        """Return widget  based on the `/principals/groups` service."""
        from adhocracy_core.resources.principal import IGroup
        context = kw['context']
        groups = find_service(context, 'principals', 'groups')
        values = [('group:' + x, x) for x, y in groups.items()
                  if IGroup.providedBy(y)]
        return SelectWidget(values=values)
github nandoflorestan / bag / bag / web / pyramid / locale.py View on Github external
"""Let the user select a locale from the enabled ones.

    If you use Deform, you can use this to get a SchemaNode for that.
    """
    import colander as c
    import deform as d

    def options():
        if blank_option_at_top:
            yield ('', _('- Choose -'))
        for loc in settings[SETTING_NAME].values():
            yield (loc.code, loc.display_name)
    values = sorted(options(), key=lambda t: _(t[1]))
    return c.SchemaNode(c.Str(), title=title, name=name,
                        validator=locale_exists_validator(settings),
                        widget=d.widget.SelectWidget(values=values))
github hypothesis / h / h / schemas / forms / admin / group.py View on Github external
def group_organization_select_widget(node, kw):
    orgs = kw["organizations"]
    org_labels = []
    org_pubids = []
    for org in orgs.values():
        org_labels.append("{} ({})".format(org.name, org.authority))
        org_pubids.append(org.pubid)

    # `zip` returns an iterator. The `SelectWidget` constructor requires an
    # actual list.
    return SelectWidget(values=list(zip(org_pubids, org_labels)))
github Pylons / deform / deform / widget.py View on Github external
**Attributes/Arguments**

    Same as :func:`~deform.widget.SelectWidget`, with some extra options
    listed here.

    tags: *bool*
        Allow dynamic option creation ( default: ``False`` ).
        See `select2 docs on tagging `_ for
        more details.
    """

    template = "select2"
    requirements = (("deform", None), ("select2", None))


class RadioChoiceWidget(SelectWidget):
    """
    Renders a sequence of ``<input type="radio">`` buttons based on a
    predefined set of values.

    **Attributes/Arguments**

    values
        A sequence of two-tuples (the first value must be of type
        string, unicode or integer, the second value must be string or
        unicode) indicating allowable, displayed values, e.g. ``(
        ('true', 'True'), ('false', 'False') )``.  The first element
        in the tuple is the value that should be returned when the
        form is posted.  The second is the display value.

    template
        The template name used to render the widget.  Default:
github VoteIT / voteit.core / voteit / core / schemas / proposal.py View on Github external
def proposal_naming_widget(node, kw):
    request = kw['request']
    values = [(x.name, x.factory.title) for x in request.registry.registeredAdapters()
              if x.provided == IProposalIds]
    return deform.widget.SelectWidget(values=values)
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / sheets / workflow.py View on Github external
def widget(self, kw: dict) -> Widget:
        states = [(x, x) for x in self.validator.choices]
        return SelectWidget(values=states)
github websauna / websauna / websauna / system / form / fieldmapper.py View on Github external
default_choice = "(not set)"

            if required:
                missing = colander.required
            else:
                missing = None

            vocabulary = get_uuid_vocabulary_for_model(dbsession, remote_model, default_choice=default_choice)

            if rel.uselist:
                # Show out all relationships
                if mode == EditMode.show:
                    return colander.SchemaNode(UUIDModelSet(remote_model), name=name, missing=missing, widget=deform.widget.CheckboxChoiceWidget(values=vocabulary))
            else:
                # Select from a single relationship
                return colander.SchemaNode(UUIDForeignKeyValue(remote_model), name=name, missing=missing, widget=deform.widget.SelectWidget(values=vocabulary))

        return TypeOverridesHandling.drop