[Grok-dev] Re: save file to filesystem

Martijn Faassen faassen at startifact.com
Thu Feb 28 07:43:54 EST 2008


Hey,

On Thu, Feb 28, 2008 at 5:38 AM, kev <mictlan.tecutli.0 at gmail.com> wrote:
> ok so trying to understand how to set this up
>
>
>  > * a special 'BlobFile' field that stores the information in the ZODB
>
>  ¿seems like a simple addition to megrok.form.fields? something like:
>
>  from z3c.blobfile.interfaces import IBlobFile
>
>   class BlobFile(schema.File):
>     interface.implements(IBlobFile)

I don't think we can reuse the IBlobFile interface here. We are
talking about the interface marking
the *field*, and we can't reuse the interface marking the file for this.

I'm also not sure whether we should be subclassing schema.File for
this, though not sure we shouldn't
either. What does namedfile do? We should follow its pattern.

>  > * probably a BlobNamedFile storage object that subclasses from the
>  > existing blobfile File object, but adds a filename (which the named
>  > file bits need)
>
>  i took a look in collective.namedfile and saw how NamedFile is set up in
>  file.py. copying that to blobfile.py and renaming a few things leaves me
>  with this:
>
>  from zope.interface import implements
>
> from z3c.blobfile import File
>  from interfaces import INamedFile
>
>  class BlobNamedFile(File):
>     implements(INamedFile)
>
>     def __init__(self, data='', contentType='', filename=None):
>         File.__init__(self, data, contentType)
>         self.filename=filename

Yes, that looks right to me.

>
>  > * a new BlobNamedFileWidget widget  that subclasses NamedFileWidget
>  > and creates a BlobNamedFile instead of a
>  >   NamedFile. With a few tweaks to collective.namedfile we could make
>  > this widget subclass really minimal, just introducing
>  >   a file object factory in it or looking up some utility or adapter to
>  > configure it, but even without that, it's going to be short.
>
>  the widget part is a bit more intimidating :)

It's basically a subclass of the widget in namedfile, that overrides
the one method that
instantiates the NamedFile object and instead you instantiate your new
BlobNamedFile object.
You also need to hook the widget up to the field, along the lines of
what happens in BlobNamedFile.

Thinking about it, it might make the most sense to get the namedfile
package adjusted for blob support
first. You need to discuss that with the creators - there might be
dependency issues where the ZODB that
namedfile is usually used with is not modern enough to support blobs.
If you need help discussing things with the
people who maintain that package please let me know (just cc me in on
any email discussion).

After it's integrated, we can do a very easy inclusion in megrok.form.

I hope Dirceu also joins in the thread and helps you!

Regards,

Martijn


More information about the Grok-dev mailing list