mdipierro
unread,Jan 14, 2009, 1:04:07 PM1/14/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web2py Web Framework
Consider the following table:
db.define_table('cirlce',
db.Field('radius','double'),
db.Field('area','double'),
db.Field('modified_on','datetime'))
now you can do:
# add a comment in the forms
db.circle.area.comment="(this is a comment)"
# do not show area in create/edit forms
db.circle.area.writable=False
# do not show now in display forms
db.circle.modified_on.readable=False
# automatically timestamp when record cretaed
db.circle.modified_on.default=request.now
# automatically timestamp when record is modified
db.circle.modified_on.update=request.now
# make the radius appear in bold in display and table
db.circle.radius.represent=lambda value: B(value)
# make a form that automatically computes area
pi=3.1415
form=SQLFOM(db.circle)
if form.accepts(request.vars,
onvalidation=lambda form: form.vars.area=pi*form.vars.radius**2): ...
# make a create form in two possible ways:
form=SQLFORM(db.circle)
form=SQLFORM(db.circle,0)
# make an update form in two possible ways:
form=SQLFORM(db.circle,record)
form=SQLFORM(db.circle,record_id)
# make a display form in two possible ways:
form=SQLFORM(db.circle,record,readonly=True)
form=SQLFORM(db.circle,record_id,readonly=True)
# so now you can do...
form=SQLFORM(db.circle,request.args[-1])
and you get a create form if the URL ends in /0, you get an update
form if the URL ends in /[valid_record_id]
#you can also define once for all
timestamp=SQLTable(None,'timestamp',
SQLField('created_on','datetime',
writable=False,
default=request.now),
SQLField('modified_on','datetime',
writable=False,
default=request.now,update=request.now))
#and use it in all your tables
db.define_table('mytable',db.Field('somefield'),timestamp)
so that created_on and modified_on are not shown in create/update but
are automatically updated and are shown in display forms.
Comments?
Please TEST TEST TEST
Massimo