[Zope3-Users] save file to filesystem

2008-02-27 Thread k b
hello,
i'm attempting to learn zope3, beginning with grok. i''ve managed to get
most of the functionality i need, but don't have a complete understanding of
the interworkings of the system. essentially i'm writing a small app that i
use to control mpd (music player deamon) by way of libmpdclient.py.

currently i'm held back by the inability to upload a file to the filesystem.
i understand that ZOBD.blob completes this funcionality. zope.conf is
configured for blobs, but i fail to understand how to save a blob to the
directory configured there. i've read this:
http://tarekziade.wordpress.com/2007/09/14/to-blob-or-not-to-blob/
i've also looked the doc tests that come with z3c.blobfile. i've also found
information which states that zope.file (not zope.app.file) includes blob
funcionality. nonetheless, i've not been able to make it work. hopefully a
bit of code will help clarify the problem. the following works to save a
file to the zodb. i've tried many variations using blobfile and extfile
without success.

import grok
from zope import interface, schema
from megrok.form.fields import File

class IAudio(interface.Interface):
name = schema.TextLine(title=uName)
data = File(title=uAudio file)


class Audio(grok.Model):
interface.implements(IAudio)

def __init__(self, data, name):
  self.data = data
  self.name = name

class AddAudio(grok.AddForm):
grok.context(uploadtest)
form_fields = grok.AutoFields(Audio)

@grok.action('Add audio')
def add(self, **data):
obj = Audio(**data)
self.context[name] = obj
self.redirect(self.url(self.context))


this setup works to save a file to the zodb.
i've tried changing from megrok.form.fields import File to from
z3c.blobfile import File. i've also tried having IAudio subclass IBlobFile,
to no avail.
in the archives of this list i've also found some references to z3c.extfile
and have tried subclassing it instead. can anyone give specific pointers on
how to modify the above code so that it stores files on the filesystem?

thanks for any and all help,
kevin
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] save file to filesystem

2008-02-27 Thread Martijn Faassen
Hi there,

I haven't had much experience with blobs yet (I hope to start working
with this in the near future).

From my reading of the blobfile docs, I think the File object
defined in it is *not* a schema field, such as the
one you use from megrok.form. These things are different things
altogether, even though they're both called file.
blobfile tries to make its File object compatible with the file object
stored by the zope.app.file package. This is the
implementation of an object that *stores* the file data, not the field
that appears in the schema. From my cursory browsing
through z3c.blobfile it doesn't implement such a file field.

So, concept involved:

* the File field in a schema

* the actual object that ends up on your Python object, a File object
(altogether different, just same name). This stores your
  file in some way, by default in the ZODB, but now we want to use the
blob version.

* the widget that displays this field in a form.

I think unfortunately some custom work seems necessary to hook this
up. megrok.form uses collective.namedfile for its file upload widget.
Collective namedfile defines a field and widget for the file. Glancing
at it, I don't think it's much code, but we do need:

* a special 'BlobFile' field that stores the information in the ZODB

* probably a BlobNamedFile storage object that subclasses from the
existing blobfile File object, but adds a filename (which the named
file bits need)

* 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.

I expect that all this is probably a bit intimidating for you to get
done yourself, but luckily there's help. I think this might make for a
good addition to megrok.form, which we're interested in expanding. I
think it makes sense for us to add blob file support in there along
the lines of what I sketched out above. Please join us in grok-dev and
we'll try to work it out with you. To start this off, I've cc-ed it
into that list as well as the developer of megrok.form.

Regards,

Martijn
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] save file to filesystem

2008-02-27 Thread kev
 
thanks for the quick responce martijn. ive gotta better grasp of the
concepts now, but yea the implementation makes  my head spin a bit. i´ll
begin to investigate using what you´ve laid out here as  a guide. i´ve
joined the grok-dev list. 

El jue, 28-02-2008 a las 00:19 +0100, Martijn Faassen escribió:
 Hi there,
 
 I haven't had much experience with blobs yet (I hope to start working
 with this in the near future).
 
 From my reading of the blobfile docs, I think the File object
 defined in it is *not* a schema field, such as the
 one you use from megrok.form. These things are different things
 altogether, even though they're both called file.
 blobfile tries to make its File object compatible with the file object
 stored by the zope.app.file package. This is the
 implementation of an object that *stores* the file data, not the field
 that appears in the schema. From my cursory browsing
 through z3c.blobfile it doesn't implement such a file field.
 
 So, concept involved:
 
 * the File field in a schema
 
 * the actual object that ends up on your Python object, a File object
 (altogether different, just same name). This stores your
   file in some way, by default in the ZODB, but now we want to use the
 blob version.
 
 * the widget that displays this field in a form.
 
 I think unfortunately some custom work seems necessary to hook this
 up. megrok.form uses collective.namedfile for its file upload widget.
 Collective namedfile defines a field and widget for the file. Glancing
 at it, I don't think it's much code, but we do need:
 
 * a special 'BlobFile' field that stores the information in the ZODB
 
 * probably a BlobNamedFile storage object that subclasses from the
 existing blobfile File object, but adds a filename (which the named
 file bits need)
 
 * 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.
 
 I expect that all this is probably a bit intimidating for you to get
 done yourself, but luckily there's help. I think this might make for a
 good addition to megrok.form, which we're interested in expanding. I
 think it makes sense for us to add blob file support in there along
 the lines of what I sketched out above. Please join us in grok-dev and
 we'll try to work it out with you. To start this off, I've cc-ed it
 into that list as well as the developer of megrok.form.
 
 Regards,
 
 Martijn

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users