What's the best practise to store images / files in blob storage

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

What's the best practise to store images / files in blob storage

lzdych
This post has NOT been accepted by the mailing list yet.
Hi Grokkers,

I'm trying to create simple model with a file and an image attribute stored in the blob storage but found it almost impossible with current Grok release (1.4) and available extensions.

mebrok.form is broken, dolmen.blob (widgets) are using different forms framework which I didn't make work easily and I also failed with plone.namedfile due to dependency conflicts and a few others packages which I found are outdated at all.

I was so surprised that I can't make it work even without blob storage easily - it seems a lot have been changed so even using zope.app.file isn't the way.

So my question is if I missed something and there is an working example or if the best way is for example to update megrok.form or if there is even anybody having working code for file/image field stored in the zodb or bettter in blobs.

Kind Regards

Lukas
Reply | Threaded
Open this post in threaded view
|

Re: What's the best practise to store images / files in blob storage

lzdych
This post has NOT been accepted by the mailing list yet.
Finally I sort it out with a great help on IRC from trollfot and goschtl (thx a lot guys!).

In my almost vanila environment created by grokproject (grok 1.4) I just had to:

1. pin these versions (IMPORTANT):
megrok.chameleon = 0.5.2
Chameleon = 1.2.13

2. add the following deps into setup.py (install_requires):
'zeam.form.base',
zeam.form.ztk
dolmen.blob
dolmen.widget.file
dolmen.widget.image

3. rewrite my form from grokcore.formlib based into zeam.form.ztk based
as you can see in the following example:

from zeam.form import ztk
from zope.schema import TextLine
from zope.interface import Interface
from dolmen.file import FileField, ImageField, FileProperty
from dolmen.blob import BlobProperty


class IDoc(Interface):
    """"""
    title = TextLine(title=u'Document title')
    attachment = FileField(title=u'Attachment', required=False)
    preview = ImageField(title=u'Preview', required=False)
    binary_file = FileField(title=u"Binary file", required=False)
    binary_image = FileField(title=u"Binary image", required=False)


class Doc(grok.Model):
    grok.implements(IDoc)

    attachment = FileProperty(IDoc['attachment'])
    preview = FileProperty(IDoc['preview'])
    binary_file = BlobProperty(IDoc['binary_file'])
    binary_image = BlobProperty(IDoc['binary_image'])

    def __init__(self, title='', attachment=None, preview=None,
        binary_file=None, binary_image=None):
        self.title = title
        self.attachment = attachment
        self.preview = preview
        self.binary_file = binary_file
        self.binary_image = binary_image


class AddDoc(ztk.Form):
    grok.name('add-doc')
    grok.title('Add doc')
    grok.context(interfaces.IAppRoot)
    ignoreContent = True
    fields = ztk.Fields(IDoc)
    actions = ztk.Actions(ztk.AddAction(u"Add", Doc))
    label = "Add doc form"


class EditDoc(ztk.Form):
    grok.name('edit')
    grok.title('Edit doc')
    grok.context(IDoc)
    ignoreContent = False
    fields = ztk.Fields(IDoc)
    actions = ztk.Actions(ztk.EditAction(u"Save"))
    label = "Edit doc form"


class ViewDoc(grok.View):
    grok.name('index')
    grok.context(Doc)

    def render(self):
        return '<html><body><p>I\'m your new document: %s' \
            '</p><a href="%s">Edit</a>' % (self.context.title, self.url(self.context) + '/edit')