Пример #1
0
class ILocaleDates(Interface):
    """This object contains various data about dates, times and time zones."""

    localizedPatternChars = TextLine(
        title=_u("Localized Pattern Characters"),
        description=_u("Localized pattern characters used in dates and times"))

    calendars = Dict(
        title=_u("Calendar type to ILocaleCalendar"),
        key_type=Choice(title=_u("Calendar Type"),
                        values=(_u("gregorian"), _u("arabic"), _u("chinese"),
                                _u("civil-arabic"), _u("hebrew"),
                                _u("japanese"), _u("thai-buddhist"))),
        value_type=Field(title=_u("Calendar"),
                         description=_u("This is a ILocaleCalendar object.")))

    timezones = Dict(title=_u("Time zone type to ILocaleTimezone"),
                     key_type=TextLine(title=_u("Time Zone type")),
                     value_type=Field(
                         title=_u("Time Zone"),
                         description=_u("This is a ILocaleTimeZone object.")))

    def getFormatter(category,
                     length=None,
                     name=None,
                     calendar=_u("gregorian")):
        """Get a date/time formatter.
class IFormStatus(IContentProvider):
    errors = Field(title='Errors',
                   description='The errors, if any',
                   required=True)

    status = Text(title='Status',
                  description='The status of the form.',
                  required=True)

    widgets = Field(title='Widgets', description='The widgets', required=True)

    pageTemplateFileName = Text(
        title="Page Template File Name",
        description='The name of the ZPT file that is used to '
        'render the status message.',
        required=False,
        default="browser/templates/statusmessage.pt")

    showPageErrors = Bool(
        title="Show Page Errors",
        description='If True, the content provider will display page level '
        'errors. Otherwise, page errors will not be displayed.',
        required=False,
        default=False)

    showWidgetErrors = Bool(
        title="Show Widget Errors",
        description='If True, the content provider will display all of '
        'their errors associated with widgets on the page. '
        'Otherwise, errors associated with widgets will not '
        'be displayed.',
        required=False,
        default=True)
class IGSFeedContentProvider(Interface):
    """ A content provider for displaying parsed ATOM or RSS feeds.
    
    """
    startNew = Bool(title=u'Start a New Topic',
                    description=u'Set to "True" if a new topic is started',
                    required=False,
                    default=True)
    topic = Text(title=u"Topic",
                 description=u"The topic that the new post is added to",
                 required=False,
                 default=u'Enter your new topic here')
    groupInfo = Field(title=u"Group Information",
                      description=u"Information about the group",
                      required=True,
                      default=None)
    siteInfo = Field(title=u"Site Information",
                     description=u"Information about the site",
                     required=True,
                     default=None)
    replyToId = Text(title=u'Reply-To Post Identifier',
                     description=u'Used when adding to a topic',
                     required=False,
                     default=u'')
    pageTemplateFileName = Text(title=u"Page Template File Name",
                                description=u"""The name of the ZPT file
                                that is used to render the post.""",
                                required=False,
                                default=u"browser/templates/postMessage.pt")
Пример #4
0
class IGSGroupPage(Interface):
    siteInfo = Field(title='Site Information',
                     description='A SiteInfo instance.',
                     required=True)

    groupInfo = Field(title='Group Information',
                      description='GroupInfo instance.',
                      required=True)
Пример #5
0
class ICanPostInfo(IViewletManager):
    u'''The viewlet manager for the Can Post information'''

    passedInUserInfo = Field(
        title=u'Passed-In User Information',
        description=u'User information for the person to be checked.',
        required=False)
Пример #6
0
class IErrorViewSnippet(Interface):
    """A view providing a view for an error"""

    widget = Field(title=_("Widget"),
                   description=_("The widget that the view is on"),
                   required=True)

    error = Field(title=_('Error'),
                  description=_('Error the view is for'),
                  required=True)

    def update(self):
        """Update view"""

    def render(self):
        """Render view"""
Пример #7
0
    def extendFields(self):
        """See `LaunchpadFormView`.

        Adds a related branches field to the form.
        """
        self.form_fields += form.Fields(Field(__name__='related_branches'))
        self.widget_errors['related_branches'] = ''
Пример #8
0
class IGSModeratorInfo(Interface):
    """Information about the users who are moderators in the group"""

    context = Field(title='Context',
                    description='Context for the moderator information')

    moderators = Tuple(
        title='Moderators',
        description='The members who are moderators in the group',
        readonly=True)

    def moderator(user):
        """Is the user a moderator?
        ARGUMENTS
          "user": A user.

        RETURNS
          "True" if the user is a moderator in the group; "False"
          otherwise.

        SIDE EFFECTS
          None
        """

    def status(user):
        """The moderator status for the user in the group.
Пример #9
0
    def test_default_widget_instantiated(self):
        from plone.autoform.widgets import ParameterizedWidget
        from z3c.form.interfaces import IFieldWidget
        from zope.component import provideAdapter
        from zope.interface import Interface
        from zope.interface import implementer
        from zope.schema import Field

        class DummyWidget(object):

            def __init__(self, request):
                self.request = request

        @implementer(IFieldWidget)
        def DummyFieldWidget(field, request):
            return DummyWidget(request)

        provideAdapter(DummyFieldWidget, (Interface, Interface), IFieldWidget)

        field = Field()
        request = object()
        widget = ParameterizedWidget(foo='bar')(field, request)

        self.assertTrue(isinstance(widget, DummyWidget))
        self.assertEqual('bar', widget.foo)
Пример #10
0
class IGSPostingInfo(Interface):
    """Information about posting to a group."""

    context = Field(title='Context',
                    description='Context for the posting information')

    whoCanPost = Text(
        title='Who Can Post to the Group',
        description='A description of who can post messages to the group',
        readonly=True)

    def can_post(user):
        """Can the user post messages to the group?

        ARGUMENTS
          "user": A user.

        RETURNS
          "True" if the user can post messages and files to the
          group; "False" otherwise.

        SIDE EFFECTS
          None
        """

    def status(user):
        """The posting-status of the user.
Пример #11
0
class IGSJoiningInfo(Interface):
    """Joining information for a group."""

    context = Field(title='Context',
                    description='Group-context for the joining information')

    joinability = Text(title='Joinability',
                       description='The joining-status for the group.',
                       readonly=True)

    def can_join(user):
        """Can the user can join the group?

          ARGUMENTS
            "user" A user.

          RETURNS
            "True" if the user is not a group member and can join the group;
            "False" otherwise.

          SIDE EFFECTS
            None.
          """

    def status(user):
        """Can the user can leave the group?
Пример #12
0
class ILocaleIdentity(Interface):
    """Identity information class for ILocale objects.

    Three pieces of information are required to identify a locale:

      o language -- Language in which all of the locale text information are
        returned.

      o script -- Script in which all of the locale text information are
        returned.

      o territory -- Territory for which the locale's information are
        appropriate. None means all territories in which language is spoken.

      o variant -- Sometimes there are regional or historical differences even
        in a certain country. For these cases we use the variant field. A good
        example is the time before the Euro in Germany for example. Therefore
        a valid variant would be 'PREEURO'.

    Note that all of these attributes are read-only once they are set (usually
    done in the constructor)!

    This object is also used to uniquely identify a locale.
    """

    language = TextLine(
        title=u"Language Type",
        description=u"The language for which a locale is applicable.",
        constraint=re.compile(r'[a-z]{2}').match,
        required=True,
        readonly=True)

    script = TextLine(
        title=u"Script Type",
        description=u"""The script for which the language/locale is
                       applicable.""",
        constraint=re.compile(r'[a-z]*').match)

    territory = TextLine(
        title=u"Territory Type",
        description=u"The territory for which a locale is applicable.",
        constraint=re.compile(r'[A-Z]{2}').match,
        required=True,
        readonly=True)

    variant = TextLine(
        title=u"Variant Type",
        description=u"The variant for which a locale is applicable.",
        constraint=re.compile(r'[a-zA-Z]*').match,
        required=True,
        readonly=True)

    version = Field(
        title=u"Locale Version",
        description=u"The value of this field is an ILocaleVersion object.",
        readonly=True)

    def __repr__(self):
        """Defines the representation of the id, which should be a compact
Пример #13
0
    def test_non_convertable_sequence(self):
        from zope.schema.interfaces import WrongContainedType

        class Field(object):
            value_type = None

            def bind(self, obj):
                return self

            def validate(self, obj):
                raise WrongContainedType([])

        with self.assertRaises(WrongContainedType):
            INT.validate_field_value(self, 'name', Field(), [1])

        with self.assertRaises(INT.fields.CannotConvertSequenceError):
            INT.fields._adapt_sequence(Field(), [])
Пример #14
0
class IFormAware(Interface):
    """Offers a form attribute.

    For advanced uses the widget will make decisions based on the form
    it is rendered in.
    """

    form = Field()
Пример #15
0
class IField(Interface):
    """Field wrapping a schema field used in the form."""

    __name__ = TextLine(title=_('Title'),
                        description=_('The name of the field within the form'),
                        required=True)

    field = Field(title=_('Schema Field'),
                  description=_('The schema field that is to be rendered'),
                  required=True)

    prefix = Field(
        title=_('Prefix'),
        description=_('The prefix of the field used to avoid name clashes'),
        required=True)

    mode = Field(
        title=_('Mode'),
        description=_('The mode in which to render the widget for the field'),
        required=True)

    interface = Field(
        title=_('Interface'),
        description=_('The interface from which the field is coming'),
        required=True)

    ignore_context = Bool(
        title=_('Ignore Context'),
        description=_('A flag, when set, forces the widget not to look at '
                      'the context for a value'),
        required=False)

    widget_factory = Field(title=_('Widget Factory'),
                           description=_('The widget factory'),
                           required=False,
                           default=None,
                           missing_value=None)

    show_default = Bool(title=_('Show default value'),
                        description=_(
                            'A flag, when set, makes the widget to display '
                            'field|adapter provided default values'),
                        default=True,
                        required=False)
class IGSSiteInfoContentProvider(Interface):
    siteInfo = Field(title="Site information",
                     description="The site-information instance to display",
                     required=True,
                     readonly=False)

    groupInfos = Field(
        title="Groups information",
        description="The list of groupInfo instances for the groups "
        "in the site",
        required=True,
        readonly=False)

    pageTemplateFileName = ASCIILine(
        title="Page Template File Name",
        description='The name of the ZPT file that is used to render '
        'the post.',
        required=False,
        default=b"browser/templates/siteinfo-html.pt")
Пример #17
0
    def __init__(self, value_type, vocabulary, **kw):
        
        # complain if value_type is not a field
        if value_type is not None and not IField.providedBy(value_type):#IGNORE:E1101
            raise ValueError("'value_type' must be field instance.")
        self.value_type = value_type
        self.vocabulary = None
        self.vocabularyName = None

        if isinstance(vocabulary, (unicode, str)):
            self.vocabularyName = vocabulary
        else: 
            assert (ISource.providedBy(vocabulary) or             #IGNORE:E1101
                    IContextSourceBinder.providedBy(vocabulary))  #IGNORE:E1101
            self.vocabulary = vocabulary
        self._init_field = bool(self.vocabularyName)
        Field.__init__(self, **kw)      # initializing List or Choice would mess up 
                                        # the vocabulary 
        self._init_field = False
Пример #18
0
    def testCorrectValueType(self):
        # allow value_type of None (??? is this OK?)
        Tuple(value_type=None)

        # do not allow arbitrary value types
        self.assertRaises(ValueError, Tuple, value_type=object())
        self.assertRaises(ValueError, Tuple, value_type=Field)

        # however, allow anything that implements IField
        Tuple(value_type=Field())
        class FakeField(object):
            implements(IField)
        Tuple(value_type=FakeField())
Пример #19
0
class IGSModerationInfo(Interface):
    """The moderation information for the group as a whole, rather than
    information about any particular user."""

    context = Field(title='Context',
                    description='Context for the site moderation information')

    moderationOn = Bool(title='Moderation On',
                        description='True if moderation on for the group',
                        readonly=True)

    moderationStatus = Text(title='Moderation Status',
                            description='The moderation status for the group',
                            readonly=True)
Пример #20
0
class IGSSiteAdministrationInfo(Interface):
    """Site administration information"""

    context = Field(
        title='Context',
        description='Context for the site administration information')

    siteAdministrators = Tuple(
        title='Site Administrators',
        description='All the administrators for the site.',
        readonly=True)

    def site_administrator(user):
        """Whether the user a site administrator.
Пример #21
0
class ILocaleDates(Interface):
    """This object contains various data about dates, times and time zones."""

    localizedPatternChars = TextLine(
        title=u"Localized Pattern Characters",
        description=u"Localized pattern characters used in dates and times")

    calendars = Dict(
        title=u"Calendar type to ILocaleCalendar",
        key_type=Choice(title=u"Calendar Type",
                        values=(u'gregorian', u'arabic', u'chinese',
                                u'civil-arabic', u'hebrew', u'japanese',
                                u'thai-buddhist')),
        value_type=Field(title=u"Calendar",
                         description=u"This is a ILocaleCalendar object."))

    timezones = Dict(title=u"Time zone type to ILocaleTimezone",
                     key_type=TextLine(title=u"Time Zone type"),
                     value_type=Field(
                         title=u"Time Zone",
                         description=u"This is a ILocaleTimeZone object."))

    def getFormatter(category, length=None, name=None, calendar=u'gregorian'):
        """Get a date/time formatter.
Пример #22
0
    def test_wrong_contained_type_no_args(self):
        # In this case we don't know what to do
        from zope.schema.interfaces import WrongContainedType

        class Field(object):
            __name__ = 'thing'

            def validate(self, value):
                raise WrongContainedType

            def bind(self, _):
                return self

        with self.assertRaises(WrongContainedType):
            self._callFUT(Field(), [object()])
Пример #23
0
    def testCorrectValueType(self):
        # TODO: We should not allow for a None valeu type.
        List(value_type=None)

        # do not allow arbitrary value types
        self.assertRaises(ValueError, List, value_type=object())
        self.assertRaises(ValueError, List, value_type=Field)

        # however, allow anything that implements IField
        List(value_type=Field())

        class FakeField(object):
            implements(IField)

        List(value_type=FakeField())
Пример #24
0
class ITerms(IVocabularyTerms):
    """A selection term"""

    context = Field()
    request = Field()
    form = Field()
    field = Field()
    widget = Field()

    def getTermByToken(self, token):  # pylint: disable=invalid-name
        """Return an ITokenizedTerm for the passed-in token.

        If `token` is not represented in the vocabulary, `LookupError`
        is raised.
        """

    def __iter__(self):
        """Iterate over terms."""

    def __len__(self, ):
        """Return number of terms."""

    def __contains__(self, value):
        """Check wether terms containes the ``value``."""
Пример #25
0
class IButton(IField):
    """A button in a form."""

    access_key = TextLine(
        title=_('Access Key'),
        description=_('The key when pressed causes the button to be pressed'),
        min_length=1,
        max_length=1,
        required=False)

    action_factory = Field(title=_('Action Factory'),
                           description=_('The action factory'),
                           required=False,
                           default=None,
                           missing_value=None)
Пример #26
0
    def testCorrectValueType(self):
        # TODO: We should not allow for a None value type.
        FrozenSet(value_type=None)

        # do not allow arbitrary value types
        self.assertRaises(ValueError, FrozenSet, value_type=object())
        self.assertRaises(ValueError, FrozenSet, value_type=Field)

        # however, allow anything that implements IField
        FrozenSet(value_type=Field())

        @implementer(IField)
        class FakeField(object):
            pass

        FrozenSet(value_type=FakeField())
Пример #27
0
class IData(Interface):
    """A proxy object for form data.

    The object will make all keys within its data attribute available as
    attributes. The schema that is represented by the data will be directly
    provided by instances.
    """
    def __init__(self, schema, data, context):  # pylint: disable=super-init-not-called
        """The data proxy is instantiated using the schema it represents, the
        data fulfilling the schema and the context in which the data are
        validated.
        """

    __context__ = Field(
        title=_('Context'),
        description=_('The context in which the data are validated'),
        required=True)
Пример #28
0
class ReportGroup(group.Group):
    label = _(u"Report")
    fields = field.Fields(
        field.Field(Field(
            __name__="table",
            title=_(u"Problems"),
            description=_(
                u"This table lists the top URLs with a "
                u"bad status. To retry a URL immediately, select "
                u"\"Enqueue\". Each entry expands to display the "
                u"pages that the link appeared on and the location in "
                u"the HTML markup."),
            required=False),
                    mode="display",
                    ignoreContext=True), )

    fields["table"].widgetFactory = ReportWidget.factory
Пример #29
0
class ILocaleFormatLength(Interface):
    """The format length describes a class of formats."""

    type = Choice(title=u"Format Length Type",
                  description=u"Name of the format length",
                  values=(u'full', u'long', u'medium', u'short'))

    default = TextLine(title=u"Default Format",
                       description=u"The name of the defaulkt format.")

    formats = Dict(title=u"Formats",
                   description=u"Maps format types to format objects",
                   key_type=TextLine(title=u"Format Type"),
                   value_type=Field(
                       title=u"Format Object",
                       description=u"Values are ILocaleFormat objects."),
                   required=True,
                   readonly=True)
Пример #30
0
class IContextAware(Interface):
    """Offers a context attribute.

    For advanced uses, the widget will make decisions based on the context
    it is rendered in.
    """

    context = Field(
        title=_('Context'),
        description=_('The context in which the widget is displayed.'),
        required=True)

    ignore_context = Bool(
        title=_('Ignore Context'),
        description=_('A flag, when set, forces the widget not to look at '
                      'the context for a value.'),
        default=False,
        required=False)
Пример #31
0
class ILocaleFormatLength(Interface):
    """The format length describes a class of formats."""

    type = Choice(title=_u("Format Length Type"),
                  description=_u("Name of the format length"),
                  values=(_u("full"), _u("long"), _u("medium"), _u("short")))

    default = TextLine(title=_u("Default Format"),
                       description=_u("The name of the defaulkt format."))

    formats = Dict(title=_u("Formats"),
                   description=_u("Maps format types to format objects"),
                   key_type=TextLine(title=_u("Format Type")),
                   value_type=Field(
                       title=_u("Format Object"),
                       description=_u("Values are ILocaleFormat objects.")),
                   required=True,
                   readonly=True)
 def set(self, object, value):
     # Override Object field logic
     Field.set(self, object, value)
Пример #33
0
 def __init__(self, *args, **kwds):
     self.years_vocabulary = kwds['years_vocabulary']
     del kwds['years_vocabulary']
     Field.__init__(self, *args, **kwds)