@pbreit: yes, I know. I'm using some capabilities (e.g. login) but I
want to create some forms on my own to customize it to my needs.

I don't see how the extra_fields solves my problem (btw, is this
explained somewhere in the official documentation? I couldn't find
it). The table definition itself is fine.

I think I've expressed my problem badly because actually it has
nothing to do with the auth_user table specifically. I created an
artificial table which hopefully explains it better.

consider a table like this:

db.define_table('mytable',
    Field('setting1', 'string'),
    Field('setting2', 'string'))

and this controller:
def edit1():
    id = request.args(0)
    db.mytable.setting2.readable = db.mytable.setting2.writable =
False
    row = db.mytable(id)
    form=SQLFORM(db.mytable, row)
    if form.accepts(request.vars, formname='mytable_form'):
        logger.debug(db._lastsql)
    return dict(form=form)


the form in the view only shows setting1, so far so good. But when I
submit the form this is the performed sql statement:
UPDATE mytable SET setting1='value1',setting2='value2' WHERE
(mytable.id = 1);

I don't want setting2 to be updated in this statement. Since writable
was set to False I would expect a sql statement like this:
UPDATE mytable SET setting1='value1' WHERE (mytable.id = 1);

did I understand something wrong? If so, how could I achieve only an
update of setting1?

On 18 Sep., 04:59, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> Why not just do?
>
> auth = Auth()
> auth.settings.extra_field['auth_user'] = []
> auth.define_tables()
>
> On Sep 17, 10:46 am, Alex <mrauc...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > first of all, many thanks to Massimo and all other contributers.
> > web2py is an amazing framework and exactly what I was looking for.
> > Keep up the excellent work!
>
> > I've got a couple of questions and problems so I'll start with the one
> > which is bugging me the most:
> > I've defined the auth_user table, added username, password and some
> > other fields. So far everything works fine. Now I want to create a
> > form where the user can change the password. In this form I do not
> > want to modify any of the other fields. So I'm doing the following
> > before creating the SQLForm (user_table == db.auth_user):
>
> > for field in user_table.fields:
> >   if field == 'password':
> >     user_table[field].readable = user_table[field].writable = True
> >   else:
> >     user_table[field].readable = user_table[field].writable =
> > False
>
> > this works fine, the form only contains the password field. But when I
> > submit the form, I end up with the following error:
> > File "C:\Tools\web2py_src\gluon\sqlhtml.py", line 1202, in accepts
> >     fields[field.name] = self.record[field.name]
> >   File "C:\Tools\web2py_src\gluon\dal.py", line 3777, in __getitem__
> >     return dict.__getitem__(self, key)
> > KeyError: 'registration_key'
>
> > so its trying to update a field which is writable==False. When I look
> > into the code in sqlhtml.py (line 1200) this is confusing me a little
> > bit:
> > for field in self.table:
> >   if not field.name in fields and field.writable==False:
> >     if record_id:
> >       fields[field.name] = self.record[field.name]
> >     elif self.table[field.name].default!=None:
> >       fields[field.name] = self.table[field.name].default
>
> > why is it checking writable==False? shouldn't it test for
> > writable==True or do I get something wrong here?
>
> > Alex

Reply via email to