Ejemplo n.º 1
0
 def __call__(self, v):
     try:
         validate.is_one_of(v, self.set_of_values, messages=self.messages)
     except Invalid, e:
         raise Invalid(e.message, validator=self)
Ejemplo n.º 2
0
        aliases = find_site(context).list_aliases
        aliases[context.short_address] = resource_path(context.__parent__)


report_schema = [
    ('title', schemaish.String(
                    validator=validator.All(
                        validator.Length(max=100),
                        validator.Required(),
                     ))),
    ('link_title', schemaish.String()),
    ('css_class', schemaish.String()),
    ('columns', schemaish.Sequence(
                    schemaish.String(
                       validator = lambda v:
                           validate.is_one_of(v, COLUMNS.keys())))),
]


class AddReportFormController(AddBase):
    page_title = 'Add Report'
    schema = report_schema
    factory = PeopleReport

    def form_widgets(self, schema):
        widgets = {
            'columns':formish.TextArea(rows=5,
                            converter_options={'delimiter':'\n'}),
                  }
        return widgets
Ejemplo n.º 3
0
        aliases = find_site(context).list_aliases
        aliases[context.short_address] = resource_path(context.__parent__)


report_schema = [
    ('title', schemaish.String(
                    validator=validator.All(
                        validator.Length(max=100),
                        validator.Required(),
                     ))),
    ('link_title', schemaish.String()),
    ('css_class', schemaish.String()),
    ('columns', schemaish.Sequence(
                    schemaish.String(
                       validator = lambda v:
                           validate.is_one_of(v, getColumns().keys())))),
]


class AddReportFormController(AddBase):
    page_title = 'Add Report'
    schema = report_schema
    factory = PeopleReport

    def form_widgets(self, schema):
        widgets = {
            'columns':formish.TextArea(rows=5,
                            converter_options={'delimiter':'\n'}),
                  }
        return widgets
Ejemplo n.º 4
0
class TestOneOf(unittest.TestCase):

    type = 'OneOf'
    fn = staticmethod(
        lambda v: staticmethod(validate.is_one_of(v, [3, 5, 7, 9])))
    class_fn = validator.OneOf([3, 5, 7, 9])

    fn_chars = staticmethod(
        lambda v: staticmethod(validate.is_one_of(v, 'ynsbl')))
    class_fn_chars = validator.OneOf('ynsbl')

    fn_list_tuples = staticmethod(lambda v: staticmethod(
        validate.is_one_of(v, [(1, 2), (3, 4), (5, 6)])))
    class_fn_list_tuples = validator.OneOf([(1, 2), (3, 4), (5, 6)])

    def test_validate_pass(self):
        self.section = 'pass'
        values = [
            3,
            5,
            7,
            9,
            None,
        ]
        check_pass('function', self, self.fn, values)
        check_pass('class', self, self.class_fn, values)

    def test_validate_fail(self):
        self.section = 'fail'
        values = [
            'foo',
            ['a', 'b', 'c'],
            '1',
            2,
            4,
            6,
            8,
            10,
            '',
            [],
        ]
        check_fail('function', self, self.fn, values)
        check_fail('class', self, self.class_fn, values)

    def test_validate_chars_pass(self):
        self.section = 'pass'
        values = [
            'y',
            'b',
            'l',
            'n',
        ]
        check_pass('function', self, self.fn_chars, values)
        check_pass('class', self, self.class_fn_chars, values)

    def test_validate_chars_fail(self):
        self.section = 'fail'
        values = [
            'foo',
            ['a', 'b', 'c'],
            '1',
            2,
            4,
            6,
            8,
            10,
            '',
            [],
            'x',
            'yy',
            'yn',
        ]
        check_fail('function', self, self.fn_chars, values)
        check_fail('class', self, self.class_fn_chars, values)

    def test_validate_lists_pass(self):
        self.section = 'pass'
        values = [
            (1, 2),
            (3, 4),
            (5, 6),
            None,
        ]
        check_pass('function', self, self.fn_list_tuples, values)
        check_pass('class', self, self.class_fn_list_tuples, values)

    def test_validate_lists_fail(self):
        self.section = 'fail'
        values = [
            'foo',
            ['a', 'b', 'c'],
            '1',
            2,
            4,
            6,
            8,
            10,
            '',
            [],
            'x',
            'yy',
            'yn',
        ]
        check_fail('function', self, self.fn_list_tuples, values)
        check_fail('class', self, self.class_fn_list_tuples, values)

    def test_validate_emptyset(self):
        self.section = 'fail'
        class_fn = validator.OneOf([])
        values = [
            (1, 2),
            (3, 4),
            (5, 6),
        ]
        check_fail('class', self, class_fn, values)
Ejemplo n.º 5
0
        aliases = find_site(context).list_aliases
        aliases[context.short_address] = resource_path(context.__parent__)


report_schema = [
    ('title',
     schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
     ))),
    ('link_title', schemaish.String()),
    ('css_class', schemaish.String()),
    ('columns',
     schemaish.Sequence(
         schemaish.String(
             validator=lambda v: validate.is_one_of(v,
                                                    getColumns().keys())))),
]


class AddReportFormController(AddBase):
    page_title = 'Add Report'
    schema = report_schema
    factory = PeopleReport

    def form_widgets(self, schema):
        widgets = {
            'columns':
            formish.TextArea(rows=5, converter_options={'delimiter': '\n'}),
        }
        return widgets
Ejemplo n.º 6
0
 def _bool(self, val):
     try:
         validate.is_one_of(val, [True, False])
     except:
         return False
     return True
Ejemplo n.º 7
0
        aliases = find_site(context).list_aliases
        aliases[context.short_address] = resource_path(context.__parent__)


report_schema = [
    ('title',
     schemaish.String(validator=validator.All(
         validator.Length(max=100),
         validator.Required(),
     ))),
    ('link_title', schemaish.String()),
    ('css_class', schemaish.String()),
    ('columns',
     schemaish.Sequence(
         schemaish.String(
             validator=lambda v: validate.is_one_of(v, COLUMNS.keys())))),
]


class AddReportFormController(AddBase):
    page_title = 'Add Report'
    schema = report_schema
    factory = PeopleReport

    def form_widgets(self, schema):
        widgets = {
            'columns':
            formish.TextArea(rows=5, converter_options={'delimiter': '\n'}),
        }
        return widgets
Ejemplo n.º 8
0
        try:
            del aliases[context.short_address]
        except KeyError:
            pass

    def after_edit(self):
        context = self.context
        aliases = find_site(context).list_aliases
        aliases[context.short_address] = resource_path(context.__parent__)


report_schema = [
    ("title", schemaish.String(validator=validator.All(validator.Length(max=100), validator.Required()))),
    ("link_title", schemaish.String()),
    ("css_class", schemaish.String()),
    ("columns", schemaish.Sequence(schemaish.String(validator=lambda v: validate.is_one_of(v, COLUMNS.keys())))),
]


class AddReportFormController(AddBase):
    page_title = "Add Report"
    schema = report_schema
    factory = PeopleReport

    def form_widgets(self, schema):
        widgets = {"columns": formish.TextArea(rows=5, converter_options={"delimiter": "\n"})}
        return widgets


class EditReportFormController(EditBase):
    page_title = "Edit Report"
Ejemplo n.º 9
0
 def __call__(self, v):
     try:
         validate.is_one_of(v, self.set_of_values, messages=self.messages)
     except Invalid, e:
         raise Invalid(e.message, validator=self)