Re: [Zope3-Users] Error when calling addform

2007-02-18 Thread Florian Lindner
Am Dienstag, 13. Februar 2007 12:04 schrieb Stephan Richter:
 On Monday 12 February 2007 15:56, David Johnson wrote:
  Many people have offered approaches.  I find the simplest and  
  cleanest approach for declaring interfaces is as follows:

 The cleanest way, in my opinion, is just not to use the addform directive
 altogether. zope.formlib is the wildly accepted successor.

Ok, I've done it now if the formlib.
Do I really have to create and set all fields manually?

class BlogCommentAddForm(form.AddForm):
form_fields = form.Fields(IBlogComment)

def create(self, data):
comment = BlogComment()
comment.name = data[name]
comment.email = data[email]
comment.content = data[content]
return comment

If I just omit create is complains that the function must be implemented. Can 
this be done easier?

Thanks,

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


Re: [Zope3-Users] Error when calling addform

2007-02-18 Thread Dominique Lederer
Florian Lindner schrieb:
 Am Dienstag, 13. Februar 2007 12:04 schrieb Stephan Richter:
 On Monday 12 February 2007 15:56, David Johnson wrote:
 Many people have offered approaches.  I find the simplest and  
 cleanest approach for declaring interfaces is as follows:
 The cleanest way, in my opinion, is just not to use the addform directive
 altogether. zope.formlib is the wildly accepted successor.
 
 Ok, I've done it now if the formlib.
 Do I really have to create and set all fields manually?
 
 class BlogCommentAddForm(form.AddForm):
 form_fields = form.Fields(IBlogComment)
 
 def create(self, data):
 comment = BlogComment()
 comment.name = data[name]
 comment.email = data[email]
 comment.content = data[content]
 return comment
 
 If I just omit create is complains that the function must be implemented. Can 
 this be done easier?

you can do this with

def create(self, data):
comment = BlogComment()
form.applyChanges(comment, self.form_fields, data)
return comment

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


Re: [Zope3-Users] Error when calling addform

2007-02-15 Thread Marius Gedminas
On Tue, Feb 13, 2007 at 07:15:11PM +0100, David Johnson wrote:
 I thought  zope.formlib was more complex.

That may be true, under the hood, but it is certainly simpler to use.

I never fully understood how to use (and extend) forms generated by ZCML
addform/editform directives.

 As I understand you must  
 create custom browser classes,

True.

 and page templates.

That is not necessary.

 Then you must  
 register those with a page or view ZCML browser directive, each of  
 which is more complicated than the addform.

The initial complexity may be a little higher, but you get a flexible
solution that scales well when you need to change something.

Form directives may work well for trivial cases, but they don't scale
when you need to change things.

 My point is that if there is something new here, I would like to  
 learn. :)

You will not regret learning zope.formlib.

Marius Gedminas
-- 
Linux was made by foreign terrorists to take money from true US companies
like Microsoft. -Some AOL'er.
To this end we dedicate ourselves... -Don
(From the sig of Don [EMAIL PROTECTED])


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


Re: [Zope3-Users] Error when calling addform

2007-02-13 Thread David Johnson
Many people have offered approaches.  I find the simplest and  
cleanest approach for declaring interfaces is as follows:


class IContactList(IContainer):
  contains('.IContact')

class IContact(Interface):
  ...schema fields...

class IContactContained(IContained):
  containers(IContactList)

Basically, the schema used in your addform CANNOT include IContained.



On Feb 11, 2007, at 7:26 PM, Florian Lindner wrote:


Hello,
I have an addform registered:

addform
label=Add Blog Comment
name=AddBlogComment.html
schema=..interfaces.IBlogComment
content_factory=..blog.BlogComment
permission=Blog.AddComment
/

addMenuItem
class=..blog.BlogComment
title=Blog Comment
description=A Blog Comment
permission=Blog.AddComment
view=AddBlogComment.html
/


class IBlogComment(IContained):
containers(IBlogEntry)

name = TextLine(
title = uYour name,
description = uYour name or nickname,
default = uGuest,
required = True)


email = TextLine(
title = uE-Mail,
required = False)

content = Text(
title = uBlog comment content,
default = u,
required = True)


class BlogComment(Contained):
 A comment to a Blog entry. 
implements(IBlogComment)

name = u
email = u
content = u


but when I call the addform resp. click on the addMenuItem  I get  
an system

error:

2007-02-11T19:19:46 ERROR SiteError
http://localhost:8080/xgm/Blog/2007_02_10_erster_post/+/ 
AddBlogComment.html

Traceback (most recent call last):
  File /home/florian/Zope3/src/zope/publisher/publish.py, line  
130, in

publish
obj = request.traverse(obj)
  File /home/florian/Zope3/src/zope/publisher/browser.py, line  
511, in

traverse
ob = super(BrowserRequest, self).traverse(obj)
  File /home/florian/Zope3/src/zope/publisher/http.py, line 447,  
in traverse

ob = super(HTTPRequest, self).traverse(obj)
  File /home/florian/Zope3/src/zope/publisher/base.py, line 263,  
in traverse

obj = publication.traverseName(self, obj, entry_name)
  File /home/florian/Zope3/src/zope/app/publication/ 
publicationtraverse.py,

line 55, in traverseName
ob2 = ob.publishTraverse(request, nm)
  File /home/florian/Zope3/src/zope/app/publisher/browser/ 
viewmeta.py, line

271, in publishTraverse
view = queryMultiAdapter((self, request), name=name)
  File /home/florian/Zope3/src/zope/component/_api.py, line 114, in
queryMultiAdapter
return sitemanager.queryMultiAdapter(objects, interface, name,  
default)
  File /home/florian/Zope3/src/zope/component/registry.py, line  
206, in

queryMultiAdapter
return self.adapters.queryMultiAdapter(
  File /home/florian/Zope3/src/zope/interface/adapter.py, line  
482, in

queryMultiAdapter
result = factory(*objects)
  File /home/florian/Zope3/src/zope/app/form/browser/editview.py,  
line 62,

in __init__
self._setUpWidgets()
  File /home/florian/Zope3/src/zope/app/form/browser/add.py, line  
48, in

_setUpWidgets
setUpWidgets(self, self.schema, IInputWidget,  
names=self.fieldNames)
  File /home/florian/Zope3/src/zope/app/form/utility.py, line  
153, in

setUpWidgets
context=context)
  File /home/florian/Zope3/src/zope/app/form/utility.py, line 97, in
setUpWidget
widget = _createWidget(context, field, viewType, view.request)
  File /home/florian/Zope3/src/zope/app/form/utility.py, line 65, in
_createWidget
return zapi.getMultiAdapter((field, request), viewType)
  File /home/florian/Zope3/src/zope/component/_api.py, line 103, in
getMultiAdapter
raise ComponentLookupError(objects, interface, name)
ComponentLookupError: ((zope.schema._bootstrapfields.Field object at
0x9e95b2c, zope.publisher.browser.BrowserRequest instance
URL=http://localhost:8080/xgm/Blog/2007_02_10_erster_post/+/ 
AddBlogComment.html),

InterfaceClass zope.app.form.interfaces.IInputWidget, u'')



 what do I have misconfigured here?

Thanks,

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



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


Re: [Zope3-Users] Error when calling addform

2007-02-13 Thread Benji York

Stephan Richter wrote:

On Monday 12 February 2007 15:56, David Johnson wrote:
Many people have offered approaches.  I find the simplest and  
cleanest approach for declaring interfaces is as follows:


The cleanest way, in my opinion, is just not to use the addform directive 
altogether. zope.formlib is the wildly accepted successor.


I know that my acceptance of formlib is certainly wild.
--
Benji York
Senior Software Engineer
Zope Corporation
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Error when calling addform

2007-02-13 Thread David Johnson
I thought  zope.formlib was more complex.  As I understand you must  
create custom browser classes, and page templates.  Then you must  
register those with a page or view ZCML browser directive, each of  
which is more complicated than the addform.


My point is that if there is something new here, I would like to  
learn. :)



On Feb 13, 2007, at 12:04 PM, Stephan Richter wrote:


On Monday 12 February 2007 15:56, David Johnson wrote:

Many people have offered approaches.  I find the simplest and
cleanest approach for declaring interfaces is as follows:


The cleanest way, in my opinion, is just not to use the addform  
directive

altogether. zope.formlib is the wildly accepted successor.

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] Error when calling addform

2007-02-11 Thread Tom Dossis
Florian Lindner wrote:
 Hello,
 I have an addform registered:
 
 addform
 label=Add Blog Comment
 name=AddBlogComment.html
 schema=..interfaces.IBlogComment
 content_factory=..blog.BlogComment
 permission=Blog.AddComment
 /
 
 addMenuItem
 class=..blog.BlogComment
 title=Blog Comment
 description=A Blog Comment
 permission=Blog.AddComment
 view=AddBlogComment.html
 /
 
 
 class IBlogComment(IContained):
 containers(IBlogEntry)
 
 name = TextLine(
 title = uYour name,
 description = uYour name or nickname,
 default = uGuest,
 required = True)
 
 
 email = TextLine(
 title = uE-Mail,
 required = False)
 
 content = Text(
 title = uBlog comment content,
 default = u,
 required = True)
 
 
 class BlogComment(Contained):
  A comment to a Blog entry. 
 implements(IBlogComment)
 
 name = u
 email = u
 content = u
 
 
 but when I call the addform resp. click on the addMenuItem  I get an system 
 error:
 
 2007-02-11T19:19:46 ERROR SiteError 
 http://localhost:8080/xgm/Blog/2007_02_10_erster_post/+/AddBlogComment.html
...
 ComponentLookupError: ((zope.schema._bootstrapfields.Field object at 
 0x9e95b2c, zope.publisher.browser.BrowserRequest instance 
 URL=http://localhost:8080/xgm/Blog/2007_02_10_erster_post/+/AddBlogComment.html),
  
 InterfaceClass zope.app.form.interfaces.IInputWidget, u'')
 
 
 
  what do I have misconfigured here?

IBlogComment has picked up the fields __parent__ and __name__ from
IContained.

Try explicitly specifying the IBlogComment fields in the addform
directive: set_before_add, e.g.

  set_before_add=name email content


If you add an __init__ constructor to BlogComment then you could use the
fields or keyword_arguments instead, e.g.

  fields=name email content

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


Re: [Zope3-Users] Error when calling addform

2007-02-11 Thread Marius Gedminas
On Sun, Feb 11, 2007 at 07:26:21PM +0100, Florian Lindner wrote:
 Hello,
 I have an addform registered:
 
 addform
 label=Add Blog Comment
 name=AddBlogComment.html
 schema=..interfaces.IBlogComment
 content_factory=..blog.BlogComment
 permission=Blog.AddComment
 /

 
 class IBlogComment(IContained):
 containers(IBlogEntry)
 
 name = TextLine(
 title = uYour name,
 description = uYour name or nickname,
 default = uGuest,
 required = True)
 
 email = TextLine(
 title = uE-Mail,
 required = False)
 
 content = Text(
 title = uBlog comment content,
 default = u,
 required = True)
 
 
 but when I call the addform resp. click on the addMenuItem  I get an system 
 error:
...
 ComponentLookupError: ((zope.schema._bootstrapfields.Field object at 
 0x9e95b2c, zope.publisher.browser.BrowserRequest instance 
 URL=http://localhost:8080/xgm/Blog/2007_02_10_erster_post/+/AddBlogComment.html),
  
 InterfaceClass zope.app.form.interfaces.IInputWidget, u'')
 
  what do I have misconfigured here?

You have

containers(IBlogEntry)

in your schema.  That's equivalent to

__parent__ = Field(constraint=ContainerTypesConstraint(IBlogEntry))

Your add form is trying to find a widget suitable for Field, but there
isn't one.

Note also that you will inherit

__name__ = TextLine(...)

from IContained.  I do not think you want __name__ and __parent__ in
your add form.  To skip those fields you'll have to explicitly enumerate
all the other fields:

addform
...
schema=..interfaces.IBlogComment
fields=name email content
...
/

Alternative solution: split the schema into a separate interface,
specify it in the addform directive, then define an interface for your
content object that inherits IContained, your schema, and specifies the
container constraint.  It's probably not worth bothering, given that you
need to enumerate only three fields.

An even better solution: learn zope.formlib and use it.  Much better
than the bare standard forms.  Here's a very short example of an add
form with zope.formlib: http://mg.pov.lt/blog/formlib-adding

I'll copy a part of it here:

class FruitAdd(form.AddForm):

form_fields = form.Fields(IFruit)

Now if you want to omit some fields from the schema, like in your
example above, you can do

class BlogCommentAdd(form.AddForm):

form_fields = form.Fields(IBlogComment).omit('__name__',
 '__parent__')

Marius Gedminas
-- 
* philiKON wonders what niemeyer is committing :)
*** benji_york is now known as benji
benji murder?
-- #zope3-dev


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