Hi Massimo

Yes.

I included the relevant lines in my first post (with writable=False
attribute).

The point was to make an added username field selectively writeable at
the form processing level. I spelt 'writable' incorrectly in one of my
lines. Everything is working fine now.

The username field is required for upcoming enhancements to a web site
with added e-commerce facilities such as an item quantity editable
cart, an order history and a payment history as an account. The key to
getting e-commerce facilities with this level of sophistication
working without headaches is well thought out database table design
and a good framework. Web2py is an excellent framework and has great
database tools, such as database table migration and inbuilt database
administration.

Here is what I am currently using for the username field.

model file before auth.define_tables():

    db.Field('username', length=32, label="User Name",
writable=False,),

table.username.requires   =  [IS_LENGTH(minsize=3,
error_message="Three or more characters required"), IS_ALPHANUMERIC(),
IS_NOT_IN_DB(db, table.username)]

controller file:

def user():
    if request.args and request.args[0] in ('register', 'login'):
      auth.settings.table_user.username.writable=True
    return dict(form=auth())

John Heenan


On Sep 17, 12:07 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> no, but there is a retrieve_username.
>
> Mind that web2py knows how to handle a field called username. Have you
> tried just the following?
>
> ...
>     Field('username', length=32, label="User Name")
> ...
> db.auth_user.username.requires   =  [IS_LENGTH(minsize=3,
> error_message="Three or more characters required"), IS_NOT_IN_DB(db,
> table.username)]
>
> def user(): return dict(form=auth())
>
> On Sep 16, 7:18 pm, John Heenan <johnmhee...@gmail.com> wrote:
>
> > I have fixed my own problem. I had a spelling mistake; 'writable' does
> > not have an extra e in it!
>
> > Upon fixing the problem I needed to make a slight adjustment to the
> > code to make it work properly. If there are no arguments to the user
> > function then a redirection to user/login (even if logged in already)
> > occurs so the code still works.
>
> > Here is the adjustment:
>
> > def user():
> >     if request.args and request.args[0] in ('register', 'login'):
> >       auth.settings.table_user.username.writable=True
> >     return dict(form=auth())
>
> > Now I wonder if there an easy way to also include the username field
> > for user/retrieve_password ?
>
> > John Heenan
>
> > On Sep 16, 5:09 pm, John Heenan <johnmhee...@gmail.com> wrote:
>
> > > I want to make an added username field of a custom auth_user table
> > > writeable with registration.
>
> > > This is how the custom non writeable field is defined:
> > >     db.Field('username', length=32, label="User Name",
> > > writable=False,),
>
> > > The require attribute is added externally:
> > > table.username.requires   =  [IS_LENGTH(minsize=3,
> > > error_message="Three or more characters required"), IS_NOT_IN_DB(db,
> > > table.username)]
>
> > > This is how I alter the alter writeable attribute for registration
>
> > > def user():
> > >   if request.args and request.args[0]=='register':
> > >     auth.settings.table_user.username.writeable=True
> > >   return dict(form=auth())
>
> > > The field does not change to a writeable one in the registration
> > > action.
>
> > > I don't know what else I need to do to make the field writeable.
>
> > > John Heenan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to