Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-14 Thread Christoph Zwerschke
Am 13.05.2010 18:14 schrieb Georg Balmer:
 Next I try generate the code for the form_template using WebHelpers.
 HTMLgeneration is mentioned in the future list.
 Has this something to do with what I try to do with Webhelpers?

Yes, webhelpers.html seems to do these things. Maybe it's good enough.

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-13 Thread Georg Balmer
OK I just registered on the wiki an opened my first page.

=
Formgen - First steps
=

I tried to find a way how I could work offline on my Sphinx document
an then upload the document to the wiki, but I didn't succeed.
Do you have a hint for a wiki dummy?

Regards
Georg
-

Am 13.05.2010 14:05, schrieb Christoph Zwerschke:
 Am 13.05.2010 07:42 schrieb Georg Balmer:
 What do I want? (random work in progress)

 Sounds good. Sphinx is already on our future list:
 http://wiki.w4py.org/futurework.html

 You can use the Wiki to add recipes and tutorials as drafts; they don't
 need to be polished. The Wiki and the existing docs can then be used as
 a starting basis for creating the Sphinx docs (which should be tested
 and proof-read). Anything that has become obsolete or has been taken
 over to the Sphinx docs can then be removed from the Wiki.

 -- Christoph

 --

 ___
 Webware-discuss mailing list
 Webware-discuss@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/webware-discuss



--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-13 Thread Christoph Zwerschke
Am 13.05.2010 15:39 schrieb Georg Balmer:
  I tried to find a way how I could work offline on my Sphinx document
  an then upload the document to the wiki, but I didn't succeed.
  Do you have a hint for a wiki dummy?

Since both Sphinx and Wiki use ReST format, you can just click on Edit 
- Edit this page and then post your content using cut  paste.

Btw, I just fixed the original Webware example in FormEncode which was 
broken because of the missing HTMLForms and had some more small problems 
(e.g. the Unicode issue you reported). It works nicely now with both 
Webware 1.1 and Paste WebKit.

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-12 Thread Georg Balmer
Right now I have questions like:

What's needed to get the basic example in an application?
-

. elaborate examples Fields OK-exit

. References to helpful documentation like
.. The Definitve Guide to Pylons (James Gardner): Chapter 6
...

Will be nice to have everything in one place on the wiki.

Regards
Georg

-
Am 11.05.2010 23:09, schrieb Christoph Zwerschke:
 Am 11.05.2010 13:33 schrieb Georg Balmer:
 Next step is your SchemaBuilder suggestion.

 Just tried it, but it doesn't seem to be very useful since you cannot
 specify and validator arguments, and I had to fix some things first (see
 http://bitbucket.org/cito/formencode/changeset/e39881f76131).

 I've added the examples to our Wiki now:
 http://wiki.w4py.org/webwareandformencode.html

 -- Christoph

 --

 ___
 Webware-discuss mailing list
 Webware-discuss@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/webware-discuss



--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-12 Thread Christoph Zwerschke
Am 12.05.2010 10:00 schrieb Georg Balmer:
  . elaborate examples Fields OK-exit

That's simple, just add names to your submit buttons and check them with 
the hasField() method.

Actually I'm not using FormEncode with Webware, so I cannot contribute 
any best practices to the Wiki, but the Wiki is editable by anybody.

It would be nice if we could add a standard form validation and 
generation plugin to Webware, though. There had been some attempts in 
the past with FunFormKit and FormKit4Python, but nothing ever got 
integrated and they are not maintained any more.

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-12 Thread Georg Balmer
What do I want? (random work in progress)

[1]
Development path to port Webware applications using FunFormKit
to Webware-1.1 and FormEncode + WebHelpers + ...
with existing and new tools.

[2]
Development path for new Webware(?) applications
with existing and new tools.

[3]
The target platform (at the time) for these applications is:
. Linux CentOS
. Apache
. Python 2.4
. MySQL 5.0

[4]
Documentation using Sphinx.

To do [1] in a form that can be published on the Webware Wiki somebody must
proofread my code and text. I am not a writer nor a very talented programmer.

In doing [1] I gain the experience and knowledge to do [2].

My next steps are:

. Using Webhelpers to generate the forms.
.. first steps
.. input specifications (repository in DB)


Regards
Georg

---
Am 13.05.2010 00:33, schrieb Christoph Zwerschke:

 Actually I'm not using FormEncode with Webware, so I cannot contribute
 any best practices to the Wiki, but the Wiki is editable by anybody.
 
 It would be nice if we could add a standard form validation and
 generation plugin to Webware, though. There had been some attempts in
 the past with FunFormKit and FormKit4Python, but nothing ever got
 integrated and they are not maintained any more.

 -- Christoph

 --

 ___
 Webware-discuss mailing list
 Webware-discuss@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/webware-discuss



--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1 (2)

2010-05-11 Thread Georg Balmer

Thank you for your reply

My test setup is:

. fedora 11
. python 2.6
. formencode in  site-packages/formencode
   (had to add the i18n directory) from [2]
. webware-1.1.b1
. using utf-8

I got the example from a direct download from formencode.org:
.  [2] svn co http://svn.colorstudy.com/FormEncode/trunk FormEncode
(examples directory: WebwareExamples/index.py)

. you may switch language for formencode in awake

. some lines in save are experimental.
  I made some changes following your suggestions.

  The german version doesn't break HTTPResponse anymore,
  but I still don't understand the mechanics of error catching and so on.


My aim is to have a basic example I can use for my next steps.

Regards
Georg


Am 10.05.2010 23:10, schrieb Christoph Zwerschke:

Am 10.05.2010 12:57 schrieb Georg Balmer:

The orginal WebwareExample by Ian Bicking is working after eliminating HTMLForm
but some german error messages produce a UnicodeEncodeError in HTTPResponse.


Sorry, I cannot find this example you're referring to, where is it?
Generally, you must output ordinary (encoded) strings in Webware, not
unicode. It's best to always use the same encoding (e.g. latin-1 or
utf-8) and work with encoded strings everywhere inside Webware.

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss




#from formencode.htmlform import HTMLForm
import formencode
from formencode import htmlfill
from formencode import validators, compound, schema
from WebKit.Page import Page


page_style = 
html
 head
  titleTell me about yourself/title
  style type=text/css
.error {background-color: #ff}
.error-message {border: 2px solid #f00}
  /style
 /head
 body

 h1Tell me about yourself/h1
 piA FormEncode example/i/p

 %s

 /body/html

form_template = '''
form action= method=POST
input type=hidden name=_action_ value=save

Your name:br
form:error name=name
input type=text name=name
br

Your age:br
form:error name=age
input type=text name=age
br

Your favorite color:br
form:error name=color
input type=checkbox value=red Redbr
input type=checkbox value=blue Bluebr
input type=checkbox value=black Blackbr
input type=checkbox value=green Greenbr
br

input name=_action_save type=submit value=submit
/form
'''

class FormSchema(schema.Schema):
name = validators.String(not_empty=True)
age = validators.Int(min=13, max=99)
color = compound.All(
validators.Set(),
validators.OneOf(['red', 'blue', 'black', 'green']),
)
filter_extra_fields = True
allow_extra_fields = True


class index(Page):

def awake(self, trans):
print  DEBUG SimpleFlow: awake
Page.awake(self, trans)
print formencode.api.get_localedir()
formencode.api.set_stdtranslation(
domain=FormEncode,
languages=[de],
)

fields = self.request().fields()
try:
self.rendered_form
except:
print  DEBUG SimpleFlow: awake: rendered_form = NONE
defaults = {}
errors = {}
self.rendered_form = None

def actions(self):
print  DEBUG SimpleFlow: actions
print Page.actions(self)
fields = self.request().fields()
for field in fields:
print %s: %s % (field, fields[field])
return ['save']

def save(self):
print  DEBUG SimpleFlow: save
ok = None
fields = self.request().fields()
try:
ok = FormSchema.to_python(fields)
print  DEBUG SimpleFlow: save: OK
except validators.Invalid, e:
print  DEBUG SimpleFlow: save: e:, type(e)
if isinstance(e, validators.Invalid):
print  Invalid instance
errors = e.error_dict
eKeys = errors.keys()
errDict = {}
for k in eKeys:
print %s: %s % (k, type(errors[k]))
if isinstance(errors[k], validators.Invalid):
print  Invalid instance
msg = errors[k].msg
errMsg =  msg.encode('utf-8', 'replace')
errDict[k] = errMsg
print  DEBUG SimpleFlow: save: e.error_dict:, errors
defaults = fields # Hinweis
self.rendered_form = htmlfill.render(form_template, defaults, errDict)

self.write(page_style % self.rendered_form)
self.defaults = {}
self.rendered_form = None

def writeContent(self):
print  DEBUG SimpleFlow: writeContent
if self.rendered_form is None:
print  DEBUG SimpleFlow: writeContent: rendered_form is NONE
defaults = {}
errors = {}

Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-11 Thread Christoph Zwerschke
Am 11.05.2010 08:53, schrieb Georg Balmer:
 I got the example from a direct download from formencode.org:
 .  [2] svn co http://svn.colorstudy.com/FormEncode/trunk FormEncode
 (examples directory: WebwareExamples/index.py)

Thanks, I was not aware of that example. Seems it was actually written
for Paste WebKit (http://pythonpaste.org/webkit/).

As you noticed it uses htmlform which is deprecated; you must use
htmlfill directly. You must also add a name=color attribute to the
checkboxes to make these work.

It seems your problem is that the formencode errors are now unicode, so
you must encode these. Here is how I got it working with the current
Webware (I simplified it a bit by not using Webware actions):


class form(Page):

schema = FormSchema()

def awake(self, trans):
Page.awake(self, trans)
try:
fields = self.request().fields()
if 'name' in fields:
fields = self.schema.to_python(fields, self)
else:
fields = self.getDefaults()
except formencode.Invalid, e:
errors = dict((k, v.encode('utf-8'))
for k, v in e.unpack_errors().iteritems())
else:
errors = None
self.rendered_form = formencode.htmlfill.render(form_template,
defaults=fields, errors=errors)

def writeContent(self):
self.write(page_style % self.rendered_form)

def getDefaults(self):
return dict(age='enter your age', color=['blue'])


Let me know how it works for you.

Btw, instead of using a schema, you could also embed the validation info
in the form template and use the SchemaBuilder to parse these.

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-11 Thread Georg Balmer
Thank your for your excellent help.
The basic example works.
Next step is your SchemaBuilder suggestion.

Regards
Georg

-
Am 11.05.2010 11:44, schrieb Christoph Zwerschke:
 Am 11.05.2010 08:53, schrieb Georg Balmer:
 I got the example from a direct download from formencode.org:
 .  [2] svn co http://svn.colorstudy.com/FormEncode/trunk FormEncode
  (examples directory: WebwareExamples/index.py)

 Thanks, I was not aware of that example. Seems it was actually written
 for Paste WebKit (http://pythonpaste.org/webkit/).

 As you noticed it uses htmlform which is deprecated; you must use
 htmlfill directly. You must also add a name=color attribute to the
 checkboxes to make these work.

 It seems your problem is that the formencode errors are now unicode, so
 you must encode these. Here is how I got it working with the current
 Webware (I simplified it a bit by not using Webware actions):


 class form(Page):

  schema = FormSchema()

  def awake(self, trans):
  Page.awake(self, trans)
  try:
  fields = self.request().fields()
  if 'name' in fields:
  fields = self.schema.to_python(fields, self)
  else:
  fields = self.getDefaults()
  except formencode.Invalid, e:
  errors = dict((k, v.encode('utf-8'))
  for k, v in e.unpack_errors().iteritems())
  else:
  errors = None
  self.rendered_form = formencode.htmlfill.render(form_template,
  defaults=fields, errors=errors)

  def writeContent(self):
  self.write(page_style % self.rendered_form)

  def getDefaults(self):
  return dict(age='enter your age', color=['blue'])


 Let me know how it works for you.

 Btw, instead of using a schema, you could also embed the validation info
 in the form template and use the SchemaBuilder to parse these.

 -- Christoph

 --

 ___
 Webware-discuss mailing list
 Webware-discuss@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/webware-discuss



--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-11 Thread Christoph Zwerschke
Am 11.05.2010 13:33 schrieb Georg Balmer:
  Next step is your SchemaBuilder suggestion.

Just tried it, but it doesn't seem to be very useful since you cannot 
specify and validator arguments, and I had to fix some things first (see 
http://bitbucket.org/cito/formencode/changeset/e39881f76131).

I've added the examples to our Wiki now:
http://wiki.w4py.org/webwareandformencode.html

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-10 Thread Christoph Zwerschke
Am 10.05.2010 12:57 schrieb Georg Balmer:
 The orginal WebwareExample by Ian Bicking is working after eliminating 
 HTMLForm
 but some german error messages produce a UnicodeEncodeError in HTTPResponse.

Sorry, I cannot find this example you're referring to, where is it? 
Generally, you must output ordinary (encoded) strings in Webware, not 
unicode. It's best to always use the same encoding (e.g. latin-1 or 
utf-8) and work with encoded strings everywhere inside Webware.

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss


Re: [Webware-discuss] Example howto use FormEncode with Webware-1.1b1

2010-05-10 Thread Georg Balmer

Thank you for your reply

My test setup is:

. fedora 11
. python 2.6
. formencode in  site-packages/formencode
  (had to add the i18n directory) from [2]
. webware-1.1.b1
. using utf-8

I got the example from a direct download from formencode.org:
.  [2] svn co http://svn.colorstudy.com/FormEncode/trunk FormEncode
   (examples directory: WebwareExamples/index.py)

. you may switch language for formencode in awake
. some lines in save are experimental

My aim is to have a basic example I can use for my next steps.

Regards
Georg


Am 10.05.2010 23:10, schrieb Christoph Zwerschke:

Am 10.05.2010 12:57 schrieb Georg Balmer:

The orginal WebwareExample by Ian Bicking is working after eliminating HTMLForm
but some german error messages produce a UnicodeEncodeError in HTTPResponse.


Sorry, I cannot find this example you're referring to, where is it?
Generally, you must output ordinary (encoded) strings in Webware, not
unicode. It's best to always use the same encoding (e.g. latin-1 or
utf-8) and work with encoded strings everywhere inside Webware.

-- Christoph

--

___
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss



#from formencode.htmlform import HTMLForm
import formencode
from formencode import htmlfill
from formencode import validators, compound, schema
from WebKit.Page import Page


page_style = 
html
 head
  titleTell me about yourself/title
  style type=text/css
.error {background-color: #ff}
.error-message {border: 2px solid #f00}
  /style
 /head
 body

 h1Tell me about yourself/h1
 piA FormEncode example/i/p

 %s

 /body/html

form_template = '''
form action= method=POST
input type=hidden name=_action_ value=save

Your name:br
form:error name=name
input type=text name=name
br

Your age:br
form:error name=age
input type=text name=age
br

Your favorite color:br
form:error name=color
input type=checkbox value=red Redbr
input type=checkbox value=blue Bluebr
input type=checkbox value=black Blackbr
input type=checkbox value=green Greenbr
br

input name=_action_save type=submit value=submit
/form
'''

class FormSchema(schema.Schema):
name = validators.String(not_empty=True)
age = validators.Int(min=13, max=99)
color = compound.All(validators.Set(),
 validators.OneOf(['red', 'blue', 'black', 'green']))
filter_extra_fields = True
allow_extra_fields = True


class index(Page):

def awake(self, trans):
print  DEBUG SimpleFlow: awake
Page.awake(self, trans)
print formencode.api.get_localedir()
formencode.api.set_stdtranslation(
domain=FormEncode,
languages=[en],
)
try:
msgs = formencode.api.Validator.all_messages()
print msgs
for msg in msgs:
 print msg
except:
print  DEBUG SimpleFlow: awake: no messages

fields = self.request().fields()
try:
self.rendered_form
except:
print  DEBUG SimpleFlow: awake: rendered_form = NONE
defaults = {}
errors = {}
self.rendered_form = None

def actions(self):
print  DEBUG SimpleFlow: actions
print Page.actions(self)
fields = self.request().fields()
for field in fields:
print %s: %s % (field, fields[field])
return ['save']

def save(self):
print  DEBUG SimpleFlow: save
ok = None
fields = self.request().fields()
try:
ok = FormSchema.to_python(fields)
print  DEBUG SimpleFlow: save: OK
except validators.Invalid, e:
print  DEBUG SimpleFlow: save: e:, type(e)
errors = e.error_dict
eKeys = errors.keys()
for k in eKeys:
print %s: %s % (k, type(errors[k]))
print  DEBUG SimpleFlow: save: e.error_dict:, errors
defaults = fields # Hinweis
self.rendered_form = htmlfill.render(form_template, defaults, errors)

self.write(page_style % self.rendered_form)

def writeContent(self):
print  DEBUG SimpleFlow: writeContent
if self.rendered_form is None:
print  DEBUG SimpleFlow: writeContent: rendered_form is NONE
defaults = {}
errors = {}
self.rendered_form = htmlfill.render(form_template, defaults, errors)
self.write(page_style % self.rendered_form)

def getDefaults(self):
return dict(
age='enter your age',
color=['blue'])

--

___
Webware-discuss mailing list