Supposed for some reason our app need a full path filename (the name
itself, not necessary the content), currently we have only one way to
do that. We use a blank TEXT input field for user to type a long long
dir name such as "D:\Inside\a\deep\deep\dir\there\is\my\big
\datafile.iso". It is not user friendly.
The <INPUT type="file"...> almost does the job but it only provide the
file's basename i.e. "datafile.iso" in above example. (Perhaps I
should change my proposed name FILENAME_SELECTOR into
FULLNAME_SELECTOR.)
My above conclusion is gathered on Windows. Don't know whether Linux
or Mac has the same problem. However, the proposed FILENAME_SELECTOR
should work cross platform because it only depends on javascript.
Need an code example?
1) Put the class definition in my first post into a models/selector.py
2) write your controller:
def test():
form=FORM(FILENAME_SELECTOR(_name='fullname'),
INPUT(_type='submit'))
if form.accepts(request.vars):
return {'':request.vars.fullname} # Got a FULL path name
return {'':form}
This feature is useful if you are developing a file sharing system
based on web2py, which need to know the full path name for later
streaming. Or if you are developing a web-ui system to wrap all your
command-line tools, you also need the full path name for a os.system
(...) later.
On Apr6, 2:19am, mdipierro <[email protected]> wrote:
> Could you explain more about what it does?
>
> On Apr 5, 12:03 pm, Iceberg <[email protected]> wrote:
>
> > Hi there,
>
> > In one of my app I need to deal with local files. First I tried using
> > INPUT(_type='text',...) to ask user to manually input the full path
> > name of a specific file, such as "C:\Program Files\Blah blah\foo
> > \bar.exe". Obviously no one likes to type that long string. So I came
> > up with this. Feel free to use it if you like.
>
> > class FILENAME_SELECTOR(DIV):
> > '''
> > Usage:
> > In your controller:
> > def action(): return {'':FORM(..., FILENAME_SELECTOR
> > (_name='the_name'), ...)}
> > After submit, the file name is in request.vars.the_name (but in UTF8
> > encoding!)
> > '''
> > def __init__(self, *components, **attributes):
> > name=attributes.get('_name','filename')
> > components=[
> > INPUT(_type='file',_name='_%s'%abs(hash(self)),
> > _onchange="document.getElementById
> > ('%s').value=this.value"%name),
> > INPUT(_type='hidden',_name=name,_id=name),]
> > super(FILENAME_SELECTOR,self).__init__(*components, **attributes)
>
> > Regards,
> > Iceberg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---