I need to ask one more thing before it works.
when an auth_user first registers, the "created_by" field is empty in the
auth_user
table.
But I want to let user go back and change their email or name or something,
so I need "created_by" field to contain auth_user.id in it. Otherwise, it
doesn't know who created it and won't let data owner update their own
record.
This problem only occurs for one table, one time, the first time that users
register. Otherwise, users can exclusively edit their own records for all
other tables using the same code.
How can I get "created_by" field to populate with the new user's
auth_user.ID when they first register?
Not sure if you need to see it, but below, is code I use for new users to
register.
thanks
Alex
def add_new_person():
db.ObjectSuperType.objectTypeID.readable =
db.ObjectSuperType.objectTypeID.writable = False ## don't let user see
field thinking they have to fill it in
db.Party.objectID.readable = db.Party.objectID.writable = False ##
don't let user see field thinking they have to fill it in
db.auth_user.partyID.readable = db.auth_user.partyID.writable = False
## don't let user see field thinking they have to fill it in
db.Party.partyTypeID.readable = db.Party.partyTypeID.writable = False
## don't let user see field thinking they have to fill it in
db.PartyAddressIntersection.addressID.readable =
db.PartyAddressIntersection.addressID.writable = False ## don't let user
see field
db.Address.id.readable = db.Address.id.writable = False ## don't let
user see field
db.auth_user.personIPAddressFirstRegisteredWith.readable =
db.auth_user.personIPAddressFirstRegisteredWith.writable = False
db.auth_user.credibility.readable = db.auth_user.credibility.writable =
False
db.Party.partyTypeID.default = 1 ## sets up db so it's a person, not
organization
db.ObjectSuperType.objectTypeID.default = 1 ## sets up db so object
type is designated as a party (not a component)
form=SQLFORM.factory(db.ObjectSuperType,db.Party,db.auth_user,db.PartyAddressIntersection,db.Address)
if form.process().accepted:
objectID =
db.ObjectSuperType.insert(**db.ObjectSuperType._filter_fields(form.vars))
form.vars.objectID=objectID
partyID = db.Party.insert(**db.Party._filter_fields(form.vars))
form.vars.partyID=partyID
partyID =
db.auth_user.insert(**db.auth_user._filter_fields(form.vars))
addressID =
db.Address.insert(**db.Address._filter_fields(form.vars))
form.vars.addressID=addressID
partyID =
db.PartyAddressIntersection.insert(**db.PartyAddressIntersection._filter_fields(form.vars))
response.flash='Thanks for filling the form'
return dict(form=form)
On Monday, August 5, 2013 3:02:42 AM UTC-7, Alex Glaros wrote:
>
> You're right Kostas, that was a great catch
>
> created_by field was empty
>
> thanks!
>
> Alex
>
> On Monday, August 5, 2013 1:50:08 AM UTC-7, Kostas M wrote:
>>
>> This grid indicates that db.auth_user has a 'created_by' column. Is this
>> your case?
>> Anyway, trying your code at a different table having a 'created_by'
>> column worked fine to me (buttons Edit and Delete are there).
>>
>>
>>
>> On Sunday, August 4, 2013 5:17:40 AM UTC+1, Alex Glaros wrote:
>>>
>>> This looks like it should work, using grid, but the "edit" button
>>> doesn't appear. only the view button.
>>>
>>> @auth.requires_login()
>>> def manage_user_profile():
>>> is_owner = (lambda row: row.created_by == auth.user_id) if auth.user
>>> else False
>>> grid = SQLFORM.grid(db.auth_user.id == auth.user_id,
>>> editable=is_owner,create=False, deletable=is_owner, user_signature=True),
>>> return dict(grid=grid)
>>>
>>>
>>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.