Ok, I managed to do almost everything I want in this function. Now I only 
need to know how to remove the record by clicking a button. I think that i 
just need to put this: 'db(db.auth_membership.id==row.id).delete()' in 
onclick property of the button. The problem is that all solutions for it I 
found do not work. I get invalid syntax error caused by apostrophes. 
Anybody have any idea on how to solve it?

W dniu wtorek, 3 czerwca 2014 18:18:42 UTC+2 użytkownik john smith napisał:
>
> Yes, it works if I add writable=False, but I still have to set user_id to 
> user.id and I don't know how to do that. 
> In regards to components, I'm not sure how does it solve my problem. Could 
> you please elaborate? I will look into this to improve my project but I 
> have deadline on Monday and need to work on other stuff. 
> Oh, and by the way, do you have any idea on how to select a user who does 
> not have a record in auth_membership? This is my current code and it 
> worked, but I want to change the query because I changed my model a little 
> bit.
> @auth.requires(auth.has_membership('librarian') or 
> auth.has_membership('admin'))
> def readers_pending():
> grid = SQLFORM.grid(db.auth_user.registration_key=='blocked', 
> deletable=False, editable=False, create=False, details=False, paginate=25, 
> links=[dict(header='Link',body=lambda row: A(T('Show'), 
> _href=URL('show_reader',args=row.id)))])
> return locals()
>
>
>
> W dniu wtorek, 3 czerwca 2014 17:30:11 UTC+2 użytkownik LaDarrius Stewart 
> napisał:
>>
>> As far as " I could replace it with SQLFORM but then I need to know how 
>> to hide user_id field and set it to user.id value"
>> What do you mean are you just trying to hide the id value? like this -> 
>> db.table.id.readable=False ?
>>
>> On Sunday, June 1, 2014 9:10:07 AM UTC-5, john smith wrote:
>>>
>>> I want to create a page that will display user data, with additional 
>>> controls. I want librarian to be able to add user to 'readers' and remove 
>>> group,  that part works. I also want admin be able to freely manage groups 
>>> of a user, I want him to have a widget that will have a list of groups with 
>>> submit button that will add user to selected group, and list of all groups 
>>> user is a member of with ability to remove him from those. I have 3 
>>> problems with that:
>>> 1. I don't know how to create form that will display drop-down list with 
>>> groups, like SQLFORM does. I could replace it with SQLFORM but then I need 
>>> to know how to hide user_id field and set it to user.id value
>>> 2. Even when click submit button of form2, action of form is executed.
>>> 3. SQLFORM.grid won't let me access the view, i get flash with 'not 
>>> authorized' message.
>>> Here is my code:
>>> @auth.requires(auth.has_membership('librarian') or 
>>> auth.has_membership('admin'))
>>> def show_reader():
>>> if request.args(0) and db.auth_user(request.args(0, cast=int)):
>>> user = db.auth_user(request.args(0, cast=int))
>>> form2=''
>>> if (auth.has_membership('admin', user.id) or 
>>> auth.has_membership('librarian', user.id)) and not 
>>> auth.has_membership('admin'):
>>> session.flash = T('Insufficient privileges')
>>> redirect(URL('readers'))
>>> else:
>>> if not auth.has_membership('reader', user.id):
>>> form=FORM(INPUT(_type='submit', _value=T('Activate user')))
>>> if form.process().accepted:
>>> session.flash = T('User has been activated')
>>> db.auth_membership.update_or_insert(user_id=user.id
>>> ,group_id=auth.id_group('reader'))
>>> redirect(URL('show_reader', args=user.id), client_side=True)
>>> else:
>>> form=FORM(INPUT(_type='submit', _value=T('Deactivate user')))
>>> if form.process().accepted:
>>> session.flash = T('User has been deactivated')
>>> #user.registration_key='blocked'
>>> #user.update_record(registration_key='blocked')
>>> db(db.auth_membership.user_id==user.id).delete()
>>> redirect(URL('show_reader', args=user.id), client_side=True)
>>> if auth.has_membership('admin'):
>>> #form2=''
>>> form2=FORM('Your name:',
>>> INPUT(_name='grupa', _type='text'),
>>> INPUT(_type='submit'))
>>> if form2.process().accepted:
>>> redirect(URL('index'))
>>> form3=SQLFORM.grid(db.auth_membership.user_id==user.id, 
>>> deletable=False, editable=False, create=False, details=False)
>>>
>>> return locals()
>>> else:
>>> session.flash = T('No such user')
>>> redirect(URL('readers'))
>>>
>>>
>>>
>>>
>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to