On Monday, March 20, 2017 at 9:38:00 AM UTC-4, paul...@gmail.com wrote:
>
> Howdy. I have a task with web2py. This is my first experience. My 
> background is in Flask/Django. Here are a few quick questions:
>
> 1. I have an image in the a database. The model is defined like this: 
>
> Field('Image', "upload", requires=[ 
> IS_NOT_EMPTY()], autodelete=True, uploadfolder='uploads/', notnull=False, 
> label=T('Images'), 
> represent=lambda x, row: x and A('%s' % 
> (db.package.Images.retrieve(x)[0]), 
> _href=URL( 
> 'default', 'template/viewer.html', args=x), 
> _target="_blank", 
> _title=T("Open Image"), 
> _class='file-reference') 
> or ''),
>
> Can someone explain what this does conceptually? 
> db.package.Images.retrieve(x)[0]
>

The .store and .retrieve methods are explained here: 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#More-on-uploads.

When a file is stored, it is renamed, and its original name is encoded in 
the new name. The .retrieve() method returns a tuple, including the 
original name (decoded from the new name) and the open file stream itself. 
So., .retrieve(x)[0] is simply the original file name.

Note, the above code would likely generate an exception, because the actual 
field name is "Image", but the code refers to db.package.Images (note 
"Images" rather than "Image").

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