Default value in dict returned by the controller

35 views
Skip to first unread message

Mandar Vaze

unread,
Jul 1, 2014, 12:36:38 PM7/1/14
to web...@googlegroups.com
Hi,

I have several views which are similar, so I am using common view file using "response.view =common_view.html" rather than separate one per controller.

Out of these - 2 or 3 views are slightly different where certain parts of the page (layout.html) need to be hidden.

I tried :

return dict(msg=msg, grid=grid, hide_my_div=True)

in the view template I have :

{{if hide_my_div:}}
<script>
 $(document).ready(function(){
      $("#my_div").hide();
  });
<script>
{{pass}}

This works for the small number of views where I want to hide "my_div"
Unfortunately - this also means I need to pass "hide_my_div=False" from large number of controllers.

Is there a way to have hide_my_div=False as a default - so that I do not need to return it explicitly - and I can override only when needed (2-3 controllers)
Something like optional params with default values ?

May be the way I am handling this is wrong. Is there a better way ?

(I know that I can create separate view files for these "odd ones", but I prefer not to, since these are going to be 90% similar to common_view.html anyway)

Thanks,
-Mandar

Kiran Subbaraman

unread,
Jul 1, 2014, 1:19:23 PM7/1/14
to web...@googlegroups.com
globals().get(' hide_my_div',False) should return a False, if this is not present.
________________________________________
Kiran Subbaraman
http://subbaraman.wordpress.com/about/
--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vinicius Assef

unread,
Jul 1, 2014, 1:37:04 PM7/1/14
to web2py
I would extend your common view with an empty block to hide the
undesired part and avoid passing this argument to views.

Mandar Vaze

unread,
Jul 1, 2014, 10:35:07 PM7/1/14
to web...@googlegroups.com
Kiran,

Thanks.

I came across same solution when I searched this forum a little more (I had already searched before posting, obviously not enough)
https://groups.google.com/d/msg/web2py/b1WmPZh6PlI/nMAX-u5Des0J

-Mandar
Reply all
Reply to author
Forward
0 new messages