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.