[Zope3-Users] Email application form causing despair!

2006-03-14 Thread Graham Stratton
I have a seemingly simple problem.  I want to provide a web form which 
is emailed off on submission.  I'd like to do some validation before it 
is emailed off.


*snip saga involving much of formlib and browser:form*

On much reflection, I think what I probably want to do is to implement 
an 'email form' content type, which has an address to email the form to, 
and a schema, and then use the formlib machinery to produce and validate 
a form from this.  Is this the right way to go?  I can't work out how I 
can use any of the higher-level formlib code.  Will I need to render one 
widget at a time and do my own validation?  Or is there something useful 
in zope.app.form?


I guess in the longer term it would make sense to make my schema 
persistent and based on the mutable schema implementation.  How might I 
go about that?  I did play a bit with the mutable schema utility, but I 
got errors when trying to add Text and TextLine fields.   I also don't 
really understand why it's a utility anyway.  Does it offer a way to 
edit any persistent schema?


I'm feeling very lost, I hope someone can point me in the right 
direction.  Thanks for the all the support.


Regards,

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


[Zope3-Users] Re: Email application form causing despair!

2006-03-14 Thread Laurence Rowe

I think you want to do something along these lines:

from zope.formlib import form
from zope.interface import Interface

class IEmailForm(Interface):
subject = schema.TextLine(
title=u'Subject',
required=True,
)
comments = schema.TextLine(
title=u'Comments',
required=True,
)

class EmailForm(form.Form):
form_fields = form.Fields(IEmailForm)

@form.action(Email, validator='validate_input')
def handle_email_action(self, action, data):
send_mail(data['subject'], data['comments'])
self.status = u'Email Sent'

def validate_input(self, action, data):
#validation logic here
return [] # no errors

def send_mail(subject, comments):
...

Plumb it in with zcml in the normal way. No idea about mutable schemas.

Hope that helps,

Laurence

Graham Stratton wrote:
I have a seemingly simple problem.  I want to provide a web form which 
is emailed off on submission.  I'd like to do some validation before it 
is emailed off.


*snip saga involving much of formlib and browser:form*

On much reflection, I think what I probably want to do is to implement 
an 'email form' content type, which has an address to email the form to, 
and a schema, and then use the formlib machinery to produce and validate 
a form from this.  Is this the right way to go?  I can't work out how I 
can use any of the higher-level formlib code.  Will I need to render one 
widget at a time and do my own validation?  Or is there something useful 
in zope.app.form?


I guess in the longer term it would make sense to make my schema 
persistent and based on the mutable schema implementation.  How might I 
go about that?  I did play a bit with the mutable schema utility, but I 
got errors when trying to add Text and TextLine fields.   I also don't 
really understand why it's a utility anyway.  Does it offer a way to 
edit any persistent schema?


I'm feeling very lost, I hope someone can point me in the right 
direction.  Thanks for the all the support.


Regards,

Graham


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


Re: [Zope3-Users] Re: Email application form causing despair!

2006-03-14 Thread Peter Bengtsson

Good code Laurence. Thanks.
I wish we had a Cookbook to put all of these into.
Zopelabs.com sucks unfortunately.

Laurence Rowe wrote:

I think you want to do something along these lines:

from zope.formlib import form
from zope.interface import Interface

class IEmailForm(Interface):
subject = schema.TextLine(
title=u'Subject',
required=True,
)
comments = schema.TextLine(
title=u'Comments',
required=True,
)

class EmailForm(form.Form):
form_fields = form.Fields(IEmailForm)

@form.action(Email, validator='validate_input')
def handle_email_action(self, action, data):
send_mail(data['subject'], data['comments'])
self.status = u'Email Sent'

def validate_input(self, action, data):
#validation logic here
return [] # no errors

def send_mail(subject, comments):
...

Plumb it in with zcml in the normal way. No idea about mutable schemas.

Hope that helps,

Laurence

Graham Stratton wrote:
I have a seemingly simple problem.  I want to provide a web form which 
is emailed off on submission.  I'd like to do some validation before 
it is emailed off.


*snip saga involving much of formlib and browser:form*

On much reflection, I think what I probably want to do is to implement 
an 'email form' content type, which has an address to email the form 
to, and a schema, and then use the formlib machinery to produce and 
validate a form from this.  Is this the right way to go?  I can't work 
out how I can use any of the higher-level formlib code.  Will I need 
to render one widget at a time and do my own validation?  Or is there 
something useful in zope.app.form?


I guess in the longer term it would make sense to make my schema 
persistent and based on the mutable schema implementation.  How might 
I go about that?  I did play a bit with the mutable schema utility, 
but I got errors when trying to add Text and TextLine fields.   I also 
don't really understand why it's a utility anyway.  Does it offer a 
way to edit any persistent schema?


I'm feeling very lost, I hope someone can point me in the right 
direction.  Thanks for the all the support.


Regards,

Graham


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



--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Re: Email application form causing despair!

2006-03-14 Thread Michael Haubenwallner

Peter Bengtsson wrote:


Good code Laurence. Thanks.
I wish we had a Cookbook to put all of these into.
Zopelabs.com sucks unfortunately.



Hmm, i have used zopelabs.com for many years now, its a great resource 
of information.


Zope3 recipes could well be collected there (a 'Zope3' category has been 
added recently).


I never found it sucking - maybe you want to tell us your troubles ?

Michael

--
http://zope.org/Members/d2m
http://planetzope.org

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


Re: [Zope3-Users] zc.table - how does sorting work?

2006-03-14 Thread Gary Poster


On Mar 14, 2006, at 11:54 AM, Laurence Rowe wrote:


Hi there,

I'm trying to use zc.table to format the output of one of my forms.  
it seems to work ok for the unsorted formatter, but not for the  
StandalonSortFormatter. Here is the code that works with plain  
formatter:



columns = (
GetterColumn(name=u'dn', title=u'Distinguished Name',  
getter=lambda i, f: i.dn, subsort=True),
GetterColumn(name=u'displayName', title=u'Name', getter=lambda  
i, f: i.displayName, subsort=True),
GetterColumn(name=u'mail', title=u'Email Address',  
getter=lambda i, f: i.mail, subsort=True),

)
class LDAPFilterForm(form.Form):
form_fields = form.Fields(interfaces.ILDAPFilter)
@form.action(Search)
def handle_search_action(self, action, data):
search = interfaces.ILDAPSearch(self.context, None)
results = search.search(data['filter'])
self.table = table.Formatter(self.context, self.request,  
list(results), columns=columns)

return self.table()


but when I change the Formatter to StandaloneSortFormatter, I still  
get the same html output. I have tried adding in this from the  
zc.table readme:



for c in columns:
directlyProvides(c, zc.table.interfaces.ISortableColumn)


Yes, you want this.


@adapter(IRequest)
@implementer(Interface)
def dummyResource(request):
return lambda:'/@@/zc.table'
provideAdapter(dummyResource, name='zc.table')


No, you don't want this.


But then I get the following traceback:


2006-03-14T16:34:32 ERROR SiteError http://localhost:8080/@@/zc.table
Traceback (most recent call last):
  File /usr/lib/python2.4/site-packages/zope/publisher/ 
publish.py, line 135, in publish

object = request.traverse(object)
  File /usr/lib/python2.4/site-packages/zope/publisher/ 
browser.py, line 500, in traverse

ob = super(BrowserRequest, self).traverse(object)
  File /usr/lib/python2.4/site-packages/zope/publisher/http.py,  
line 451, in traverse

ob = super(HTTPRequest, self).traverse(object)
  File /usr/lib/python2.4/site-packages/zope/publisher/base.py,  
line 289, in traverse

subobject = publication.traverseName(
  File /usr/lib/python2.4/site-packages/zope/app/publication/ 
publicationtraverse.py, line 56, in traverseName

ob2 = ob.publishTraverse(request, nm)
  File /usr/lib/python2.4/site-packages/zope/app/publisher/ 
browser/resources.py, line 40, in publishTraverse

locate(resource, sm, name)
  File /usr/lib/python2.4/site-packages/zope/app/location/ 
location.py, line 72, in locate

object.__name__ = name
TypeError: func_name must be set to a string object
exceptions.TypeError:
func_name must be set to a string object
/usr/lib/python2.4/site-packages/zope/app/location/location.py(72) 
locate()

- object.__name__ = name


Using the debugger I can see:


(Pdb) name
u'zc.table


Any ideas? I'm stumped.


Not sure, but I'm guessing it is the dummy adapter.  Try again  
without it.


Also, as I wrote yesterday, we have an alternate sorting  
implementation that we ought to get in zc.table.  I sent it to  
Martijn Faassen; if you think you might look at it and maybe merge  
it, I could send it to you too. :-)


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


[Zope3-Users] Prevent Duplicate Persistency

2006-03-14 Thread Dax
For the following example (taken from Zope3 In 30 Minutes):

class IMark(Interface):
This is the book mark object.

url = TextLine(
title=uURL/Link,
description=uURL of the website,
default=uhttp://www.zope.org;,
required=True)

description = Text(
title=uDescription,
description=uDescription of the website,
default=u,
required=False)

How can I prevent Mark objects from having the same url?  So if a Mark
object exists in BookMarker with Mark.url=http://www.zope.org/;, how
can I prevent another Mark object from being added when its url is
http://www.zope.org;?

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