Skip to main content

Extra SQLAlchemy support for zeam.form

Project description

zeam.form.rdb provides an helper to generate form fields for zeam.form.base, using zeam.form.ztk fields from an SQLAlchemy model.

To accomplish, you must create your fields using the descriptor ModelFields in your form. It will automatically fetch the context of the form, and generate the fields accordingly, caching them (for performance reasons).

Example:

from zeam.form.rdb import ModelFields
from zeam.form.base import Form

class MyForm(Form):
  label = "Test form"
  fields = ModelFields()

In your SQLAlchemy schema, you can use the extra dictionnary info to control the widget generated. Foreign key will generate a choice of possible values to select, using the column you desire as title.

Example:

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Integer, String
from zope import schema

idT_Effort = Column(
    'idT_Effort',
    Integer,
    primary_key=True,
    info={'title': u"Identifier"})
idT_Opportunity = Column(
    'idT_Opportunity',
    Integer,
    ForeignKey('T_Opportunity.idT_Opportunities'),
    info={'title': u'Opportunity',
          'title_column': 'Title'})
Name = Column(
    'Name',
    String(45))
URL = Column(
    'URL',
    String(63),
    info={'title': u"URL",
          'schema': schema.URI})

For a ForeignKey, you have the possibility to provides multiple columns to title_column, and a function to be called to create the title as title_factory, both in the info dictionnary.

A field will be required unless the column is nullable, or the option required is given through info.

title and description from info will be used as well in order to create the form field.

Changes

1.0b1 (2012/04/27)

  • Initial version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zeam.form.rdb-1.0b1.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file zeam.form.rdb-1.0b1.tar.gz.

File metadata

  • Download URL: zeam.form.rdb-1.0b1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zeam.form.rdb-1.0b1.tar.gz
Algorithm Hash digest
SHA256 b2df39666038af672b1a705afd4d8c1290b187890e792196ffdcfd5b242d1192
MD5 5b4d1c028ed461c850abde736880e65c
BLAKE2b-256 2bdbc3b24cd3f7b19e062968fee9bf155ead18fd734288e1a9ba2ce1a10d4750

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page