Hi all,
This is my first foray into web app design and so I wondered if it
would be possible to get a bit of a sanity check on what I'm doing to
ensure I'm understanding web2py correctly.
My database has a table which should store data collected by SQLFORM
along with the ID of the logged on user who entered the data.
The relevant bits of my model look like this:
--------------------
db.define_table('data',
Field('dataowner', db.auth_user, default=auth.user.id,
writable=False, readable=False), #this points at the auth user
Field('provider', db.providers), #points to another table
Field('speed', 'integer'),
Field('timestamp', default=request.now, writable=False,
readable=False))
db.data.dataowner.requires=IS_IN_DB(db,
'auth_user.id','auth_user.email') #and here shows which field to
return for a record
db.data.provider.requires=IS_IN_DB(db, 'providers.id','providers.name')
db.data.speed.requires=IS_NOT_EMPTY()
---------------------
And the controller like this:
---------------------
@auth.requires_login()
def adddata():
form=SQLFORM(db.data, fields=['provider', 'speed'])
if form.accepts(request.vars, session):
#response.flash puts the flash in this page, session.flash in
the next page of the session
session.flash = 'form accepted'
redirect(URL(r=request, f='index'))
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)
----------------------
My intention is to collect the provider and speed data with SQLFORM
and for the logged on user id and the timestamp to be automatically
populated. As you can see, I have used a decorator on the adddata
function to require a logged on user.
Does this look right to you?
Thanks in advance!
Chris