[Zope-CMF] Uploading news items with FTP

Shane Hathaway shane@digicool.com
Tue, 24 Apr 2001 10:49:04 -0400 (EDT)


On Mon, 23 Apr 2001, Jonathan Corbet wrote:

> If you look at http://cmf.zope.org/doc/user/BasicContent.txt/view, it says,
> among other things:
>
>       the CMF checks the incoming data to see if it has a piece of metadata
>       called Type. The value of this metadata property would instruct the
>       CMF to create, for instance, a NewsItem.
>
> But, as far as I can tell, that simply is not true.  A couple of content
> types (Document, NewsItem) use parseHeadersBody to grab metadata and set
> things like the title, but that is done *after* the object has been
> created.  There is nothing, currently, which looks at headers before the
> object is created.

I'm afraid our "marketing engine" has leaped ahead of us on this one.
There is initial support for parsing headers on upload, but it hasn't been
completely wired up.

> So, even though NewsItem defines a PUT_factory method, nothing ever calls
> it.
>
> I could perhaps bash out a hacky solution in PortalFolder.PUT_factory that
> would make things work.  I get a sense, though, from the code that the
> whole portal_types mechanism is intended to be used in this sort of role,
> and I haven't done anywhere near enough time staring at the code to figure
> out how I might make that happen...

PortalFolder.PUT_factory will, in the (hopefully near) future, invoke the
portal_types tool to decide what kind of upload it is.  Really the only
thing holding it up is a decision on the UI for configuring the upload
behavior.  Perhaps we should just make it a configurable script similar to
this:

if content_type=='text/plain':
    if string.lower(headers.get('Type', '')) == 'news':
        return 'News Item'
elif content_type='text/html':
    return 'Document'
return default_type(content_type)

The script, a skinnable object and probably called 'getTypeForUpload',
would be supplied the 'headers', 'content_type', and 'default_type'
parameters and would be expected to return the ID of a type.  The
default_type function would look at the mime_type parameter (which doesn't
exist yet) of each type and the first match it finds would win.

What do you think?  This solution would be easy and flexible.

Shane