[Zope-CMF] .csv into lots of Content objects
seb bacon
seb@jamkit.com
Mon, 2 Jul 2001 19:04:55 +0100
* Chris Withers <chrisw@nipltd.com> [010702 17:44]:
> Hi,
>
> I'm interested in how people would go about turning each row of a .csv file into
> a piece of CMF content via FTP or WebDAV?
> Has anyone done this?
> If not, would it be possible with the hookable PUT stuff?
> Where should I look to start playing?
I'd create a new type called "ExcelImport", and register its extension
in the content_types_registry (or whatever it's called...).
Then every time you WebDAV a csv file, its PUT method is called. In
that, I'd do something like:
body = StringIO(REQUEST.get('BODY', '')
for line in body.readlines():
fields = string.split(line, ",")
type, id, title, description = fields[0],fields[1],fields[2],fields[3]
somefolder.invokeFactory(type,id,title=title,description=description)
...etc...
>
> Also, and I guess this one is harder, how can I make, say, a folder of CMF
> content objects appear as a single .csv file to a WebDAV or FTP client?
>
when you try to grab something via WebDAV, its manage_FTPget method is
called. you'd have to iterate over each object in the folder, flatten
it out, return the csv file. the only thing I'm not sure about is if
you can do this with folders. I've never looked at how the webdav
implementation manages collections. For all I know, they might be the
same as vanilla content - if you're lucky.
Look at CMFDefault/Document.py for more ideas.
> For extra mega bonus points (looking at Seb here ;-), how could I do the same
> with rows from an Excel spreadsheet?
If you're on a win box, just use the excel com interface, I'm sure you
can either iterate over rows or save as csv from it. If you're
on nix, use xlHtml to convert it first, then do some fancy regexps.
But I have to know - why oh why have you got content in an excel
spreadsheet? :-)
Do you have a catalogue of items that can be redeemed for points? I
need a new kettle.
seb