[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-28 Thread Lamps902
Thanks to both of you guys! After a much needed rest, I got it working with 
a solution comparable to what you guys specified/described. 

Anthony - I noticed the book's section on using the *host* and 
*scheme*parameters for URL(), but was a bit thrown off - is there a way to use 
URL() to point to a page (i.e. google.com) outside of your site (whatever 
tinkering I did with URL(), it was always appending or prepending some 
elements of my site's address to the URL pointing to another page)?

-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-28 Thread Anthony
The URL() function is primarily intended for generating web2py URLs, not 
external URLs. It will always add a controller and function (if none are 
specified, it will use the controller and function of the current request).

Anthony

On Thursday, March 28, 2013 10:36:15 AM UTC-4, Lamps902 wrote:

 Thanks to both of you guys! After a much needed rest, I got it working 
 with a solution comparable to what you guys specified/described. 

 Anthony - I noticed the book's section on using the *host* and 
 *scheme*parameters for URL(), but was a bit thrown off - is there a way to 
 use 
 URL() to point to a page (i.e. google.com) outside of your site (whatever 
 tinkering I did with URL(), it was always appending or prepending some 
 elements of my site's address to the URL pointing to another page)?


-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-28 Thread Lamps902
Got it. Thank you!

On Thursday, March 28, 2013 9:41:03 AM UTC-5, Anthony wrote:

 The URL() function is primarily intended for generating web2py URLs, not 
 external URLs. It will always add a controller and function (if none are 
 specified, it will use the controller and function of the current request).

 Anthony

 On Thursday, March 28, 2013 10:36:15 AM UTC-4, Lamps902 wrote:

 Thanks to both of you guys! After a much needed rest, I got it working 
 with a solution comparable to what you guys specified/described. 

 Anthony - I noticed the book's section on using the *host* and 
 *scheme*parameters for URL(), but was a bit thrown off - is there a way to 
 use 
 URL() to point to a page (i.e. google.com) outside of your site 
 (whatever tinkering I did with URL(), it was always appending or prepending 
 some elements of my site's address to the URL pointing to another page)?



-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-27 Thread Niphlod
so, you have an url (i.e. a string) that needs to return an image.
you should have a controller that, when that URI is matched, returns the 
image after increasing its number_visited value seems pretty standard 
to me

On Wednesday, March 27, 2013 7:15:12 PM UTC+1, Lamps902 wrote:

 Let's say you have an SQL grid generated from a db with field *my_url*, 
 which stores the value of an absolute URL, and has a representation defined 
 in this way: 

 db.my_db.my_url.represent = lambda the_url, row: A(generate_link_image(), 
 _href=the_url, _target='_blank')

 What would be a good way to modify the above code so that when the link is 
 clicked, some field in *my_db* (for example, *number_visited*, 
 corresponding to the number of times the url has been clicked) is updated? 
 I'm not sure you can use _href=URL(...) with absolute links, and other 
 variants I've tried end up updating every record referenced in the table 
 rather than just the one that the user clicks. Thanks.


-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-27 Thread Lamps902
In the case that I'm dealing with, the image is incidental to the problem. 
But let's say there is an image, and a relative URL (i.e. file download); 
you can do something like this:

db.my_db.file.represent = lambda x,y: \
A(generate_image(y.file),
_href=URL(args=[my_db/download, x],vars = 
dict(action=update_download_number, id=y.id)))

Can't do this for absolute links. Maybe I'm misunderstanding your 
suggestion, but the same image generator function will be invoked for all 
of the rows in the table, so if I use that, all the rows end up being 
updated, as opposed to the one which should be updated. So basically, I 
think it comes down to how to go about creating a function that's invoked 
when an absolute link is clicked, and passing an identifier related 
specifically to that link to the function.

On Wednesday, March 27, 2013 2:41:16 PM UTC-5, Niphlod wrote:

 so, you have an url (i.e. a string) that needs to return an image.
 you should have a controller that, when that URI is matched, returns the 
 image after increasing its number_visited value seems pretty standard 
 to me

 On Wednesday, March 27, 2013 7:15:12 PM UTC+1, Lamps902 wrote:

 Let's say you have an SQL grid generated from a db with field *my_url*, 
 which stores the value of an absolute URL, and has a representation defined 
 in this way: 

 db.my_db.my_url.represent = lambda the_url, row: A(generate_link_image(), 
 _href=the_url, _target='_blank')

 What would be a good way to modify the above code so that when the link 
 is clicked, some field in *my_db* (for example, *number_visited*, 
 corresponding to the number of times the url has been clicked) is updated? 
 I'm not sure you can use _href=URL(...) with absolute links, and other 
 variants I've tried end up updating every record referenced in the table 
 rather than just the one that the user clicks. Thanks.



-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-27 Thread Niphlod
uhm... I didn't quite understand, but it seems that you want different 
things to happen when printing the url and when accessing the url.
Why is hard separating printing a link logic from the accessing the 
link one ?
It's a common construct, i.e. on one page 

click here to like the image

and on another page

-
image
-
you liked this image

the second page, either accessed as a relative or as an absolute url, makes 
no difference from the web2py standpoint.

If I totally missed your requirements, can you give a plain english 
explanation on what you're trying to accomplish ?
PS: I'm on gtalk for the next hour if this requires a long digression :P

-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-27 Thread Lamps902
Thanks, Niphlod. It may require some digression/elaboration, so do you mind 
if I get in touch with you about this tomorrow? Hopefully, after I get some 
rest, I'll be able to articulate the issue a bit better...

On Wednesday, March 27, 2013 4:08:46 PM UTC-5, Niphlod wrote:

 uhm... I didn't quite understand, but it seems that you want different 
 things to happen when printing the url and when accessing the url.
 Why is hard separating printing a link logic from the accessing the 
 link one ?
 It's a common construct, i.e. on one page 

 click here to like the image

 and on another page

 -
 image
 -
 you liked this image

 the second page, either accessed as a relative or as an absolute url, 
 makes no difference from the web2py standpoint.

 If I totally missed your requirements, can you give a plain english 
 explanation on what you're trying to accomplish ?
 PS: I'm on gtalk for the next hour if this requires a long digression :P


-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-27 Thread Anthony
What do you mean by absolute vs. relative URLs in this case, and why does 
that matter (i.e., show examples)? The URL function can generate absolute 
URLs http://web2py.com/books/default/chapter/29/04#Absolute-urls by 
specifying the scheme and host arguments, but it's not clear why you would 
need that in this case. Note, if your URL includes args or vars used to 
identify a specific record, then you can access the record identifier via 
request.args or request.vars within the function called by the URL.

Anthony

On Wednesday, March 27, 2013 4:59:02 PM UTC-4, Lamps902 wrote:

 In the case that I'm dealing with, the image is incidental to the problem. 
 But let's say there is an image, and a relative URL (i.e. file download); 
 you can do something like this:

 db.my_db.file.represent = lambda x,y: \
 A(generate_image(y.file),
 _href=URL(args=[my_db/download, x],vars = 
 dict(action=update_download_number, id=y.id)))

 Can't do this for absolute links. Maybe I'm misunderstanding your 
 suggestion, but the same image generator function will be invoked for all 
 of the rows in the table, so if I use that, all the rows end up being 
 updated, as opposed to the one which should be updated. So basically, I 
 think it comes down to how to go about creating a function that's invoked 
 when an absolute link is clicked, and passing an identifier related 
 specifically to that link to the function.

 On Wednesday, March 27, 2013 2:41:16 PM UTC-5, Niphlod wrote:

 so, you have an url (i.e. a string) that needs to return an image.
 you should have a controller that, when that URI is matched, returns the 
 image after increasing its number_visited value seems pretty standard 
 to me

 On Wednesday, March 27, 2013 7:15:12 PM UTC+1, Lamps902 wrote:

 Let's say you have an SQL grid generated from a db with field *my_url*, 
 which stores the value of an absolute URL, and has a representation defined 
 in this way: 

 db.my_db.my_url.represent = lambda the_url, row: 
 A(generate_link_image(), _href=the_url, _target='_blank')

 What would be a good way to modify the above code so that when the link 
 is clicked, some field in *my_db* (for example, *number_visited*, 
 corresponding to the number of times the url has been clicked) is updated? 
 I'm not sure you can use _href=URL(...) with absolute links, and other 
 variants I've tried end up updating every record referenced in the table 
 rather than just the one that the user clicks. Thanks.



-- 

--- 
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/groups/opt_out.




[web2py] Re: using a representation of an absolute URL to update a db?

2013-03-27 Thread Anthony
Specifically, maybe something like this:

db.define_table('image',
Field('file', 'upload', represent=lambda v, r: A(generate_image(v),
  _href=URL('default', 'download', args=v, vars=dict(action=
'update_download_number', id=r.id,
Field('downloads', 'integer', default=0, writable=False))

def download():
if request.vars.action == 'update_download_number':
db.image(request.vars.id).update_record(downloads=db.image.downloads 
+ 1)
return response.download(request, db)

Anthony

On Wednesday, March 27, 2013 5:46:28 PM UTC-4, Anthony wrote:

 What do you mean by absolute vs. relative URLs in this case, and why does 
 that matter (i.e., show examples)? The URL function can generate absolute 
 URLs http://web2py.com/books/default/chapter/29/04#Absolute-urls by 
 specifying the scheme and host arguments, but it's not clear why you would 
 need that in this case. Note, if your URL includes args or vars used to 
 identify a specific record, then you can access the record identifier via 
 request.args or request.vars within the function called by the URL.

 Anthony

 On Wednesday, March 27, 2013 4:59:02 PM UTC-4, Lamps902 wrote:

 In the case that I'm dealing with, the image is incidental to the 
 problem. But let's say there is an image, and a relative URL (i.e. file 
 download); you can do something like this:

 db.my_db.file.represent = lambda x,y: \
 A(generate_image(y.file),
 _href=URL(args=[my_db/download, x],vars = 
 dict(action=update_download_number, id=y.id)))

 Can't do this for absolute links. Maybe I'm misunderstanding your 
 suggestion, but the same image generator function will be invoked for all 
 of the rows in the table, so if I use that, all the rows end up being 
 updated, as opposed to the one which should be updated. So basically, I 
 think it comes down to how to go about creating a function that's invoked 
 when an absolute link is clicked, and passing an identifier related 
 specifically to that link to the function.

 On Wednesday, March 27, 2013 2:41:16 PM UTC-5, Niphlod wrote:

 so, you have an url (i.e. a string) that needs to return an image.
 you should have a controller that, when that URI is matched, returns the 
 image after increasing its number_visited value seems pretty standard 
 to me

 On Wednesday, March 27, 2013 7:15:12 PM UTC+1, Lamps902 wrote:

 Let's say you have an SQL grid generated from a db with field *my_url*, 
 which stores the value of an absolute URL, and has a representation 
 defined 
 in this way: 

 db.my_db.my_url.represent = lambda the_url, row: 
 A(generate_link_image(), _href=the_url, _target='_blank')

 What would be a good way to modify the above code so that when the link 
 is clicked, some field in *my_db* (for example, *number_visited*, 
 corresponding to the number of times the url has been clicked) is updated? 
 I'm not sure you can use _href=URL(...) with absolute links, and other 
 variants I've tried end up updating every record referenced in the table 
 rather than just the one that the user clicks. Thanks.



-- 

--- 
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/groups/opt_out.