Hello all, I'd love you to give me your opinion and some help about what follows. I just downloaded Zope to my machine (MacOs X!!) and I'm an old style mac user. Now, I promised I'd have tried to realize a small solution for monday morning. I want a Zcatalogue to index some objects on the base of a property. This property is the name of the file BUT the extension, for example: code2.html property: code2 code88.html property: code88 and so on. That's because I want Zope to search for files whose code CONTAINS a given string. As far as I can tell, the standard machinery that comes with Zcatalogue searches on the files names ONLY with exact corrispondence, since the type of the file name property is ... well I don't remember. The point is I thought to give each file with a property of the right type so Zope could search adhering to my wishes. Am I right? Now these files are really a lot. Some users upload them to an ftp folder and I should have a script that adds the property to each file when it lands in my folder (AND fill it properly). How do I do this? I looked at the Folder API but I didn't find a way to detect a file arrival. Should I use a Zclass instead? And how? In the meantime I keep editing those files manually but I admit this makes me feel quite dummy. thanks so much for ANY hint Bye Catonano
On Fri, Dec 13, 2002 at 05:11:16PM +0100, catonano wrote:
This property is the name of the file BUT the extension, for example:
code2.html property: code2 code88.html property: code88
add an index of type FieldIndex to your ZCatalog, name it by the name you want to search on, e.g. itemcode create a Script (Python) object named itemcode in your root which contains only : return context.getId().split('.')[-1] Go to the Advanced tag of your ZCatalog and click Update Go to the Find tab of your ZCatalog and search for all objects you want to add to the ZCatalog use the ZCatalog like this : result = context["Catalog"].searchResults(itemcode='blah') will find all objects which itemcode's value is 'blah' this is compltely untested but should work bye, Jerome Alet
On Fri, Dec 13, 2002 at 05:31:38PM +0100, Jerome Alet wrote:
create a Script (Python) object named itemcode in your root which contains only :
return context.getId().split('.')[-1]
that'll break the first time somebody uploads a file named "foo.bar.baz.html" ... instead try (untested): import string name = context.getId() splitname = id.split('.') splitname.pop() # get rid of the extension name = string.join(splitname, '.') # reassemble the string return name -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
On Fri, Dec 13, 2002 at 10:14:47AM -0800, Paul Winkler wrote:
On Fri, Dec 13, 2002 at 05:31:38PM +0100, Jerome Alet wrote:
create a Script (Python) object named itemcode in your root which contains only :
return context.getId().split('.')[-1]
that'll break the first time somebody uploads a file named "foo.bar.baz.html" ...
My fingers typed exactly the opposite of what I wanted to type it seems. I wanted to keep all but the last one, of course, so this is probably something more like this one : return '.'.join(context.getId().split('.')[:-1]) And I said this was completely untested IIRC. BTW this one is also completely untested hth Jerome Alet
On Fri, Dec 13, 2002 at 08:19:56PM +0100, Jerome Alet wrote:
I wanted to keep all but the last one, of course, so this is probably something more like this one :
return '.'.join(context.getId().split('.')[:-1])
... which does in one line what I did in 4. TMTOWTDI lives :) --PW -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
Paul and Jerome, Venerdì, 13 Dic 2002, alle 21:32 Europe/Rome, Paul Winkler ha scritto:
On Fri, Dec 13, 2002 at 08:19:56PM +0100, Jerome Alet wrote:
I wanted to keep all but the last one, of course, so this is probably something more like this one :
return '.'.join(context.getId().split('.')[:-1])
... which does in one line what I did in 4. TMTOWTDI lives :)
thanks a lot to the both of you. I didn't realize I could place such a script to make it inherited by sub-branches even if I HAD read about acquisition !! Thanks! Now may I ask for a bit more help? i'm so near the solution! Well I used the 4 lines script because I was a bit intimidated by the 1 line one. Still, reading it a little better, I understood it uses a string as a stack with the dot as a distinction point ('my.String.htm'.split(.) should give back a stack made like this: htm String my right? ) I was disappointed when I saw I haven't got the string API reference in Zope but I have to connect to the Internet to read it. Too bad I don't always have a net connection at my disposal. Back to us, I had to do a small modification to the 4 lines script; it was import string name = context.getId() splitname = id.split('.') // where's 'id' defined? splitname.pop() # get rid of the extension name = string.join(splitname, '.') # reassemble the string return name but it had to be import string name = context.getId() splitname = NAME.split('.') //(the right reference is 'name' not id ;) )) splitname.pop() # get rid of the extension name = string.join(splitname, '.') # reassemble the string return name Ok, now, I'm a good pupil !! ;-) The one thing I can't still do is search files in my catalog whose names CONTAINS a substring. I can search files names taht start with or end with a substring (catalogue.searchResults({'code': '*' + aString} and catalogue.searchResults({'code': aString + '*') No more. How do I search general substrings (the common 'contains' relation?) Thanks so much, anyway Bye Catonano
On Sun, Dec 15, 2002 at 08:06:59PM +0100, catonano wrote:
Still, reading it a little better, I understood it uses a string as a stack with the dot as a distinction point ('my.String.htm'.split(.)
oops, don't forget the quotes around the dot.
should give back a stack made like this:
htm String my
right?
You can think of it that way... technically, some_string.split() returns a list: ['my', 'String', 'htm'] Lists can be treated like stacks in some respects; they have a pop() method which removes and returns the last element in the list.
I was disappointed when I saw I haven't got the string API reference in Zope but I have to connect to the Internet to read it. Too bad I don't always have a net connection at my disposal.
you should grab the python documentation from python.org, very good to have around.
Back to us, I had to do a small modification to the 4 lines script; it was
import string name = context.getId() splitname = id.split('.') // where's 'id' defined?
oops, my mistake... should have been splitname = name.split('.')
The one thing I can't still do is search files in my catalog whose names CONTAINS a substring.
don't really know, sorry. -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
participants (3)
-
catonano -
Jerome Alet -
Paul Winkler