{ "info": { "author": "Souheil Chelfouh", "author_email": "trollfot@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Other Audience", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "===================\ndolmen.widget.image\n===================\n\n`dolmen.widget.image` is a thin layer above `dolmen.widget.file`\nproviding a widget suitable to fields implementing IImageField. It\nadds, thanks to `dolmen.thumbnailer` a preview of the uploaded image\nin both input and display mode.\n\nExample\n=======\n\nWe are going to develop here a small example, to demonstrate the use\nof `dolmen.widget.image`. First, we instanciate our test model and add\nan image field to the object::\n\n >>> from persistent import Persistent\n\n >>> class Mammoth(Persistent):\n ... pass\n\n >>> import dolmen.file\n >>> import grokcore.component as grok\n >>> from zope.interface import Interface, alsoProvides\n >>> from zope.schema.fieldproperty import FieldProperty\n\n >>> class IMammothId(Interface):\n ... \"\"\"Even mammoths need an ID card\"\"\"\n ... picture = dolmen.file.ImageField(title=u'Luggages')\n\n >>> manfred = Mammoth()\n >>> manfred.picture = None\n >>> alsoProvides(manfred, IMammothId)\n\nThe picture is now set on our Mammoth. We create a form to try and\nedit the picture field::\n\n >>> from megrok.z3cform.base import EditForm\n\n >>> class EditMammoth(EditForm):\n ... grok.name('edit')\n ... grok.context(IMammothId)\n\n >>> grok.testing.grok_component('edit', EditMammoth)\n True\n\nWe persist our Mammoth to get a located mammoth with an URL::\n\n >>> from zope.component.hooks import getSite\n >>> root = getSite()\n >>> root['manfred'] = manfred\n >>> manfred = root['manfred']\n\nWe can call the edit form on our persisted object::\n\n >>> from zope.component import getMultiAdapter\n >>> from zope.publisher.browser import TestRequest\n \n >>> request = TestRequest()\n\n >>> form = getMultiAdapter((manfred, request), name='edit')\n >>> form.updateWidgets() \n >>> print form.widgets['picture'].render() \n
\n\nNow, let's try with a fake value::\n \n >>> manfred.picture = \"some fake image\"\n >>> form = getMultiAdapter((manfred, request), name='edit')\n >>> form.updateWidgets() \n\n >>> print form.widgets['picture'].render() \n \n