the easiest (and "eastethically pleasing") method is to use components:
controllers/default.py
def index():
form1 = LOAD('default', 'form1.load', ajax=True)
form2 = LOAD('default', 'form2.load', ajax=True)
form3 = LOAD('default', 'form3.load', ajax=True)
def form1():
grid = SQLFORM.grid(db.table1, formname='form1')
return dict(grid=grid)
def form2():
grid = SQLFORM.grid(db.table2, formname='form2')
return dict(grid=grid)
def form3():
grid = SQLFORM.grid(db.table3, formname='form3')
return dict(grid=grid)
On Tuesday, June 3, 2014 5:06:55 PM UTC+2, john smith wrote:
>
> Thanks, naming forms works as expected.
> Regarding grid, when I try to access show_readers function as admin, I get
> redirected to readers function with flash message saying: 'not authorized'.
> Librarian can access it, but not if I move the grid code outside of if
> statement, then librarian gets same message. I don't need to use grid, I
> just want there to be a list of groups user is currently a member of, and a
> button next to all these groups that would remove the user from group. I
> will probably try to do it using for loop and html table.
> I'm not sure how am I supposed to resolve my dropdown issue with SQLFORM
> factory, but I'll try to read some more on that. General idea I had for
> that would be a form with one field only and a submit button. The field
> would be a dropdown list with a list of all groups in auth_groups. Then
> admin could add users to group by just selecting group and clicking submit.
> Basically I want to have same thing that you get in appadmin for adding new
> record to auth_membership, just without the User_id field (it would by
> default take value from request.args). This dropdown list combined with
> list of groups with some kind of 'remove from group' buttons, should
> provide an easy way for admins to manage user groups. I hope that
> explanation was clear, English is not my first language. Thank you for your
> help.
>
> W dniu wtorek, 3 czerwca 2014 16:21:21 UTC+2 użytkownik LaDarrius Stewart
> napisał:
>>
>> 1) Use SQLFORM factory.
>> 2) Name your forms example below. (changes in red do this to them all
>> with different names of course)
>> 3) Not sure whats going on can you explain a bit more?
>> form2=FORM('Your name:',
>> INPUT(_name='grupa', _type='text'),
>> INPUT(_type='submit'))
>> if form2.process(formname='SomeName').accepted:
>> redirect(URL('index'))
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.