Lots of new features in trunk, please test

5 views
Skip to first unread message

mdipierro

unread,
Jan 14, 2009, 1:04:07 PM1/14/09
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

vince

unread,
Jan 14, 2009, 1:24:08 PM1/14/09
to web2py Web Framework
nice one! time saver!
what is a display form? is that a form generated readonly? i didn't
know there is a helper to generate display form. can you tell me more?

vincent

Fran

unread,
Jan 14, 2009, 2:19:40 PM1/14/09
to web2py Web Framework
On Jan 14, 6:04 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Please TEST TEST TEST

I get this appended to each row in my T2 forms unless they have
already specified their own table.name.comment:
<td>None</td>

F

mdipierro

unread,
Jan 14, 2009, 2:24:28 PM1/14/09
to web2py Web Framework
yes, new in trunk

mdipierro

unread,
Jan 14, 2009, 2:25:24 PM1/14/09
to web2py Web Framework
T2 needs to be fixed to account for this. for now set comment=''.

mdipierro

unread,
Jan 14, 2009, 4:34:36 PM1/14/09
to web2py Web Framework
One more feature in trunk....

db.define_table('image',SQLField('file','upload'))

and

db.image.file.authorize=lambda record: True or False

then controller

def download(): return response.download(request,db)

will let you download the file if and only if the lambda returns True.
works on GAE too.
the idea to include something like T2.has_access into the lambda and
you can do authorization of media files uploaded by users almost
without coding.

Massimo

Paul Eden

unread,
Jan 14, 2009, 5:05:29 PM1/14/09
to web...@googlegroups.com
Very nice.
--
Best Regards,

Paul Eden

"...and a little looking out for the other guy too."
- Mr. Smith
Reply all
Reply to author
Forward
0 new messages