Hi,
I have defined a database table which has some fields which must be
computed:
agent_table = 'agent'
db.define_table(
agent_table,
Field('email', unique=True),
Field('agent_doc_id', length=128, compute=create_new_agent),
Field('password', 'password', length=512,
compute=automatic_password,readable
=False, label='Password'),
format = '%(email)s %(agent_doc_id)s %(password)s')
# Add constraints to the agent table
agent = db[agent_table]
agent.email.requires =
[IS_EMAIL(error_message=auth.messages.invalid_email), IS_NOT_IN_DB(db,
'%s.email' % (agent_table))]
The functions create_new_agent and automatic_password are part of my
libraries. They are returning the expected types (strings in both cases)
I am rendering the form with:
def register_agent():
# create an insert form from the table
form = SQLFORM(db[agent_table])
# Pre-populate the email with the input in the signup page
form.vars.email = request.vars.email
# if form is correct perform the insert
if form.process().accepted:
response.flash = 'Agent created'
else:
response.flash = 'Please fill in the form'
# and get a list of all agents
records = SQLTABLE(db().select(db.agent.ALL),headers=
'fieldname:capitalize')
return dict(form=form, records=records)
I was assuming that form.process() will take care of updating the fields
which have a compute parameter, and then insert the resulting data in the
database.
But this is not what is happening: the 'compute' fields are empty.
How can I force the 'compute' fields to be updated?
Thanks,
Daniel
--