[web2py] Re: how to save controller vars into a field?

2017-09-07 Thread Anthony
On Thursday, September 7, 2017 at 3:34:08 AM UTC-4, pbreit wrote:
>
> Are you trying to store the URL of the page the user is currently on?
>
> I think you just want to store the URL. There's not just one variable as 
> far as I could tell. So you might have to build it like:
>
> bookmark = "%s://%s%s" % (request.env.wsgi_url_scheme, request.env.
> remote_addr, request.env.request_uri)
>

Note, you probably want request.env.web2py_original_uri rather than 
request.env.request_uri (the former is the actual incoming requested URL, 
whereas the latter is the full web2py URL after rewrite).

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.


[web2py] Re: how to save controller vars into a field?

2017-09-07 Thread Alex Glaros
It worked!  Thanks Pbreit

on my desktop, it skiped the port part of the address 8000 so had to add to 
use w2p URL format:  bookmark = request.get_vars.bookmark.rsplit('/', 1)[-1]

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


[web2py] Re: how to save controller vars into a field?

2017-09-07 Thread Anthony

>
> VIEW THAT CAPTURES CURRENT PAGE VARS
>
> {{import json}} <-- side question: Why "import json" only works in 
> view and not controller?
>

Not sure what you mean. The json module is part of the standard library and 
can be imported from anywhere.
 

> {{=A('Add this page or manage bookmarks', _href=URL('default', 
> 'manage_menu_favorites', vars=dict(specificURL = request.url, 
> saved_menu_vars =  json.dumps(request.get_vars))), _class='btn btn-warning 
> btn-lg', 
> _style='font-size:120%;float:left;padding:10px;margin:10px;text-transform: 
> capitalize;')}}
>

At this point, what exactly is in request.get_vars (note, request.get_vars 
contains the variables in the query string of the URL, so this would be the 
query string of the current page)? Why do you want users to go to a new 
page whose URL includes a JSON representation of the query string from the 
previous page?

If users have a set of saved bookmarks, it does not make sense to keep all 
the bookmarks in the query string of the URL (i.e., request.get_vars). It 
makes more sense to store the bookmarks in the db and load them into the 
session as needed.

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.


[web2py] Re: how to save controller vars into a field?

2017-09-07 Thread pbreit
Are you trying to store the URL of the page the user is currently on?

I think you just want to store the URL. There's not just one variable as 
far as I could tell. So you might have to build it like:

bookmark = "%s://%s%s" % (request.env.wsgi_url_scheme, request.env.
remote_addr, request.env.request_uri)

Kind of ugly. I'm surprised there isn't an env variable of the current 
URL/URI.

http://www.web2py.com/books/default/chapter/29/04/the-core#request

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


[web2py] Re: how to save controller vars into a field?

2017-09-06 Thread Alex Glaros
am still having trouble making it work

What data structure type do I vars in so that user can return next day and 
have bookmarks work? Right now is stored in "string" field in a regular 
table. Tried "json" field type but Postgres rejected. Is it supposed be 
some sort of dictionary field? Field('saved_menu_vars', 'string')

VIEW THAT CAPTURES CURRENT PAGE VARS

{{import json}} <-- side question: Why "import json" only works in view 
and not controller?
{{=A('Add this page or manage bookmarks', _href=URL('default', 
'manage_menu_favorites', vars=dict(specificURL = request.url, 
saved_menu_vars =  json.dumps(request.get_vars))), _class='btn btn-warning 
btn-lg', 
_style='font-size:120%;float:left;padding:10px;margin:10px;text-transform: 
capitalize;')}}

CONTROLLER THAT SAVES VARS INTO A TABLE

justCreatedBookMark = 
db.menu_favorites.insert(menu_favorites_redirect_parms = 
json.loads(saved_menu_vars), menu_favorites_title = 
form.vars.title_of_your_bookmark, user_fk = auth.user_id)

VIEW THAT DISPLAYS BOOKMARKS

{{for r in session.menuFavoritesSet:}}
{{=A(r.menu_favorites_title, 
_href=URL(r.menu_favorites_url, 
vars=json.loads(r.menu_favorites_redirect_parms)))}}
{{pass}}

Is there a better way to test contents of saved vars?

am a little confused with: **request.get_vars  
The vars are stored in a table. How does that get them out of their field?

thanks

Alex

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


[web2py] Re: how to save controller vars into a field?

2017-09-06 Thread Leonel Câmara
One way to do it would be:

saved_menu_vars = urllib.quote(json.dumps(request.get_vars))

Then in the controller you could:

url_vars = json.loads(request.vars.saved_menu_vars)

Or you could simply:

URL('default', 'manage_menu_favorites', vars=dict(specificURL = 
request.url, **request.get_vars))

Then in the controller you assume that any vars that is not specificURL is 
one of the new favorite get vars. Which is fine if you don't use 
specificURL anywhere else. 

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