Index: in/waeup.sirp/trunk/src/waeup/sirp/widgets/passportwidget.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/widgets/passportwidget.py	(revision 6555)
+++ 	(revision )
@@ -1,185 +1,0 @@
-##
-## resultswidget.py
-## Login : <uli@pu.smp.net>
-## Started on  Tue Jul 20 02:04:30 2010 Uli Fouquet
-## $Id$
-## 
-## Copyright (C) 2010 Uli Fouquet
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
-## 
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-## 
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##
-"""A widget to display IObject instances in forms.
-"""
-import grok
-import os
-import zope.file.file
-import zope.file.upload
-from zope.app.file.interfaces import IImage
-from zope.browserpage import ViewPageTemplateFile
-from zope.formlib.interfaces import IDisplayWidget
-from zope.formlib.objectwidget import ObjectWidget, ObjectWidgetView
-from zope.formlib.widget import renderElement, DisplayWidget
-from zope.formlib.widgets import FileWidget
-from zope.formlib.utility import setUpWidgets
-from zope.interface import implements, implementsOnly
-from zope.schema import getFieldNamesInOrder
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.traversing.browser import absoluteURL
-
-
-class WAeUPPassportWidgetView(ObjectWidgetView):
-    template = ViewPageTemplateFile('objectwidget.pt')
-
-class PassportImage(object):
-    grok.implements(IImage)
-
-    _data = None
-    _file = None
-    contenttype = 'image/jpeg'
-    path = None
-    
-    def __init__(self, data=None, fileobj=None, contenttype='image/jpeg'):
-        #print "INIT"
-        self.contenttype = contenttype
-        self._data = data
-        if data is not None:
-            self._data = None
-            return
-        if fileobj is not None:
-            self._file = fileobj
-            return
-        self.path = os.path.join(
-            os.path.dirname(os.path.dirname(__file__)),
-            'browser', 'static', 'placeholder_m.jpg')
-
-    @property
-    def contentType(self):
-        return self.contenttype
-
-    @property
-    def data(self):
-        print "DATA"
-        if self._file is not None:
-            print "FILE"
-            return self._file.open().read()
-        if self.path:
-            print "PATH"
-            return open(self.path, 'rb').read()
-        print "NONE"
-        return self._data
-
-    def getSize(self):
-        if self._file is not None:
-            return self._file.size
-        if self.path is not None:
-            info = os.stat(self.path)
-            return info.st_size
-        return len(self._data)
-
-class PassportWidget(FileWidget):
-
-    def __call__(self):
-        result = super(PassportWidget, self).__call__()
-        url = absoluteURL(self.context.context, self.request) + '/passport.jpg'
-        image = renderElement(
-            'img',
-            src=url,
-            width='100px',
-            )
-        #import pdb; pdb.set_trace()
-        return '%s <br />%s' % (image, result)
-
-    def _toFieldValue(self, input):
-        if input is None or input == '':
-            return self.context.missing_value
-        if getattr(input, 'filename', False):
-            contenttype = input.headers.get('Content-Type')
-            file_ = zope.file.file.File()
-            zope.file.upload.updateBlob(file_, input)
-            return PassportImage(fileobj=file_, contenttype=contenttype)
-            return file_
-        return self.context.missing_value
-        try:
-            seek = input.seek
-            read = input.read
-        except AttributeError, e:
-            raise ConversionError(_('Form input is not a file object'), e)
-        else:
-            seek(0)
-            data = read()
-            if data or getattr(input, 'filename', ''):
-                return PassportImage(data)
-                return data
-            else:
-                return self.context.missing_value
-
-    def no__init__(self, context, request, factory, **kw):
-        super(PassportWidget, self).__init__(context, request)
-
-        # define view that renders the widget
-        self.view = self._getView(request)
-
-        # factory used to create content that this widget (field)
-        # represents
-        self.factory = factory
-
-        # handle foo_widget specs being passed in
-        self.names = getFieldNamesInOrder(self.context.schema)
-        for k, v in kw.items():
-            if k.endswith('_widget'):
-                setattr(self, k, v)
-
-        # set up my subwidgets
-        self._setUpWidgets()
-
-    def nosubwidgets(self):
-        result = [self.getSubWidget(name) for name in self.names]
-        return result
-
-    def no_setUpWidgets(self):
-        return self._setUpEditWidgets()
-
-    def no_getView(self, request):
-        return WAeUPObjectWidgetView(self, request)
-
-#class WAeUPObjectDisplayWidget(WAeUPObjectWidget):
-#
-#    implementsOnly(IDisplayWidget)
-#
-#    def _setUpDisplayWidgets(self):
-#        # subwidgets need a new name
-#        setUpWidgets(self, self.context.schema, IDisplayWidget,
-#                         prefix=self.name, names=self.names,
-#                         context=self.context)
-#
-#    def _setUpWidgets(self):
-#        return self._setUpDisplayWidgets()
-
-class PassportDisplayWidget(DisplayWidget):
-
-    grok.implements(IDisplayWidget)
-    
-    def __call__(self):
-        #result = super(PassportDisplayWidget, self).__call__()
-        url = absoluteURL(self.context, self.request) + '/passport.jpg'
-        #url = absoluteURL(self.context.context, self.request) + '/passport.jpg'
-        image = renderElement(
-            'img',
-            src=url,
-            width='100px',
-            )
-        #import pdb; pdb.set_trace()
-        #print "IMAGE: ", image
-        return '<br />%s' % (image,)# result)
-        return '%s <br />%s' % (image, result)
Index: in/waeup.sirp/trunk/src/waeup/sirp/widgets/tests/test_passportwidget.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/widgets/tests/test_passportwidget.py	(revision 6555)
+++ 	(revision )
@@ -1,235 +1,0 @@
-"""Tests for objectwidget.
-"""
-import doctest
-import unittest
-import sys
-from zope.app.file.interfaces import IImage
-from zope.component import testing
-from zope.interface import Interface, implements
-from zope.interface.verify import verifyClass
-from zope.publisher.browser import TestRequest
-from zope.schema import Object, TextLine
-from zope.schema.interfaces import ITextLine
-from zope.traversing.adapters import DefaultTraversable
-from zope.traversing.interfaces import ITraversable
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-from zope.component import provideAdapter
-
-from zope.formlib.interfaces import (
-    IInputWidget, IDisplayWidget,MissingInputError)
-from zope.formlib.widgets import TextWidget, DisplayWidget
-from zope.formlib.tests.test_browserwidget import BrowserWidgetTest
-from zope.formlib.interfaces import IWidgetInputErrorView
-
-from waeup.sirp.widgets.objectwidget import WAeUPObjectWidget as ObjectWidget
-from waeup.sirp.widgets.objectwidget import (
-    WAeUPObjectDisplayWidget as ObjectDisplayWidget)
-
-from waeup.sirp.widgets.passportwidget import (
-    PassportWidget, PassportDisplayWidget, PassportImage,
-    )
-
-
-class ITestContact(Interface):
-    name = TextLine()
-    email = TextLine()
-    
-class TestContact(object):
-    implements(ITestContact)
-
-class TestImage(object):
-    implements(IImage)
-
-class ITestContent(Interface):
-    passport = Object(
-        title = u'Passport Photograph',
-        required = True,
-        schema = IImage)
-
-    foo = Object(
-        ITestContact, 
-        title = u'Foo Title',
-        description = u'',
-        )
-    
-class PassportWidgetInputErrorView(object):
-    implements(IWidgetInputErrorView)
-
-    def __init__(self, error, request):
-        self.error = error
-        self.request = request
-
-    def snippet(self):
-        return repr(self.error)
-
-class PassportWidgetTest(BrowserWidgetTest):
-    """Documents and tests the passort image widget.
-
-        >>> from zope.interface.verify import verifyClass
-        >>> verifyClass(IInputWidget, ObjectWidget)
-        True
-    """
-
-    _FieldFactory = Object
-    def _WidgetFactory(self, context, request, **kw):
-        kw.update({'factory': TestContact})
-        return ObjectWidget(context, request, **kw)
-
-    def setUpContent(self, desc=u'', title=u'Foo Title'):
-        provideAdapter(TextWidget, (ITextLine, IDefaultBrowserLayer),
-                       IInputWidget)
-        
-        class TestObject(object):
-            implements(ITestContent)
-
-        self.content = TestObject()
-        self.field = ITestContent['foo']
-        self.request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl')
-        self.request.form['field.foo'] = u'Foo Value'
-        self._widget = self._WidgetFactory(self.field, self.request)
-
-    def setUp(self):
-        super(PassportWidgetTest, self).setUp()
-        self.field = Object(ITestContact, __name__=u'foo')
-        provideAdapter(TextWidget,
-                       (ITextLine, IDefaultBrowserLayer),
-                       IInputWidget)
-
-    def test_applyChanges(self):
-        self.request.form['field.foo.name'] = u'Foo Name'
-        self.request.form['field.foo.email'] = u'foo@foo.test'
-        widget = self._WidgetFactory(self.field, self.request)
-
-        self.assertEqual(widget.applyChanges(self.content), True)
-        self.assertEqual(hasattr(self.content, 'foo'), True)
-        self.assertEqual(isinstance(self.content.foo, TestContact), True)
-        self.assertEqual(self.content.foo.name, u'Foo Name')
-        self.assertEqual(self.content.foo.email, u'foo@foo.test')
-
-    def test_error(self):
-        provideAdapter(
-            PassportWidgetInputErrorView,
-            (MissingInputError, TestRequest),
-            IWidgetInputErrorView)
-
-        widget = self._WidgetFactory(self.field, self.request)
-        self.assertRaises(MissingInputError, widget.getInputValue)
-        error_html = widget.error()
-        if sys.version_info < (2, 5):
-            self.failUnless("email: <zope.formlib.interfaces.Mis" 
-                             in error_html)
-            self.failUnless("name: <zope.formlib.interfaces.Miss"
-                             in error_html)
-        else:
-            self.failUnless(
-                "email: MissingInputError(u'field.foo.email', u'', None)"
-                in error_html)
-            self.failUnless(
-                "name: MissingInputError(u'field.foo.name', u'', None)"
-                in error_html)
-
-    def test_applyChangesNoChange(self):
-        self.content.foo = TestContact()
-        self.content.foo.name = u'Foo Name'
-        self.content.foo.email = u'foo@foo.test'
-
-        self.request.form['field.foo.name'] = u'Foo Name'
-        self.request.form['field.foo.email'] = u'foo@foo.test'
-        widget = self._WidgetFactory(self.field, self.request)
-        widget.setRenderedValue(self.content.foo)
-
-        self.assertEqual(widget.applyChanges(self.content), False)
-        self.assertEqual(hasattr(self.content, 'foo'), True)
-        self.assertEqual(isinstance(self.content.foo, TestContact), True)
-        self.assertEqual(self.content.foo.name, u'Foo Name')
-        self.assertEqual(self.content.foo.email, u'foo@foo.test')
-
-    def test_respect_custom_widgets(self):
-        # We can use our own subwidgets when creating ObjectWidgets
-        class CustomTextWidget(TextWidget):
-            pass
-
-        # We create a custom widget for the `name` field of ITestContact
-        name_widget = CustomTextWidget(ITestContact['name'], self.request)
-
-        # Custom widgets are passed by <fieldname>_widget keyword:
-        widget = self._WidgetFactory(self.field, self.request,
-                                     name_widget=name_widget)
-        widget1, widget2 = widget.subwidgets()
-        self.assertTrue(widget1 is name_widget)
-        
-        
-class PassportDisplayWidgetTest(BrowserWidgetTest):
-    """Documents and tests the display variant of passport widget.
-
-        >>> from zope.interface.verify import verifyClass
-        >>> verifyClass(IDisplayWidget, ObjectDisplayWidget)
-        True
-
-   """
-    _FieldFactory = Object
-    def _WidgetFactory(self, context, request, **kw):
-        #kw.update({'factory': TestContact})
-        #kw.update({'factory': TestImage})
-        return PassportDisplayWidget(context, request, **kw)
-        #return ObjectDisplayWidget(context, request, **kw)
-
-    def setUpContent(self, desc=u'', title=u'Foo Title'):
-        provideAdapter(TextWidget, (ITextLine, IDefaultBrowserLayer),
-                       IInputWidget)
-        provideAdapter(DisplayWidget, (ITextLine, IDefaultBrowserLayer),
-                       IDisplayWidget)
-        # The widget must be traversable. We register the default
-        # adapter that can turn nearly any object into an ITraversable.
-        provideAdapter(DefaultTraversable, (None,), ITraversable)
-        
-        class TestObject(object):
-            implements(ITestContent)
-
-        self.content = PassportImage() #TestImage()
-        #self.content.name = u'Foo Name'
-        #self.content.email = u'foo@foo.test'
-        self.field = ITestContent['passport']
-        self.request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl')
-        self.request.form['field.passport'] = u'Foo Value'
-        self._widget = self._WidgetFactory(self.field, self.request)
-
-    def setUp(self):
-        super(PassportDisplayWidgetTest, self).setUp()
-        self.field = Object(ITestContact, __name__=u'passport')
-        #provideAdapter(TextWidget,
-        #               (ITextLine, IDefaultBrowserLayer),
-        #               IInputWidget)
-        #provideAdapter(DisplayWidget,
-        #               (ITextLine, IDefaultBrowserLayer),
-        #               IDisplayWidget)
-
-        
-    def test_interfaces(self):
-        from zope.interface.verify import DoesNotImplement
-        self.assertTrue(IDisplayWidget.providedBy(self._widget))
-        self.assertFalse(IInputWidget.providedBy(self._widget))
-        self.assertTrue(verifyClass(IDisplayWidget, ObjectDisplayWidget))
-
-    def DISABLEDtest_render(self):
-        widget = PassportDisplayWidget(
-            self.field, self.request) #, TestImage)
-        widget.setRenderedValue(self.content)
-
-        check_list = [
-            '<td', 'class=', 'row',
-            'Foo Name',
-            '</td>', '<td', 'class=', 'row',
-            'foo@foo.test',
-            '</td>']
-        self.verifyResult(widget(), check_list, inorder=True)    
-
-def test_suite():
-    return unittest.TestSuite((
-        #unittest.makeSuite(PassportWidgetTest),
-        unittest.makeSuite(PassportDisplayWidgetTest),
-        doctest.DocTestSuite(),
-        ))
-
-if __name__=='__main__':
-    unittest.main(defaultTest='test_suite')
