Questions tagged [colander]

Colander is a simple framework for validating, serializing and deserializing of data obtained via XML, JSON, an HTML form post or any other equally simple data structure.

The colander python package allows you to:

  • Define a schema declaratively (as a series of Python classes), or imperatively (with a series of function calls).
  • Deserialize a structure of simple types (sequences, mappings, numbers, strings) to produce objects conforming to your schema. The input is validated automatically.
  • Serialize objects conforming to the schema to a simple python structure, suitable for conversion to JSON, XML or HTML form data.

Colander is a good basis for form generation systems, data description systems, and configuration systems.

72 questions
12
votes
3 answers

colander schema for mapping where keys are variable but value are arrays

How do I define the schema in colander for JSON of the following form? { 'data' : { 'key_1' : [123, 567], 'key_2' : ['abc','def'], 'frank_underwood' : [666.66, 333.333], ... etc ... } } The keys inside 'data'…
XiaoChuan Yu
  • 3,951
  • 1
  • 32
  • 44
9
votes
1 answer

How to make file upload facultative with Deform and Colander?

I would like to render a form containing a sequence of files, representing different images of a product. Providing files should be facultative, so the form should validate even in the absence of files. How can I do this ? Here is the colander…
ascobol
  • 7,554
  • 7
  • 49
  • 70
8
votes
2 answers

Deform/Colander validator that has access to all nodes?

How do you define a custom validator in Deform/Colander that has access to all node values. I need to access the values from two fields in order to decide if a particular value is valid or not?
user2665694
6
votes
1 answer

Catch empty list with colander

I'm using colander to validate (and deserialize json data) input to some web services. I would like to add a rule to a colander schema to catch an empty list, but I can not figure out how to do it. Right now I have the following example,…
mogul
  • 4,441
  • 1
  • 18
  • 22
6
votes
1 answer

Using colander for xml deserialization

How should colander be used for xml deserialization? Docs say that it can even be used for xml deserialization and validation, but I didn't find any good examples for that in docs or on the web! If anyone has used colander for xml deserialization…
Neo
  • 5,070
  • 10
  • 46
  • 65
5
votes
1 answer

Allow raw HTML in Deform form description fields

How would you stop Deform from escaping HTML in field titles or descriptions when rendering? My current best solution is to search/replace the returned rendered HTML string with what I need. Deform by default will escape all HTML characters to HTML…
Oli
  • 1,335
  • 1
  • 9
  • 10
4
votes
1 answer

Validate optional values with Colander

I'm using Colander to validate request parameters for a Pyramid web server. For example: class MySchema(colander.MappingSchema): first_name = colander.SchemaNode(colander.String()) …
Jens
  • 8,423
  • 9
  • 58
  • 78
4
votes
1 answer

Working with Many to Many Relationships in Deform/Colander HTML Select Field

I'm working in the Pyramid framework and using the Deform package to render HTML forms given a colander scheme. I'm struggling to get my head wrapped around how to handle a schema with a many to many relationship. For example, my sqlalchemy models…
dhildreth
  • 637
  • 1
  • 6
  • 15
4
votes
1 answer

Report form post-process error messages in HTML controls with Deform

Deform allows to add validation on different fields of a form. However, it checks that the form is valid in itself but that does not necessarily mean that the form processing will be valid. For example, if the form is for creating a new user with an…
user1919510
3
votes
1 answer

Is there a way to make a deform/colander form field read-only/disabled?

I'm trying to use deform as part of pyramid and have no trouble getting fully editable or fully read-only forms, but I can't seem to find a way of creating a read-only text input field. The following code does not do what I want, but I think you…
d0nut
  • 610
  • 5
  • 5
3
votes
0 answers

How to define a decimal with two decimal places using Python colander

I'm a newbie Python developer. I have a class that defines a DecimalNode in my Python code as such: class DecimalNode(colander.SchemaNode): schema_type = colander.Decimal validator = colander.Range(0, 100) But I need to make sure that there is a…
Ray
  • 4,679
  • 10
  • 46
  • 92
3
votes
2 answers

How to convert a datetime from one arbitrary timezone to another arbitrary timezone

Let's say I receive an arbitrary datetime object in a request, like this, which could be coming from any possible timezone - I don't know which one. For the sake of example, pretend it comes from the East Coast import pytz from colander import…
slashdottir
  • 7,835
  • 7
  • 55
  • 71
3
votes
0 answers

How to create tuples from two columns with sqlalchemy, populate deform select widget from database

The deform select widget takes a sequence of two element tuples. How do I create two element tuples from two columns from an sqlalchemy query. The below code works with the hardcoded example. class ProfileValueSelect(colander.MappingSchema): …
BScott
  • 135
  • 6
3
votes
1 answer

How to use lists or arrays in Colander forms

How can I send lists/arrays in POST forms and get them decoded with Colander? I've tried in several ways but no luck so far. Using a form and Colander schema like the following will throw the error: [1,2,3] is not iterable example_1.html:
Ander
  • 5,093
  • 7
  • 41
  • 70
3
votes
2 answers

Sharing objects between view and application with Pyramid

I'm trying to create a web interface for a data analysis pipeline using Pyramid. I'm using deform and colander to make the forms. I've been adapting this example: http://pyramid-tutorials.readthedocs.org/en/latest/humans/security/step02/ Most of the…
ate50eggs
  • 444
  • 3
  • 14
1
2 3 4 5