I am using LocalFS to refer to a directory structure like this: folder1 | folder11 There are image (.jpg) files in both folders. I have two questions about this: 1)Folders names are directly related to string fields in a MySQL database which use spaces between words (eg New York), but folders names don't use spaces (eg NewYork). How can I skip spaces from database fields to make them refer to these folders (eg New York --> NewYork)? 2)Using LocalFS, can I do something like <dtml- var "localfsObject['<dtml-var par1>'].['<dtml-var par11>'], where par1 and par11 are folder names (after skiping spaces)? Regards, Rogerio Atem ------------------------------------------- E-mail enviado pelo servidor do CEFETCampos
Rogerio Atem de Carvalho writes:
1)Folders names are directly related to string fields in a MySQL database which use spaces between words (eg New York), but folders names don't use spaces (eg NewYork). How can I skip spaces from database fields to make them refer to these folders (eg New York --> NewYork)?
Here's what I'm using to transform spaces to '_': path = string.translate(path, string.maketrans(' ', '_')) This is only invoked on file upload. If you're doing it a lot, I'd just create the translation table once and stash it in a member variable. If you're doing this from DTML, the following untested code should be a clue: <dtml-let table="_.string.maketrans(' ', '_')"> ... <dtml-let fname="_.string.translate(name, table)"> ... </dtml-let> ... </dtml-let> Better check that maketrans and translate are in the version of the string module available for DTML...
2)Using LocalFS, can I do something like <dtml- var "localfsObject['<dtml-var par1>'].['<dtml-var par11>'], where par1 and par11 are folder names (after skiping spaces)?
It'd be more like: <dtml-var "localfsObject[par1][par11]"> I.E. inside the quotes you're in Python and par1 and par11 are assumed to be variable names. The quotes would mean you were looking for folders named "<dtml-var par1>", etc. Note that you neither need nor want a '.' between the subscripts.
1)Folders names are directly related to string fields in a MySQL database which use spaces between words (eg New York), but folders names don't use spaces (eg NewYork). How can I skip spaces from database fields to make them refer to these folders (eg New York --> NewYork)?
_.string.replace(folder_name, " ", "") This will return a string with the spaces removed, if 'folder_name' is a string variable containing the folder name (with spaces).
2)Using LocalFS, can I do something like <dtml- var "localfsObject['<dtml-var par1>'].['<dtml-var par11>'], where par1 and par11 are folder names (after skiping spaces)?
You can't nest dtml like this. Just use: <dtml-var "localfsObject[par1][par11]"> (also note that I removed the . between [par1] and [par11]) See http://www.zope.org/Members/jfarr/HowTo/DTML_with_LocalFS for more information on using DTML with Local File System objects. --jfarr
participants (3)
-
Dan L. Pierson -
Jonothan Farr -
Rogerio Atem de Carvalho