Make sure we have these;
pip install sprox pip install genshi pip install tw.forms
And we will be able to write a script to produce a form without getting too long.
from sqlalchemy import Column, Integer, String, create_engine, Date, Float, Text from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base from sprox.formbase import AddRecordForm, FormBase from sprox.fillerbase import TableFiller from sprox.tablebase import TableBase # coding: utf-8 Base = declarative_base() metadata = Base.metadata class Customer(Base): __tablename__ = 'customer' id = Column(Integer, primary_key=True) customer = Column(String(6), nullable=False, unique=True) name = Column(String(40), nullable=False) zip = Column(String(255), nullable=False) phone1 = Column(String(31), nullable=False) class newCustomerForm(FormBase): __model__ = Customer class DBSession1(): def __init__(self): dbhost = "x" dbuser = "x" dbpass = "x" dbdbas = "x" self.engine1= create_engine('mysql://' + dbuser + ":" + dbpass + "@" + dbhost + "/" + dbdbas) self.Base1 = declarative_base() self.Session1 = sessionmaker(bind=self.engine1) return None if __name__ == "__main__": w = DBSession1() x = newCustomerForm(w.Session1) print x()
What is Genshi and why did it pop up?
This might actually be a weakness of the Sprox packages, but Sprox really likes Genshi to make that final push from a Python data structure to HTML code. I call it a weakness, but this final transition is the realm of a template architecture. Popular Python templating specifications include Jinja2, Chameleon(Zope), Mako, etc. The weakness here is that it really likes Genshi, and it is not obvious how to use, for example, Mako instead.