How to use the deform.widget.CheckboxChoiceWidget 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 websauna / websauna / websauna / system / form / fieldmapper.py View on Github external
if mode in (EditMode.add, EditMode.edit):
                default_choice = "--- Choose one ---"
            else:
                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
github VoteIT / voteit.core / voteit / core / schemas / agenda_item.py View on Github external
def ai_tags_widget(node, kw):
    request = kw['request']
    tags = sorted(request.meeting.tags, key=lambda x: x.lower())
    values = [(x, x) for x in tags]
    return deform.widget.CheckboxChoiceWidget(values=values)
github VoteIT / voteit.core / voteit / core / plugins / immediate_ap.py View on Github external
view.flash_messages.add(_("Access granted - welcome!"))
        return HTTPFound(location = view.request.resource_url(self.context))

    def config_schema(self):
        return ImmediateAPConfigSchema()


class ImmediateAPConfigSchema(colander.Schema):
    title = _("Configure immediate access policy")
    immediate_access_grant_roles = colander.SchemaNode(
        colander.Set(),
        title = _("Roles"),
        description = _("immediate_ap_schema_grant_description",
                        default = "Users will be granted these roles IMMEDIATELY upon requesting access."),
        default = _DEFAULT_ROLES,
        widget = deform.widget.CheckboxChoiceWidget(values=security.STANDARD_ROLES,),
    )


def includeme(config):
    config.registry.registerAdapter(ImmediateAP, name = ImmediateAP.name)
github Pylons / deform / deformdemo / app.py View on Github external
        @colander.deferred
        def deferred_checkbox_widget(node, kw):
            return deform.widget.CheckboxChoiceWidget(values=choices)
github hypothesis / h / h / accounts / schemas.py View on Github external
if value.get('new_password') != value.get('new_password_confirm'):
            exc['new_password_confirm'] = _('The passwords must match')

        if not svc.check_password(user, value.get('password')):
            exc['password'] = _('Wrong password.')

        if exc.children:
            raise exc


class NotificationsSchema(CSRFSchema):
    types = (('reply', _('Email me when someone replies to one of my annotations.'),),)

    notifications = colander.SchemaNode(
        colander.Set(),
        widget=deform.widget.CheckboxChoiceWidget(
            omit_label=True,
            values=types),
    )


def includeme(config):
    pass
github VoteIT / voteit.core / voteit / core / schemas / invite_ticket.py View on Github external
#Note that validation for token depends on email, so it can't be set at field level.
    token = colander.SchemaNode(colander.String(),
                                title = _(u"claim_ticket_token_title",
                                          default = u"The access token your received in your email."),)


class AddTicketsSchema(colander.Schema):
    roles = colander.SchemaNode(
        colander.Set(),
        title = _(u"Roles"),
        default = (security.ROLE_VIEWER, security.ROLE_DISCUSS, security.ROLE_PROPOSE, security.ROLE_VOTER),
        description = _(u"add_tickets_roles_description",
                        default = u"""One user can have more than one role. Note that to be able to propose,
                        discuss and vote you need respective role. This is selected by default. If you want
                        to add a user that can only view, select View and uncheck everything else."""),
        widget = deform.widget.CheckboxChoiceWidget(values=security.MEETING_ROLES,),
    )
    emails = colander.SchemaNode(colander.String(),
                                 title = _(u"add_tickets_emails_titles",
                                           default=u"Email addresses to give the roles above."),
                                 description = _(u"add_tickets_emails_description",
                                                 default=u'Separate email addresses with a single line break.'),
                                 widget = deform.widget.TextAreaWidget(rows=7, cols=40),
                                 preparer = strip_and_lowercase,
                                 validator = colander.All(no_html_validator, multiple_email_validator),
    )
    message = colander.SchemaNode(colander.String(),
                                  title = _(u"Welcome text of the email that will be sent"),
                                  description = _(u"ticket_message_description",
                                                  default = u"The mail will contain instructions on how to access the meeting, "
                                                        u"so focus on anything that might be specific for your participants."),
                                  widget = deform.widget.TextAreaWidget(rows=5, cols=40),
github websauna / websauna / websauna / system / form / widget.py View on Github external
"""Extra widgets.

Mostly for high level integration.
"""
from colander import null, string_types
import deform
from deform.widget import _normalize_choices
from websauna.utils.slug import uuid_to_slug


class RelationshipCheckboxWidget(deform.widget.CheckboxChoiceWidget):
    """Choose a group of relationships.

    .. note ::

        TODO: This widget needs to die. This is a hack using the default ColanderAlchemy dictify() format which dumps the whole object in relationship as dictionary for us. We are only interested in the relationship object ids. Fix this so that Colander schema can give us list of ids, or even SQLAlchemy model instances themselves.
    """

    #: The model which we are using as the base for the queries
    model = None

    template = 'checkbox_choice'
    readonly_template = 'readonly/checkbox_choice'

    #: callable(obj) which translates raw SQLAlchemy instance to a tuple (id, human readable label)
    make_entry = lambda obj: (obj.id, str(obj.id))
github VoteIT / voteit.core / voteit / core / schemas / poll.py View on Github external
context = kw['context']
    #Proposals to vote on
    proposal_choices = set()
    agenda_item = find_interface(context, IAgendaItem)
    if agenda_item is None:
        Exception("Couldn't find the agenda item from this polls context")
    #Get valid proposals - should be in states 'published' to be selectable
    #FIXME: Wrong sorting!
    for prop in agenda_item.get_content(iface=IProposal, states='published', sort_on='title'):
        proposal_choices.add((prop.uid, "#%s | %s" % (prop.aid, prop.title)))
    # get currently chosen proposals
    if IPoll.providedBy(context):
        for prop in context.get_proposal_objects():
            proposal_choices.add((prop.uid, prop.title, ))
    proposal_choices = sorted(proposal_choices, key=lambda proposal: proposal[1].lower())
    return deform.widget.CheckboxChoiceWidget(values=proposal_choices)
github VoteIT / voteit.core / voteit / core / schemas / proposal.py View on Github external
def proposal_states_widget(node, kw):
    wf = get_workflow(IProposal, 'Proposal')
    state_values = []
    ts = _
    for info in wf._state_info(IProposal):  # Public API goes through permission checker
        item = [info['name']]
        item.append(ts(info['title']))
        state_values.append(item)
    return deform.widget.CheckboxChoiceWidget(values=state_values)