Before you attempt a more complex solution, you should do some analysis to 
figure out if one extra Ajax request is really a problem (either for the 
server or the browser). Even though the Ajax approach requires an extra 
request, it may actually end up being a bit more efficient, as all the 
requests relating to login and the form in question will not require any 
full page reloads (so no need to generate, transmit, and re-render the full 
page layout -- just the forms).

Alternatively, I suppose you could conditionally include either a login 
form or your other form in the initial page depending on whether the user 
is logged in. Then, if they hit "apply" and are not logged in, they see the 
login form, log in, and are then returned to the original page, which this 
time will include the main form (you could send a flag that will trigger 
the modal to open automatically when the page loads).

Anthony

On Saturday, February 20, 2016 at 1:55:24 PM UTC-5, Ron Chatterjee wrote:
>
> Here is an example that I leveraged from the other thread. If I 
> insert @auth.requires_login() on the top of any of the function definition, 
> then when I go to the view main_page, I will get the log in screen first. 
> The question is, how do I access the main_page without logging in but only 
> get asked to log in when the form is displayed. One way to do this would be 
> to put SQLFORM(db.mytable).process() outside as an independent function def 
> and then use   @auth.requires_login(). But in that case, I will need to use 
> LOAD. And I am not a big fan of using component and overload the browser.
>
> *Model:*
> db.define_table('mytable',
>                 Field('name', type='list:string', requires=IS_IN_SET 
> (('True','False', 'Neither'), multiple=True)))
>
> *View:*
> {{extend 'layout.html'}}
> <h1>
>     Hit apply to see the modal
> </h1>
> {{=A( 'Apply to this post',_class = "btn 
> btn-primary",_style="background-color:green;;background-image:none",_onclick="""
>  
> $('#cont_id').modal('show')   """)}}
> {{=main_pg}}
>
> *Controller:*
>
> def main_page():
>     main_pg=DIV('')
>     form = SQLFORM(db.mytable).process() 
>     dialog = modal_wrapper(form, _id='cont_id', header='Header', 
> footer='footer')
>     main_pg.append(dialog)
>     return dict(main_pg = main_pg)
>
> def modal_wrapper(content, _id, header='', footer=''):
>
>     main_wrap = DIV('',  _class="modal fade",  _role="dialog", _id=_id, 
> _tabindex="-1" )
>     title_id = _id + '_title'
>     main_wrap['_aria-labelledby']=title_id
>
>     dialog_div=DIV('', _class="modal-dialog" , _role="document")
>     content_div=DIV('', _class="modal-content")
>     header_div = DIV( _class="modal-header")
>
>     close_cross = BUTTON(
>                         SPAN(XML('&times'), **{'_aria-hidden':"true"}),
>                         _type="button",  _class="close",
>                          data={'dismiss':"modal"},
>                          **{'_aria-label':"Close"}
>                          )
>     title_h4 = H4( header,  _class="modal-title",  _id = title_id)
>     body_div = DIV( content, _class="modal-body")
>
>
>     close_btn = BUTTON('Close',  _type="button", _class="btn btn-default", 
> data={'dismiss':"modal"})
>     footer_div =  DIV( footer, close_btn, _class="modal-footer")
>
>     # gluon all
>     main_wrap[0] = dialog_div
>     dialog_div[0] = content_div
>
>     header_div.append(close_cross)
>     header_div.append(title_h4)
>
>     [content_div.append(c) for c in (header_div, body_div, footer_div)]
>     return main_wrap
>
>
>
> On Thursday, February 18, 2016 at 8:35:09 PM UTC-5, Anthony wrote:
>>
>> If you alternatively want a login form or the main form to appear in the 
>> modal, and upon login you want the login form replaced with the main form 
>> in the modal (without having to re-click the apply button), it seems using 
>> an Ajax component would be the most straightforward approach.
>>
>> Anthony
>>
>> On Thursday, February 18, 2016 at 7:49:03 PM UTC-5, Ron Chatterjee wrote:
>>>
>>> Yes. Exactly
>>>
>>> On Thursday, February 18, 2016 at 6:23:44 PM UTC-5, Najtsirk wrote:
>>>>
>>>> If I do understand you correct: you want to have in the same modal form:
>>>>
>>>>    - if the user is logged in: a form for submitting a new Post;
>>>>    - if the user is not logged in: a login form.
>>>>
>>>> Is that correct?
>>>>
>>>> On Thursday, 18 February 2016 23:22:19 UTC+1, Ron Chatterjee wrote:
>>>>>
>>>>> Here in the picture I explained. Once I click on the button, I do 
>>>>> display the form in my modal. But that display inside the modal can only 
>>>>> be 
>>>>> if the user signed in or the request to sign in. If I could do something 
>>>>> like this.
>>>>>
>>>>> def process_form():
>>>>>
>>>>>        form = SQLFORM(db.post).process()
>>>>> return locals()
>>>>>
>>>>> Then I could use @auth.requires_login() on the top of the def. If I do 
>>>>> that, then I will need to use load inside myfunction which I don't want 
>>>>> to. 
>>>>> May be I need to think more..lol
>>>>>
>>>>>
>>>>> On Thursday, February 18, 2016 at 4:04:28 PM UTC-5, Anthony wrote:
>>>>>>
>>>>>> On Thursday, February 18, 2016 at 3:58:08 PM UTC-5, Ron Chatterjee 
>>>>>> wrote:
>>>>>>>
>>>>>>> Yes. Or if there is a way to add @auth.requires_login() to the table 
>>>>>>> itself. In other words, SQLFORM will validate if the user is logged in 
>>>>>>> or 
>>>>>>> not based on that flag. like requires=IS_NOT_EMPTY(). Similar to that 
>>>>>>> requires = IS_LOGGED_IN(). But there isn't anything like that. lol. So, 
>>>>>>> yes, I need to work around.
>>>>>>>
>>>>>>
>>>>>> The point is, you want to check for login *before* presenting the 
>>>>>> form. In any case, it's trivially easy to add code to check for login 
>>>>>> before showing a form, so I don't think it would be all that helpful to 
>>>>>> build that functionality into SQLFORM.
>>>>>>
>>>>>> Anthony
>>>>>>
>>>>>

-- 
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.

Reply via email to