Re: [Zope3-Users] stuck with zope.schema.List and subwidget

2005-08-26 Thread Adam Groszer
Hello Christian,

I'm having almost the same problems with a 'simple'
OrderedMultiSelectWidget. Look for the subject
"problems with " on the list [Zope3-dev].

Saturday, August 27, 2005, 1:01:04 AM, you wrote:

> Hi!

> Did anyone ever test or succeed using the subwidget-directive of
> zope.app.form.browser.sequencewidget.SequenceWidget?

> Following the lines of zope/app/form/browser/widgets.txt a widget for a
> list of objects would be defined by something like this:


> author_w = CustomWidgetFactory(ObjectWidget, Person)

> class ArticleEditView(EditView):
> authors_widget = CustomWidgetFactory(SequenceWidget, subwidget=author_w)


> Instead of SequenceWidget I tried ListSequenceWidget, too.

> But I allways get the error-message:
> __init__() takes at least 4 arguments (3 given)

> I'm really stuck. Which further argument should I pass to
> CustomWidgetFactory? CustomWidgetFactory--if I get it right--calls the
> constructur of SequenceWidget that complains about the missing argument.
> (self, context, field, request, subwidget=None) is the list of arguments
> of __init__
> Especially: What should I pass as 'field'-argument?
> I played around with the source code and changed the list to (self,
> context, request, subwidget=None) and--WOW-- it presents a form yust as
> I want it. [Now I allways get a new (schema-)error, which I can't track:
> "Es gab *1* Eingabefehler."]

> The constructor of SequenceWidget reads like this:

> def __init__(self, context, field, request, subwidget=None):
> super(SequenceWidget, self).__init__(context, request)
> self.subwidget = subwidget

> I really don't understand what is done with 'field'. Where is it passed
> to?


> Can someone give me a hint?


> Kind regards,
> Christian


> PS. I found a way to define a widget for objects of objects yesterday,
> see zope3-users. The example above is taken from there.
> ___
> Zope3-users mailing list
> Zope3-users@zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users



-- 
Best regards,
 Adammailto:[EMAIL PROTECTED]
--
Quote of the day:
Birth: The first and direst of all disasters.

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


Re: [Zope3-Users] stuck with zope.schema.List and subwidget

2005-08-28 Thread Stephan Richter
On Friday 26 August 2005 19:01, Christian Lueck wrote:
> author_w = CustomWidgetFactory(ObjectWidget, Person)
>
> class ArticleEditView(EditView):
>     authors_widget = CustomWidgetFactory(SequenceWidget,
> subwidget=author_w)
>
>
> Instead of SequenceWidget I tried ListSequenceWidget, too.
>
> But I allways get the error-message:
> __init__() takes at least 4 arguments (3 given)

The problem, I think (actually I just checked, so I know ;-), is that 
CustomWidgetFactory was not designed to work well with advanced widgets, i.e. 
widgets that have more constructor arguments beyond the field and the 
request.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] stuck with zope.schema.List and subwidget

2005-08-29 Thread Christian Lueck
Stephan Richter schrieb:
> 
> The problem, I think (actually I just checked, so I know ;-), is that 
> CustomWidgetFactory was not designed to work well with advanced widgets, i.e. 
> widgets that have more constructor arguments beyond the field and the 
> request.
> 
Hm, so you think :-) I should rather use CustomSequenceWidgetFactory?
No, that doesn't work ether. (Still the same error, still don't know what to 
pass to 'fields'.)

But I got an other solution/suggestion: Redefine the constructor of
zope.app.form.browser.sequencewidget.SequenceWidget in new classes, say
CustomSequenceWidget and CustomListSequenceWidget. They work together
with CustomWidgetFactory (pretty) well:

from zope.app.form.browser.sequencewidget import SequenceWidget, 
ListSequenceWidget

class CustomSequenceWidget(SequenceWidget):
def __init__(self, context, request, subwidget=None):
super(SequenceWidget, self).__init__(context, request)
self.subwidget = subwidget

class CustomListSequenceWidget(ListSequenceWidget):
def __init__(self, context, request, subwidget=None):
super(SequenceWidget, self).__init__(context, request)
self.subwidget = subwidget


And then defining tuple/sequence-widgets like this:

tuplex_widget = CustomWidgetFactory(CustomSequenceWidget, subwidget=objectx_w)

listx_widget = CustomWidgetFactory(CustomListSequenceWidget, 
subwidget=objectx_w)


This way I got the poll-example of zope/app/form/browser/widget.txt
working, which did not work out of the box. Besides this bigger change there had
to be added some minor changes, espesially in configure.zcml

I suggest to add the two above classes to
zope/app/form/browser/sequencewidget.py

Regards
Christian


The poll-example:

interfaces.py


from zope.interface import Interface
from zope.schema import Object, Tuple, TextLine
from zope.schema.interfaces import ITextLine
from zope.i18n import MessageIDFactory

_ = MessageIDFactory("poll")

class IPollOption(Interface):

label = TextLine(
title=u'Label',
min_length=1)

description = TextLine(
title=u'Description',
min_length=1)

class IPoll(Interface):

options = Tuple(
title=u'Options',
value_type=Object(schema=IPollOption,
  title=u'Poll Option'))

def getResponse(option):
"get the response for an option"

def choose(option):
'user chooses an option'


poll.py


from persistent import Persistent
from interfaces import IPoll, IPollOption
from zope.interface import implements, classImplements

class PollOption(Persistent, object):
implements(IPollOption)

class Poll(Persistent, object):
implements(IPoll)

def getResponse(self, option):
return self._responses[option]

def choose(self, option):
self._responses[option] += 1
self._p_changed = 1

def get_options(self):
return self._options

def set_options(self, options):
self._options = options
self._responses = {}
for option in self._options:
self._responses[option.label] = 0

options = property(get_options, set_options, None, 'fiddle options')


browser.py


from zope.app.form.browser.editview import EditView
from zope.app.form.browser.add import AddView
from zope.app.form import CustomWidgetFactory
from zope.app.form.browser import SequenceWidget, ObjectWidget

from interfaces import IPoll, IPollOption
from poll import Poll, PollOption

class PollVoteView:
__used_for__ = IPoll

def choose(self, option):
self.context.choose(option)
self.request.response.redirect('.')

class CustomSequenceWidget(SequenceWidget):

def __init__(self, context, request, subwidget=None):
super(SequenceWidget, self).__init__(context, request)

self.subwidget = subwidget


ow = CustomWidgetFactory(ObjectWidget, PollOption)
sw = CustomWidgetFactory(CustomSequenceWidget, subwidget=ow)

class PollEditView(EditView):
__used_for__ = IPoll

options_widget = sw

class PollAddView(AddView):
__used_for__ = IPoll

options_widget = sw


configure.zcml







  

  

  

  





  








  

  













vote.zpt



Poll voting



Poll voting



Option
Option









results.zpt



Poll results


Poll results

OptionResultsDescription



Option
Result