コード例 #1
0
def add_csrf(schema: colander.Schema):
    """Add a hidden csrf_token field on the existing Colander schema."""
    csrf_token = colander.SchemaNode(colander.String(),
                                     name="csrf_token",
                                     widget=deform.widget.HiddenWidget(),
                                     default=deferred_csrf_value)

    schema.add(csrf_token)
コード例 #2
0
ファイル: test_init.py プロジェクト: Janaba/adhocracy3
def _add_reference_node(schema: colander.Schema, target_isheet=None):
    from adhocracy_core.interfaces import ISheet
    from adhocracy_core.interfaces import SheetToSheet
    from adhocracy_core.schema import Reference
    reference_node = Reference(name='reference')
    isheet = target_isheet or ISheet
    class PostPoolReference(SheetToSheet):
        target_isheet = isheet
    schema.add(reference_node)
    schema['reference'].reftype = PostPoolReference
コード例 #3
0
ファイル: csrf.py プロジェクト: gitter-badger/websauna
def add_csrf(schema: colander.Schema):
    """Add a hidden CSRF field on the schema."""
    csrf_token = colander.SchemaNode(
        colander.String(),
        name="csrf_token",
        widget=deform.widget.HiddenWidget(),
        default=deferred_csrf_value,
        validator=deferred_csrf_validator,
    )

    schema.add(csrf_token)
コード例 #4
0
def _add_reference_node(schema: colander.Schema, target_isheet=None):
    from adhocracy_core.interfaces import ISheet
    from adhocracy_core.interfaces import SheetToSheet
    from adhocracy_core.schema import Reference
    reference_node = Reference(name='reference')
    isheet = target_isheet or ISheet

    class PostPoolReference(SheetToSheet):
        target_isheet = isheet

    schema.add(reference_node)
    schema['reference'].reftype = PostPoolReference
コード例 #5
0
def add_put_data_subschemas(node: colander.Schema, kw: dict):
    """Add the resource sheet colander schemas that are 'editable'."""
    context = kw.get('context', None)
    request = kw.get('request', None)
    sheets = request.registry.content.get_sheets_edit(context, request)
    if request.content_type == 'multipart/form-data':
        body = unflatten_multipart_request(request)
    else:
        body = request.json_body
    data = body.get('data', {})
    for sheet in sheets:
        name = sheet.meta.isheet.__identifier__
        if name not in data:
            continue
        subschema = sheet.meta.schema_class(name=name)
        node.add(subschema.bind(**kw))
コード例 #6
0
ファイル: schemas.py プロジェクト: libscott/adhocracy3
def add_put_data_subschemas(node: colander.Schema, kw: dict):
    """Add the resource sheet colander schemas that are 'editable'."""
    context = kw.get('context', None)
    request = kw.get('request', None)
    sheets = request.registry.content.get_sheets_edit(context, request)
    if request.content_type == 'multipart/form-data':
        body = unflatten_multipart_request(request)
    else:
        body = request.json_body
    data = body.get('data', {})
    for sheet in sheets:
        name = sheet.meta.isheet.__identifier__
        if name not in data:
            continue
        subschema = sheet.meta.schema_class(name=name)
        node.add(subschema.bind(**kw))
コード例 #7
0
ファイル: validators.py プロジェクト: imwm/mediapublic
def validator_from_model(model):
    validator = Schema(Mapping())
    for key, column in model.__table__.columns.items():
        if key in _excludes:
            # skip things like ID that won't be in the body
            continue
        missing = colander.required
        if column.nullable:
            missing = colander.drop
        validator.add(
            SchemaNode(sqla_to_colander_type(column.type),
                       name=key,
                       missing=missing,
                       **sqla_kwargs(column.type)))

    return CorniceSchema.from_colander(validator)
コード例 #8
0
ファイル: validators.py プロジェクト: thequbit/scrupulous
def validator_from_model(model):
    validator = Schema(Mapping())
    for key, column in model.__table__.columns.items():
        if key in _excludes:
            # skip things like ID that won't be in the body
            continue
        missing = colander.required
        if column.nullable:
            missing = colander.drop
        validator.add(
            SchemaNode(
                sqla_to_colander_type(column.type),
                name=key,
                missing=missing,
                **sqla_kwargs(column.type)
            )
        )

    return CorniceSchema.from_colander(validator)
コード例 #9
0
def _add_post_pool_node(inst: colander.Schema,
                        iresource_or_service_name=IPool):
    from adhocracy_core.schema import PostPool
    post_pool_node = PostPool(
        name='post_pool', iresource_or_service_name=iresource_or_service_name)
    inst.add(post_pool_node)
コード例 #10
0
ファイル: csrf.py プロジェクト: agronholm/websauna
def add_csrf(schema: colander.Schema):
    """Add a hidden CSRF field on the schema."""
    csrf_token = colander.SchemaNode(colander.String(), name="csrf_token", widget=deform.widget.HiddenWidget(), default=deferred_csrf_value, validator=deferred_csrf_validator,)

    schema.add(csrf_token)
コード例 #11
0
ファイル: csrf.py プロジェクト: arianmaykon/websauna
def add_csrf(schema: colander.Schema):
    """Add a hidden csrf_token field on the existing Colander schema."""
    csrf_token = colander.SchemaNode(colander.String(), name="csrf_token", widget=deform.widget.HiddenWidget(), default=deferred_csrf_value)
    csrf_token.dictify_by_default = False
    schema.add(csrf_token)
コード例 #12
0
def _add_other_node(inst: colander.Schema):
    other_node = colander.MappingSchema(name='other', missing={})
    inst.add(other_node)
コード例 #13
0
def _add_references_node(inst: colander.Schema):
    from adhocracy_core.schema import UniqueReferences
    reference_node = UniqueReferences(name='references')
    inst.add(reference_node)
コード例 #14
0
class MappingFields(object):
    def __init__(self,
                 title,
                 name,
                 prefix,
                 l_fields,
                 round=1,
                 desc=None,
                 widget=None):
        self.title = title
        self.desc = desc
        self.prefix = prefix
        self.name = name
        self.l_fields = []

        for f in l_fields:
            try:
                assert (not isinstance(f, MappingFields))
            except AssertionError:
                raise ValueError("Only 1 depth of mapping is allowed")

            f_ = copy.deepcopy(f)
            f_.sn.name = '{}-{}'.format(prefix, f.name)
            self.l_fields += [f_]

        self.round = round
        self.mapinit = {f.name: f.mapinit for f in l_fields}

        self.processing_form = {
            'form': lambda x: {
                f.name: f.processing_form['form'](x[f.name])
                for f in self.l_fields
            },
            'db': lambda x: {
                f.sn.name: f.processing_form['db'](x[f.name])
                for f in self.l_fields
            }
        }

        self.sn = Schema(title=self.title,
                         name=name,
                         description=desc,
                         widget=widget)
        for f in self.l_fields:
            self.sn.add(f.sn)

    def set_mode(self):
        return MappingFields(self.title,
                             self.name,
                             self.prefix,
                             self.l_fields,
                             self.round,
                             desc=self.desc)

    def hidden_mode(self):
        return MappingFields(self.title,
                             self.name,
                             self.prefix,
                             self.l_fields,
                             self.round,
                             widget=HiddenWidget())
コード例 #15
0
ファイル: test_init.py プロジェクト: Janaba/adhocracy3
def _add_other_node(inst: colander.Schema):
    other_node = colander.MappingSchema(name='other', missing={})
    inst.add(other_node)
コード例 #16
0
ファイル: test_init.py プロジェクト: Janaba/adhocracy3
def _add_references_node(inst: colander.Schema):
    from adhocracy_core.schema import UniqueReferences
    reference_node = UniqueReferences(name='references')
    inst.add(reference_node)
コード例 #17
0
ファイル: test_init.py プロジェクト: Janaba/adhocracy3
def _add_post_pool_node(inst: colander.Schema, iresource_or_service_name=IPool):
    from adhocracy_core.schema import PostPool
    post_pool_node = PostPool(name='post_pool',
                              iresource_or_service_name=iresource_or_service_name)
    inst.add(post_pool_node)
コード例 #18
-1
 def admin_view(self):
     schema = Schema()
     schema.add(self.context.question_schema_node('dummy', lang = self.get_lang(), context = self.context))
     form = Form(schema)
     self.response['form_resources'] = form.get_widget_resources()
     self.response['dummy_form'] = form.render()
     return self.response