hello, by default, if some function needs auth, w2p gives back some
text/html:
When I work with components ajax way, I don't want my content parts to
get mangled with it...
1) if I am not logged in, it would flood my tiny content area with big
login page clone :)
2) in my case, I want my current content (of target div) to stay in
place if I don't have permisions,  (and new  content should replace it
only if accessible).

so I made a small patch, You can test it hear
https://web2py-gae-test.appspot.com/auth_for_web2py_components/default/test
its default new app with several changes in
/controllers/default.py : user()
/views/web2py_ajax.html  : web2py_ajax_page()

is it a good way? or how would be better?

/controllers/default.py

def user():
    if request.ajax:
        result = auth()
        if not auth.user:
            return "ERROR" +"<br> You should %s first <br>\n" %
( A('login',  _target="blank", _href=auth.settings.login_url).xml())
        if isinstance(result, str):
            response.flash = result
            return "ERROR"
        return result # no dict(form=result)
    else:
        return dict(form=auth())


/views/web2py_ajax.html

    'success': function(text) {
        if (text.startsWith( "ERROR" )) {
          jQuery('#'+target).prepend( text.substr( "ERROR".length ) );
        }
        else {
            jQuery('#'+target).html(text);
        }

Reply via email to