Keep in mind that the layout is executed for every page (that extends it), 
so only defining that variable in the dashboard function will not work, as 
it will remain undefined otherwise. Declaring the variable as global within 
the dashboard function has no effect because each HTTP request executes the 
models, controller, and view in a fresh environment. Instead, you should 
either set a default value for user_right1 in a model file or directly in 
the layout. In the layout, you can do something like:

{{if globals().get('user_right1', False):}}

The above will check if 'user_right1' is defined in the current global 
environment (for the current request), and if not, it returns a default 
value of False.

Anthony

On Wednesday, June 6, 2018 at 6:05:44 AM UTC-4, Rahul wrote:
>
> Hi Anthony,
>          Thanks for getting back - I understood your point. I included it 
> in one of my functions and called it where it worked.  for example I called 
> it in dashboard() function which is used to show the dashboard and is the 
> first landing page of my application. However now whenever I want to 
> navigate to some other page it gives me the following error -  Basically it 
> is the same error I got before. It is trying to fetch value of user_right1 
> . 
> I have even defined* user_right1* as global and provided a default value 
> for example 
>
> global user_right1
> user_right1=False
>
> *Error*:
> 127.0.0.1.2018-06-06.15-16-08.ba03dfb3-628e-42bf-9b34-fe8a6d34c5ec
> *<type 'exceptions.NameError'> name 'user_right1' is not defined*
> Version
>
> web2py™
> Version 2.15.3-stable+timestamp.2017.08.07.12.51.45 
>
> Python
> Python 2.7.13: C:\Python27\python.exe (prefix: C:\Python27) 
>
> Traceback
>
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
>
> Code in my controller is pretty simple it retrieves the value stored in 
> the database and checks whether it is *True *or *False *and based on the 
> value it provides module access to the users
> *default.py *
>
> global user_right1
> user_right1 = False
>
> def dashboard():
>           ##Code to retrieve the value
>           user_right1=True
>           return dict(user_right1=user_right1)
>
>  
>
> in my *layout *page - *sbadmin2_layout.html -  Remember this is the 
> layout page *
>
> {{if patchmanRight==True:}}
> <li>.....
> --
> --  Show few modules else not
> </li>
> {{pass}}
>
> What could be done to fix this issue as it will keep on giving me this 
> error for every other navigation in the application unless it is 
> dashboard.html ? 
>
> Thanks! 
> Rahul D.
>
>
>
>
> On Tuesday, June 5, 2018 at 7:21:41 PM UTC+5:30, Anthony wrote:
> On Tuesday, June 5, 2018 at 7:34:38 AM UTC-4, Rahul wrote:
> Hi A
>
>>
>>> ll,
>>>         I am visiting this group after a long time. I have a question 
>>> perhaps a simple one  - I want to check for user rights for my application 
>>> and I want to code it in plugin layout  (any_layout_installed.html ) file. 
>>> I am trying to verify parameters passed to this file. I can pass session 
>>> variables and check for the rights however one drawback is that if I change 
>>> the value from say True to False, it does not refresh this for the session 
>>> variable. I must restart the browser to get rid of this previously 
>>> initialized session variable. So I want to know if there is away to do this 
>>> with some local variables  (pass local variables) and if these could be 
>>> called in the view (*plugin_layouts\layouts\<any_plugin_layout.html>*)
>>>
>>> for example in layout view - 
>>> {{if user_right1==True:}}
>>>
>>>  <HTML CODE TO SHOW THE SECTION ELSE NOT >
>>> {{pass}}
>>>
>>>
>>>
>>> The question is where (in which function in the controller ) do I 
>>> specify this value *user_right1* to use it in 
>>> *plugin_layouts\layouts\<any_plugin_layout.html>* ?? I hope I am clear 
>>> with my question.
>>>
>>
>> The variable user_right1 must either be defined in a model file or 
>> returned in the dictionary by the controller:
>>
>> def myfunction():
>>     ...
>>     return dict(user_right1=True, ...)
>>
>> 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to