def setUp(self):
     super(TestLaunchpadRadioWidgetWithDescription, self).setUp()
     self.request = LaunchpadTestRequest()
     field = Choice(__name__='test_field', vocabulary=self.TestEnum)
     self.field = field.bind(object())
     self.widget = LaunchpadRadioWidgetWithDescription(
         self.field, self.TestEnum, self.request)
Exemple #2
0
 def test_create_vocabulary(self):
     vocabulary.setVocabularyRegistry(DummyRegistry())
     field = Choice(vocabulary="vocab")
     o = object()
     bound = field.bind(o)
     self.assertEqual([term.value for term in bound.vocabulary],
                      [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
 def setUp(self):
     super(ItemWidgetTestCase, self).setUp()
     self.request = LaunchpadTestRequest()
     self.vocabulary = SimpleVocabulary([self.SAFE_TERM, self.UNSAFE_TERM])
     field = Choice(__name__='test_field', vocabulary=self.vocabulary)
     self.field = field.bind(object())
     self.widget = self.WIDGET_CLASS(
         self.field, self.vocabulary, self.request)
Exemple #4
0
 def test_ChoiceInputWidget(self):
     ztapi.provideMultiView((IChoice, IIterableVocabulary), IBrowserRequest,
                            IInputWidget, '', DropdownWidget)
     field = Choice(values=[1, 2, 3])
     bound = field.bind(object())
     widget = ChoiceInputWidget(bound, TestRequest())
     self.assert_(isinstance(widget, DropdownWidget))
     self.assertEqual(widget.context, bound)
     self.assertEqual(widget.vocabulary, bound.vocabulary)
Exemple #5
0
 def test_get_widgets_for_schema_fields(self):
     salutation = Choice(title=u'Salutation', values=("Mr.", "Mrs.", "Captain", "Don"))
     contactname = TextLine(title=u'Name')
     request = FakeRequest()
     salutation = salutation.bind(request)
     contactname = contactname.bind(request)
     view1 = getViewProviding(contactname, IInputWidget, request)
     self.assertEquals(view1.__class__, zope.app.form.browser.textwidgets.TextWidget)
     view2 = getViewProviding(salutation, IInputWidget, request)
     self.assertEquals(view2.__class__, zope.app.form.browser.itemswidgets.DropdownWidget)
 def test_ChoiceDisplayWidget(self):
     provideAdapter(ItemDisplayWidget,
                    (IChoice, IIterableVocabulary, IBrowserRequest),
                    IDisplayWidget)
     field = Choice(values=[1, 2, 3])
     bound = field.bind(object())
     widget = ChoiceDisplayWidget(bound, TestRequest())
     self.assert_(isinstance(widget, ItemDisplayWidget))
     self.assertEqual(widget.context, bound)
     self.assertEqual(widget.vocabulary, bound.vocabulary)
 def setUp(self):
     super(TestSuggestionWidget, self).setUp()
     request = LaunchpadTestRequest()
     vocabulary = SimpleHugeVocabulary(
         [self.SAFE_TERM, self.UNSAFE_TERM])
     provideUtility(
         vocabulary, provides=IVocabularyFactory,
         name='SimpleHugeVocabulary')
     field = Choice(
         __name__='test_field', vocabulary="SimpleHugeVocabulary")
     field = field.bind(object())
     self.widget = self.ExampleSuggestionWidget(
         field, vocabulary, request)
Exemple #8
0
 def test_validate_mixed(self):
     choice = Choice(values=[1, 'b', (0.2,)])
     choice.validate(1)
     choice.validate('b')
     choice.validate((0.2,))
     self.assertRaises(ConstraintNotSatisfied, choice.validate, '1')
     self.assertRaises(ConstraintNotSatisfied, choice.validate, 0.2)
    def setUpFields(self):
        """See `LaunchpadFormView`.

        The schema permits the series field to be None (required=False) to
        create the milestone, but once a series field is set, None is invalid.
        The choice for the series is redefined to ensure None is not included.
        """
        super(MilestoneEditView, self).setUpFields()
        if self.context.product is None:
            # This is a distribution milestone.
            choice = Choice(
                __name__='distroseries', vocabulary="FilteredDistroSeries")
        else:
            choice = Choice(
                __name__='productseries', vocabulary="FilteredProductSeries")
        choice.title = _("Series")
        choice.description = _("The series for which this is a milestone.")
        field = form.Fields(choice, render_context=self.render_context)
        # Remove the schema's field, then add back the replacement field.
        self.form_fields = self.form_fields.omit(choice.__name__) + field
class ITextLineTest(Interface):
    s1 = TextLine(
        required=True,
        min_length=2,
        max_length=10)

    s2 = TextLine(
        required=False,
        missing_value=u'')

    s3 = Choice(
        required=False,
        values=(u'Bob', u'is', u'Your', u'Uncle'))
Exemple #11
0
class IRoom(Interface):
    """A service object."""

    building = Choice(title=_(u'Building'),
                      vocabulary='AllBuildings',
                      required=False)

    #    devices = List(title=_(u"Devices"),
    #        value_type=Choice(vocabulary='AllUnusedOrUsedRoomDevices'),
    #        required=False,
    #        default=[])
    #
    #    physicalConnectors = List(title=_(u"Physical connectors"),
    #        value_type=Choice(vocabulary='AllUnusedOrUsedRoomPhysicalConnectors'),
    #        required=False,
    #        default=[])

    #    racks = List(title=_(u"Racks"),
    #        value_type=Choice(vocabulary='AllUnusedOrUsedRoomRacks'),
    #        required=False,
    #        default=[])
    #
    physicalComponents = List(
        title=_(u"Physical components"),
        value_type=Choice(vocabulary='AllUnusedOrUsedRoomPhysicalComponents'),
        required=False,
        default=[])

    level = TextLine(max_length=80,
                     title=_("Level"),
                     description=_("Level of the room."),
                     default=u"",
                     required=False)

    coordinates = TextLine(max_length=80,
                           title=_("coordinates"),
                           description=_("Coordinates of the room."),
                           default=u"",
                           required=False)
Exemple #12
0
 def createProductField(self):
     """Create a Choice field to select one of the project group's
     products."""
     return form.Fields(Choice(
         __name__='product',
         vocabulary='ProjectProducts',
         title=_('Project'),
         description=_(
             '${context} is a group of projects, which specific '
             'project do you have a question about?',
             mapping=dict(context=self.context.title)),
         required=True),
                        render_context=self.render_context)
Exemple #13
0
class ILaunchpadPrincipal(IPrincipal):
    """Marker interface for launchpad principals.

    This is used for the launchpad.AnyPerson permission.
    """

    access_level = Choice(
        title=_("The level of access this principal has."),
        vocabulary=AccessLevel, default=AccessLevel.WRITE_PRIVATE)

    account = Attribute("The IAccount the principal represents.")

    person = Attribute("The IPerson the principal represents.")
class ISignedCodeOfConduct(Interface):
    """The Signed Code of Conduct."""

    id = Int(title=_("Signed CoC ID"), required=True, readonly=True)

    owner = Choice(
        title=_('Owner'),
        required=True,
        vocabulary='ValidOwner',
        description=_(
            """The person who signed the code of conduct by mail or fax."""))

    signedcode = Text(title=_("Signed Code"))

    signingkey = Choice(title=_('Signing OpenPGP Key'),
                        description=_("""OpenPGP key ID used to sign the
                        document. It must be valid inside the Launchpad
                        context."""),
                        vocabulary='ValidGPGKey',
                        required=True)

    datecreated = Datetime(title=_("Date Created"),
                           description=_("Original Request Timestamp"))

    recipient = Int(title=_("Recipient"), description=_("Person Authorizing."))

    admincomment = Text(title=_("Admin Comment"),
                        description=_(
                            "Admin comment, to e.g. describe the reasons why "
                            "this registration was approved or rejected."))

    active = Bool(title=_("Active"),
                  description=_("Whether or not this Signed CoC "
                                "is considered active."))

    displayname = Attribute("Fancy Title for CoC.")

    def sendAdvertisementEmail(subject, content):
        """Send Advertisement email to signature owner preferred address
Exemple #15
0
 def test_ChoiceSequenceEditWidget(self):
     provideAdapter(ChoiceCollectionInputWidget,
                    (IList, IChoice, IBrowserRequest),
                    IInputWidget)
     provideAdapter(SelectWidget,
                    (IList, IIterableVocabulary, IBrowserRequest),
                    IInputWidget)
     field = List(value_type=Choice(values=[1, 2, 3]))
     bound = field.bind(object())
     widget = CollectionInputWidget(bound, TestRequest())
     self.assertTrue(isinstance(widget, SelectWidget))
     self.assertEqual(widget.context, bound)
     self.assertEqual(widget.vocabulary, bound.value_type.vocabulary)
Exemple #16
0
 def test_widget_extract(self):
     from plone.app.z3cform.widget import SelectWidget
     widget = SelectWidget(self.request)
     widget.field = Choice(
         __name__='selectfield',
         values=['one', 'two', 'three']
     )
     widget.name = 'selectfield'
     self.request.form['selectfield'] = 'one'
     self.assertEquals(widget.extract(), 'one')
     widget.multiple = True
     self.request.form['selectfield'] = 'one;two'
     self.assertEquals(widget.extract(), 'one;two')
Exemple #17
0
class IEventIfEventHost(IEventIfSupernode):
    """ event interface of object """

    eventInpObjs_shutdown = Set(title=_("shutdown event <-"),
                                value_type=Choice(
                                    title=_("objects"),
                                    vocabulary="AllEventInstances"),
                                default=set([]),
                                readonly=False,
                                required=True)

    def eventInp_shutdown(eventMsg):
        """ start the shutdown of the host """
Exemple #18
0
 def test_ListOfChoicesDisplayWidget(self):
     provideAdapter(ChoiceCollectionDisplayWidget,
                    (IList, IChoice, IBrowserRequest),
                    IDisplayWidget)
     provideAdapter(ItemsMultiDisplayWidget,
                    (IList, IIterableVocabulary, IBrowserRequest),
                    IDisplayWidget)
     field = List(value_type=Choice(values=[1, 2, 3]))
     bound = field.bind(object())
     widget = CollectionDisplayWidget(bound, TestRequest())
     self.assertTrue(isinstance(widget, ItemsMultiDisplayWidget))
     self.assertEqual(widget.context, bound)
     self.assertEqual(widget.vocabulary, bound.value_type.vocabulary)
class IProvidersSchema(Interface):

    bookmark_providers = Tuple(
        title=_(u"Bookmark providers"),
        description=_(
            u"help_selected_providers",
            default=u"Please check any provider you want to be "
            u"enabled to your visitors.",
        ),
        value_type=Choice(vocabulary=PROVIDERS),
    )

    enabled_portal_types = Tuple(
        title=_(u"Content types"),
        description=_(
            u"help_portal_types",
            default=u"Please select content types in which the "
            u"viewlet will be applied.",
        ),
        value_type=Choice(vocabulary=TYPES),
    )

    use_as_action = Bool(
        title=_(u"Use as a content action?"),
        description=_(
            u"help_use_as_content_action",
            default=u"Check this if you want the social bookmarks to"
            u" appear as an action for contents.",
        ),
    )

    show_icons_only = Bool(
        title=_(u"Show icons only?"),
        description=_(
            u"help_show_icons_only",
            default=u"Check this if you want the social bookmarks to"
            u" be rendered as icons only.",
        ),
    )
Exemple #20
0
class IDoWireProfileRegister(IDoWireProfile):
    joinable_groups = List(title=u'Joinable Groups',
                           description=u'Groups on this site you can join.',
                           required=False,
                           value_type=Choice(title=u'Group',
                                             vocabulary='JoinableGroups'),
                           unique=True,
                           default=[])

    came_from = URI(
        title=u'Came From',
        description=u'The page to return to after registration has finished',
        required=False)
class IIntTest(Interface):
    i1 = Int(
        required=True,
        min=1,
        max=10)

    i2 = Int(
        required=False)

    i3 = Choice(
        required=False,
        values=(0, 1, 2, 3, 5, 7, 11),
        missing_value=0)
Exemple #22
0
    def update_dynamic_fields(self):
        categories = (self.fields['cat1'], self.fields['cat2'])

        for category in categories:
            category.field.description = u''
            category.field.value_type = Choice(
                source=self.available_categories(self.context,
                                                 category.__name__))

        categories[0].widgetFactory = CheckBoxFieldWidget
        categories[0].field.required = True
        categories[1].widgetFactory = RadioFieldWidget
        categories[1].field.required = True
Exemple #23
0
class IInterfaceSnmpScanWizard(Interface):
    """A interface object."""
    searchIpV4 = HostIpValid(
            min_length=1,
            max_length=30,
            title=_("IP address"),
            default=u"127.0.0.1",
            required=True)
    indexType = Choice(
        title = _("Index type"),
        vocabulary="SnmpIndexTypes",
        default = u"mac",
        required = True)
Exemple #24
0
    def __init__(self, validate_categories=True, allow_uncommon=None, **kw):
        self.validate_categories = validate_categories
        self.allow_uncommon = allow_uncommon

        # Avoid validation for the 'default' property, if set
        self._init_field = True
        super(Tags, self).__init__(**kw)
        self._init_field = False

        if self.value_type is None:
            self.value_type = Choice(
                title=_(u"Tag"),
                source=TagsSourceBinder(allow_uncommon=allow_uncommon))
Exemple #25
0
class IThemeTagging(Interface):
    """ Theme tagging """

    tags = List(
        title=u"Themes",
        description=u"List of themes that this content object should be "
        "associated with",
        required=False,
        max_length=3,
        value_type=Choice(
            title=u"Theme",
            vocabulary="Allowed themes",
        ))
Exemple #26
0
class IOrganization(Interface):
    """A Organization object."""

    name = TextLine(
        title = _(u'Organization name'),
        description = _(u"Organization name"),
        required = False)

    subOUs = List(
        title = _(u'Sub organisational units'),
        value_type=Choice(vocabulary='AllValidSubOrganisationalUnits'),
        default=[],
        required = False)
class IListUsersForm(Interface):
    """Field definition for List Users form."""

    groups = FrozenSet(
        title=_(u'Groups'),
        description=_(u'Select groups from which you want to display users ' \
            'from.'),
        constraint=must_select_one_constraint,
        value_type=Choice(
            vocabulary='plone.app.vocabularies.Groups',
        )
    )

    user_attributes = List(
        title=_(u'User attributes'),
        description=_(u'Select which user attributes you want displayed in ' \
            'the results table.'),
        constraint=must_select_one_constraint,
        value_type=Choice(
            vocabulary='collective.listusers.vocabularies.UserAttributes',
        )
    )
class IBuildFarmJobDB(Interface):
    """Operations on a `BuildFarmJob` DB row.

    This is deprecated while it's flattened into the concrete implementations.
    """

    id = Attribute('The build farm job ID.')

    job_type = Choice(title=_("Job type"),
                      required=True,
                      readonly=True,
                      vocabulary=BuildFarmJobType,
                      description=_("The specific type of job."))
class ICsv(Interface):
    """Schema for parsing a CSV file."""
    csv = Bytes(title='CSV File',
                description='The CSV file to be processed.',
                required=True)

    # TODO: Check for the required attributes
    columns = List(title='Columns',
                   description='The columns in the CSV.',
                   value_type=Choice(title='Profile attribute',
                                     vocabulary='ProfileAttributes'),
                   unique=True,
                   required=True)
class ICodeImportEvent(Interface):
    """One event in the code-import audit trail."""

    id = Int(readonly=True, required=True)
    date_created = Datetime(title=_("Date Created"),
                            required=True,
                            readonly=True)

    event_type = Choice(title=_("Event"),
                        required=True,
                        readonly=True,
                        vocabulary=CodeImportEventType,
                        description=_("The type of this event."
                                      ""))
    code_import = Choice(title=_("Code Import"),
                         required=False,
                         readonly=True,
                         vocabulary='CodeImport',
                         description=_(
                             "The code import affected by this event."
                             ""))
    person = PublicPersonChoice(title=_("Person"),
                                required=False,
                                readonly=True,
                                vocabulary='Person',
                                description=_(
                                    "The person that triggered this event."
                                    ""))
    machine = Choice(title=_("Machine"),
                     required=False,
                     readonly=True,
                     vocabulary='CodeImportMachine',
                     description=_(
                         "The import machine where this event occured."
                         ""))

    def items():
        """List of key-value tuples recording additional information.
Exemple #31
0
class IAdminTranslator(Interface):
    """Set of attributes that can only be edited by the owner of the
    translation group this translator is part of.

    These attributes let you add translators to translation groups and set
    the languages that the translators are responsible for. These are all
    administrative tasks.
    """

    id = Int(
        title=_('Translator ID'),
        required=True,
        readonly=True,
    )
    datecreated = Datetime(
        title=_('Date Appointed'),
        required=True,
        readonly=True,
    )
    translationgroup = Choice(
        title=_('Translation Group'),
        required=True,
        vocabulary='TranslationGroup',
        description=_(
            "The translation group "
            "in which the translation team (individual supervisor) is being "
            "appointed."))
    language = Choice(title=_('Language'),
                      required=True,
                      vocabulary='Language',
                      description=_("The language that this "
                                    "team or person will be responsible for."))
    translator = PublicPersonChoice(
        title=_('Translator'),
        required=True,
        vocabulary='ValidPersonOrTeam',
        description=_("The translation team (or individual supervisor) to "
                      "be responsible for the language in this group."))
Exemple #32
0
class ISaveData(IAction):
    """A form action adapter that will save form input data and
       return it in csv- or tab-delimited format."""
    showFields = List(
        title=_(u'label_savefields_text', default=u'Saved Fields'),
        description=_(
            u'help_savefields_text',
            default=u''
            u'Pick the fields whose inputs you\'d like to include in '
            u'the saved data. If empty, all fields will be saved.'),
        unique=True,
        required=False,
        value_type=Choice(vocabulary=fieldsFactory),
    )
    form.widget(ExtraData=CheckBoxFieldWidget)
    ExtraData = List(
        title=_(u'label_savedataextra_text', default='Extra Data'),
        description=_(
            u'help_savedataextra_text',
            default=
            u'Pick any extra data you\'d like saved with the form input.'),
        unique=True,
        value_type=Choice(vocabulary=vocabExtraDataDL),
    )
    DownloadFormat = Choice(
        title=_(u'label_downloadformat_text', default=u'Download Format'),
        default=u'csv',
        vocabulary=vocabFormatDL,
    )
    UseColumnNames = Bool(
        title=_(u'label_usecolumnnames_text', default=u'Include Column Names'),
        description=_(
            u'help_usecolumnnames_text',
            default=
            u'Do you wish to have column names on the first line of downloaded input?'
        ),
        required=False,
    )
class IMultiLanguageSelectionSchema(Interface):
    """ Interface for language selection - control panel fieldset
    """

    default_language = Choice(
        title=_(u"heading_site_language", default=u"Default site language"),
        description=_(u"description_site_language",
                      default=u"The default language used for the content "
                      u"and the UI of this site."),
        required=True,
        vocabulary=("plone.app.multilingual.vocabularies."
                    "AllContentLanguageVocabulary"))

    available_languages = List(
        title=_(u"heading_available_languages",
                default=u"Available languages"),
        description=_(u"description_available_languages",
                      default=u"The languages in which the site should be "
                      u"translatable."),
        required=True,
        missing_value=set(),
        value_type=Choice(vocabulary=("plone.app.multilingual.vocabularies."
                                      "AllContentLanguageVocabulary")))
Exemple #34
0
class ILDAPServerConfiguration(Interface):
    """Configuration of an LDAP server.
    """
    enabled = Bool(
            title=_(u"label_ldap_enabled",
                default=u"Active"),
            description=_(u"help_ldap_enabled",
                default=u"Use this LDAP server"),
            default=False,
            required=True)

    server = ASCIILine(
            title=_(u"label_ldap_server",
                default=u"Server"),
            description=_(u"help_ldap_server",
                default="The address or hostname of the LDAP server."),
            default="localhost",
            required=True)

    connection_type = Choice(
            title=_(u"label_ldap_connection_type",
                default=u"Connection type"),
            description=_(u"help_ldap_connection_type",
                default=u""),
            vocabulary="plone.app.ldap.engine.LDAPConnectionTypes",
            default=0,
            required=True)

    connection_timeout = Int(
            title=_(u"label_connection_timeout",
                default=u"Connection timeout"),
            description=_(u"help_connection_timeout",
                default=u"The timeout in seconds to wait for a connection to "
                "the LDAP server to be established."),
            default=5,
            min=-1,
            max=300,
            required=True)

    operation_timeout = Int(
            title=_(u"label_operation_timeout",
                default=u"Operation timeout"),
            description=_(u"help_operation_timeout",
                default=u"The timeout in seconds to wait for an operation such "
                "as a search or update to complete. If no timeout should be "
                "used use -1 as value."),
            default=-1,
            min=-1,
            max=300,
            required=True)
Exemple #35
0
class IPatchPanel(Interface):
    """A PatchPanel object."""

    portCount = Int(
        title = _(u'Port quantity'),
        description = _(u'Quantity of all patch ports'),
        required = False)
        

    rack = Choice(
        title = _(u'Rack'),
        vocabulary = 'AllRacks',
        required = False)
        

    patchports = List(
        title = _(u'Patch ports'),
        value_type=Choice(vocabulary='AllUnusedOrUsedPatchPanelPatchPorts'),
        default=[],
        required = False)
        
    def trigger_online():
        """
Exemple #36
0
class IBirthInfo(Interface):
    state1 = Choice(
        title=u('State of Birth'),
        description=u('The state in which you were born.'),
        vocabulary="states",
        default="AL",
        )
    state2 = Choice(
        title=u('State of Birth'),
        description=u('The state in which you were born.'),
        vocabulary="states",
        default="AL",
        )
    state3 = Choice(
        title=u('Favorite State'),
        description=u('The state you like the most.'),
        vocabulary=states.StateVocabulary(),
        )
    state4 = Choice(
        title=u("Name"),
        description=u("The name of your new state"),
        vocabulary="states",
        )
Exemple #37
0
class IHasSharingPolicies(Interface):
    """Sharing policies used to define bug and branch visibility rules."""
    branch_sharing_policy = exported(Choice(
        title=_('Branch sharing policy'),
        description=_("Sharing policy for this pillar's branches."),
        required=False,
        readonly=True,
        vocabulary=BranchSharingPolicy),
                                     as_of='devel')
    bug_sharing_policy = exported(Choice(
        title=_('Bug sharing policy'),
        description=_("Sharing policy for this pillar's bugs."),
        required=False,
        readonly=True,
        vocabulary=BugSharingPolicy),
                                  as_of='devel')
    specification_sharing_policy = exported(Choice(
        title=_('Blueprint sharing policy'),
        description=_("Sharing policy for this project's specifications."),
        required=False,
        readonly=True,
        vocabulary=SpecificationSharingPolicy),
                                            as_of='devel')
Exemple #38
0
class II18nManager(Interface):
    """Context languages manager

    This interface is used to handle contents providing several languages
    """

    languages = List(
        title=_("Proposed languages"),
        description=_("List of languages available for this content"),
        required=False,
        value_type=Choice(vocabulary=BASE_LANGUAGES_VOCABULARY_NAME))

    def get_languages(self):
        """Get full languages list"""
Exemple #39
0
class IBarraConfSchema(Interface):
    """ Schema de configuracao da Barra de Identidade """

    cor = Choice(
        title=_(u'Cor de fundo'),
        description=_(
            u'help_cor_barra',
            default=u"Escolha uma das opções para "
            "cor de fundo da barra.",
        ),
        required=True,
        default=_(u'verde'),
        vocabulary=cores,
    )
 def makeField(self, context, vocabulary):
     field = Choice(
         title=_('Branch'), vocabulary=vocabulary, required=False,
         description=_("The Bazaar branch."))
     field.context = context
     return field
Exemple #41
0
 def __init__(self, values=None, vocabulary=None,
              source=None, **kw):
     Choice.__init__(self, values, vocabulary, source, **kw)
Exemple #42
0
 def test_validate_int(self):
     choice = Choice(values=[1, 3])
     choice.validate(1)
     choice.validate(3)
     self.assertRaises(ConstraintNotSatisfied, choice.validate, 4)
Exemple #43
0
 def test_validate_string(self):
     choice = Choice(values=['a', 'c'])
     choice.validate('a')
     choice.validate('c')
     choice.validate(u'c')
     self.assertRaises(ConstraintNotSatisfied, choice.validate, 'd')
Exemple #44
0
 def test_validate_tuple(self):
     choice = Choice(values=[(1, 2), (5, 6)])
     choice.validate((1, 2))
     choice.validate((5, 6))
     self.assertRaises(ConstraintNotSatisfied, choice.validate, [5, 6])
     self.assertRaises(ConstraintNotSatisfied, choice.validate, ())