How to use the deform.schema 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 Pylons / deform / deform / sampleapp / app.py View on Github external
LONG_DESC = """
The name of the thing.  This is a pretty long line, and hopefully I won't
need to type too much more of it because it's pretty boring to type this kind
of thing """

class MemoryTmpStore(dict):
    def preview_url(self, uid):
        return None

memory = MemoryTmpStore()

class DatesSchema(schema.SequenceSchema):
    date = schema.SchemaNode(schema.Date())

class SeriesSchema(schema.MappingSchema):
    name = schema.SchemaNode(schema.String())
    dates = DatesSchema()

class FileUploads(schema.SequenceSchema):
    file = schema.SchemaNode(schema.FileData())

class MySchema(schema.MappingSchema):
    name = schema.SchemaNode(schema.String(), description=LONG_DESC)
    title = schema.SchemaNode(schema.String(),
                              validator=colander.Length(max=10),
                              description=LONG_DESC)
    password = schema.SchemaNode(schema.String(),
                                 validator=colander.Length(min=5))
    cool = schema.SchemaNode(schema.Boolean(), default=True)
    series = SeriesSchema()
    color = schema.SchemaNode(schema.String(),
github Pylons / deform / deform / sampleapp / app.py View on Github external
of thing """

class MemoryTmpStore(dict):
    def preview_url(self, uid):
        return None

memory = MemoryTmpStore()

class DatesSchema(schema.SequenceSchema):
    date = schema.SchemaNode(schema.Date())

class SeriesSchema(schema.MappingSchema):
    name = schema.SchemaNode(schema.String())
    dates = DatesSchema()

class FileUploads(schema.SequenceSchema):
    file = schema.SchemaNode(schema.FileData())

class MySchema(schema.MappingSchema):
    name = schema.SchemaNode(schema.String(), description=LONG_DESC)
    title = schema.SchemaNode(schema.String(),
                              validator=colander.Length(max=10),
                              description=LONG_DESC)
    password = schema.SchemaNode(schema.String(),
                                 validator=colander.Length(min=5))
    cool = schema.SchemaNode(schema.Boolean(), default=True)
    series = SeriesSchema()
    color = schema.SchemaNode(schema.String(),
                              validator=colander.OneOf(('red', 'blue')))
    uploads = FileUploads()

def validate_form(form, value):
github Kotti / deform_bootstrap / deform_bootstrap / demo / __init__.py View on Github external
def inline_checkboxchoice(self):
        class Schema(colander.Schema):
            choice = colander.SchemaNode(
                deform.schema.Set(),
                widget=deform.widget.CheckboxChoiceWidget(
                    values=[('a', 'Awesome'),
                            ('b', 'Bogus'),
                            ('c', 'Crud')],
                    inline=True),
                description='Pick as many as apply')
        schema = Schema()
        form = deform.Form(schema, buttons=('submit',))
        return self.render_form(form)
github Pylons / deform / deform / sampleapp / app.py View on Github external
from deform import widget
from deform import form
from deform import exception

LONG_DESC = """
The name of the thing.  This is a pretty long line, and hopefully I won't
need to type too much more of it because it's pretty boring to type this kind
of thing """

class MemoryTmpStore(dict):
    def preview_url(self, uid):
        return None

memory = MemoryTmpStore()

class DatesSchema(schema.SequenceSchema):
    date = schema.SchemaNode(schema.Date())

class SeriesSchema(schema.MappingSchema):
    name = schema.SchemaNode(schema.String())
    dates = DatesSchema()

class FileUploads(schema.SequenceSchema):
    file = schema.SchemaNode(schema.FileData())

class MySchema(schema.MappingSchema):
    name = schema.SchemaNode(schema.String(), description=LONG_DESC)
    title = schema.SchemaNode(schema.String(),
                              validator=colander.Length(max=10),
                              description=LONG_DESC)
    password = schema.SchemaNode(schema.String(),
                                 validator=colander.Length(min=5))
github Pylons / substanced / substanced / image / __init__.py View on Github external
class ImageUploadTempStore(FileUploadTempStore):
    def preview_url(self, uid):
        root = self.request.root
        return self.request.mgmt_path(root, '@@preview_image_upload', uid)

@colander.deferred
def image_upload_widget(node, kw):
    request = kw['request']
    tmpstore = ImageUploadTempStore(request)
    widget = deform.widget.FileUploadWidget(tmpstore)
    widget.template = 'image_upload'
    return widget

imagenode = colander.SchemaNode(
    deform.schema.FileData(),
    widget = image_upload_widget,
    )

class ImageUploadSchema(Schema):
    file = imagenode.clone()

class ImageUploadPropertySheet(FileUploadPropertySheet):
    schema = ImageUploadSchema()
    
@content(
    IImage,
    name='Image',
    icon='icon-camera',
    add_view='add_image',
    # prevent view tab from sorting first (it would display the image when
    # manage_main clicked)
github Pylons / deform / deform / field.py View on Github external
""" If a widget is not assigned directly to a field, this
        function will be called to generate a default widget (only
        once). The result of this function will then be assigned as
        the ``widget`` attribute of the field for the rest of the
        lifetime of this field. If a widget is assigned to a field
        before form processing, this function will not be called."""
        wdg = getattr(self.schema, "widget", None)
        if wdg is not None:
            return wdg
        widget_maker = getattr(self.schema.typ, "widget_maker", None)
        if widget_maker is None:
            widget_maker = schema.default_widget_makers.get(
                self.schema.typ.__class__
            )
            if widget_maker is None:
                for (cls, wgt) in schema.default_widget_makers.items():
                    if isinstance(self.schema.typ, cls):
                        widget_maker = wgt
                        break
        if widget_maker is None:
            widget_maker = widget.TextInputWidget
        return widget_maker(item_css_class=self.default_item_css_class())
github Pylons / substanced / substanced / file / views.py View on Github external
)
def view_file(context, request):
    return context.get_response(request=request)

@mgmt_view(
    context=IFile,
    name='view',
    tab_title='View',
    permission='sdi.view'
    )
def view_tab(context, request):
    return HTTPFound(location=request.sdiapi.mgmt_path(context))

class AddFileSchema(FilePropertiesSchema):
    file = colander.SchemaNode(
        deform.schema.FileData(),
        widget = file_upload_widget,
        missing = colander.null,
        )

@colander.deferred
def name_or_file(node, kw):
    def _name_or_file(node, struct):
        if not struct['file'] and not struct['name']:
            raise colander.Invalid(node, 'One of name or file is required')
        if not struct['name']:
            filename = struct['file'].get('filename')
            if filename:
                name_node = file_name_node.bind(
                    context=kw['context'], request=kw['request']
                    )
                name_node.validator(node['file'], filename)
github Pylons / deform / deform / field.py View on Github external
def widget(self):
        """ If a widget is not assigned directly to a field, this
        function will be called to generate a default widget (only
        once). The result of this function will then be assigned as
        the ``widget`` attribute of the field for the rest of the
        lifetime of this field. If a widget is assigned to a field
        before form processing, this function will not be called."""
        wdg = getattr(self.schema, "widget", None)
        if wdg is not None:
            return wdg
        widget_maker = getattr(self.schema.typ, "widget_maker", None)
        if widget_maker is None:
            widget_maker = schema.default_widget_makers.get(
                self.schema.typ.__class__
            )
            if widget_maker is None:
                for (cls, wgt) in schema.default_widget_makers.items():
                    if isinstance(self.schema.typ, cls):
                        widget_maker = wgt
                        break
        if widget_maker is None:
            widget_maker = widget.TextInputWidget
        return widget_maker(item_css_class=self.default_item_css_class())
github Pylons / substanced / substanced / sdi / views / file.py View on Github external
)
def view_file(context, request):
    return context.get_response(request=request)

@mgmt_view(
    context=IFile,
    name='view',
    tab_title='View',
    permission='sdi.view'
    )
def view_tab(context, request):
    return HTTPFound(location=request.mgmt_path(context))

class AddFileSchema(FilePropertiesSchema):
    file = colander.SchemaNode(
        deform.schema.FileData(),
        widget = file_upload_widget,
        missing = colander.null,
        )

@colander.deferred
def name_or_file(node, kw):
    def _name_or_file(node, struct):
        if not struct['file'] and not struct['name']:
            raise colander.Invalid(node, 'One of name or file is required')
        if not struct['name']:
            filename = struct['file'].get('filename')
            if filename:
                name_node = file_name_node.bind(
                    context=kw['context'], request=kw['request']
                    )
                name_node.validator(node['file'], filename)
github Pylons / deform / deform / sampleapp / app.py View on Github external
name = schema.SchemaNode(schema.String())
    dates = DatesSchema()

class FileUploads(schema.SequenceSchema):
    file = schema.SchemaNode(schema.FileData())

class MySchema(schema.MappingSchema):
    name = schema.SchemaNode(schema.String(), description=LONG_DESC)
    title = schema.SchemaNode(schema.String(),
                              validator=colander.Length(max=10),
                              description=LONG_DESC)
    password = schema.SchemaNode(schema.String(),
                                 validator=colander.Length(min=5))
    cool = schema.SchemaNode(schema.Boolean(), default=True)
    series = SeriesSchema()
    color = schema.SchemaNode(schema.String(),
                              validator=colander.OneOf(('red', 'blue')))
    uploads = FileUploads()

def validate_form(form, value):
    if value['name'] != value['title']:
        exc = exception.Invalid(form, 'Name does not match title')
        exc['title'] = 'Does not match title'
        exc['name'] = 'Does not match name'
        raise exc

def form_view(request):
    # Create a schema; when the form is submitted, we want to assert
    # that the name must match the title; we use a validator for the
    # entire form by assigning it a validator
    schema = MySchema(validator=validate_form)