Simple form utilities for using Pyramid with FormEncode and WebHelpers.
Documentation: https://docs.pylonsproject.org/projects/pyramid-simpleform/en/latest/
Bindings to help integrate formencode with Pyramid.
License: Other
Simple form utilities for using Pyramid with FormEncode and WebHelpers.
Documentation: https://docs.pylonsproject.org/projects/pyramid-simpleform/en/latest/
File "/home/myname/myenv/lib/python3.5/site-packages/pyramid_simpleform-0.7-py3.5.egg/pyramid_simpleform/__init__.py", line 157, in errors_for
errors = self.errors.get(field, [])
AttributeError: 'str' object has no attribute 'get'
Getting this error while trying to use FormRenderer
's errorlist
method to get the errors for the form field.
But documentation says that
Any errors get dumped into the errors property as a dict.
Don't know maybe documentation is not compatible with this version of the package.
I have a schema that defines a single non-empty text field and sets the controls that allow additional fields and filters them. The schema looks like this:
class Message(Schema):
"""Message reply."""
allow_extra_fields = True
filter_extra_fields = True
message = validators.UnicodeString(not_empty=True, max=500)
It is then processed in the following view code:
@view_config(request_method='POST', renderer='message.mak')
def claim_update(context, request):
thread = context.data
form = pyramid_simpleform.Form(
request, schema=schemas.Message)
if form.validate():
# ... persist and redirect
return exc.HTTPSeeOther('/message')
return {'thread': thread, 'form': FormRenderer(form)}
The form renderer adds a csrf token and then the form is submitted by the user. The view code runs again and after validating (and stripping of attributes not in my schema) the form.data dictionary looks like this:
{'_csrf': u'6921efe037911dfe28991802462034c227173a06',
'message': u'',
'submit': u'Add message'}
The attributes that should have been stripped out have not been.
Performing a standalone to_python
on my Message schema does work as expected (only the message gets returned, and when empty, Invalid is raised.
This causes me trouble because I'm resetting the csrf token on every successful post, but the old csrf value keeps coming back.
The method of the Form class determines how it reads information from the request, either from the request.POST
attribute (with the default method='POST'
), or the general request.params
attribute (for any other method).
This method needs to be explicitly provided to the Form class upon instantiation, along with the request object. If no method is provided, it defaults to 'POST'. This causes some confusing behavior when using simpleform to validate a multipart/form-data
PUT request.
Would it make sense to change the behavior to read the request.method
by default, instead of using a hard-coded value of 'POST'? Doing this during initialization would still allow the method to be controlled by the user when the method argument is provided.
Hi there,
I am getting following error with Python 3.10.4 version -
File "D:\Projects\Github\proj\pyramid-101\venv\lib\site-packages\pyramid_simpleform\__init__.py", line 175
except Invalid, e:
^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized
From this post, I think this is because this syntax in pyramid_simpleform\__init__.py
is no longer supported by newer version of Python -
except Invalid, e:
Is there any plan to upgrade the package to support newer version of Python?
We typically point http://docs.pylonsproject.org/projects/<project_name>/en/latest/
to http://<project_name>.readthedocs.io/en/latest/
, but I don't know who does that or how. Anyone know? Is that @blaflamme ?
For now I've merged a PR that at least points to a current URL, just not canonical.
Hi,
It seems like pyramid_simpleform doesn't work with Python 3.5.
I got syntax error when I call from pyramid_simpleform import Form
.
Is there any workaround to use FormEncode with Pyramid on Python 3.5?
Or just a general question, is there any recommended form handling library for Pyramid on Python 3.5?
Any help is much appreciated!
Any idea if I can get this working somehow? The functionality that checks if the value should be checked is comparing a datetime against a string?
def radio(self, name, value=None, checked=False, label=None, **attrs):
"""
Outputs radio input.
"""
checked = self.data.get(name) == value or checked
return tags.radio(name, value, checked, label, **attrs)
(Pdb) value
'05/08/15'
(Pdb) self.data.get(name)
datetime.date(2015, 5, 8)
(Pdb)
${form.radio('delivery_schedule_date', value=date['date'].strftime('%x')
delivery_schedule_date = validators.DateConverter(
not_empty=True,
messages={'empty': 'Please select a date'})
Hi,
I'm currently extending the FormRenderer of simpleform for supporting parsley.js
http://parsleyjs.org/documentation.html
Just to know if it worth submit a pull request to this repo or keep it as a pluginish ..
Thks
someone endup implement it like this:
http://stackoverflow.com/questions/5400397/python-pyramid-how-to-use-checkboxes-and-radio-buttons
from pyramid_simpleform.renderers import FormRenderer as OldFormRenderer
from webhelpers.html import tags
class FormRenderer(OldFormRenderer):
def checkbox(self, name, value="1", checked=False, label=None, id=None,
*_attrs):
"""
Outputs checkbox input.
"""
id = id or name
return tags.checkbox(name, value, checked, label, id, *_attrs)
There should be an option for password field for not to be filled on error. let the user type it again.
as described here does this library can handle this?
See pyramid_jinja2:
https://github.com/Pylons/pyramid_jinja2/blob/master/docs/conf.py
https://github.com/Pylons/pyramid_jinja2/blob/master/rtd.txt
https://github.com/Pylons/pyramid_jinja2/blob/master/setup.py#L50
As well as specific RTD config to use rtd.txt
.
On pypi its version is 0.6.1 and it was uploaded on 2011-02-26. It would be great if you could release new version.
I have a form:
a[]=a&a[]=b&a[]=c
Processed with the following code:
def handler(request):
validators = {'a[]': formencode.ForEach(formencode.validators.String(max=16))}
form = Form(request, validators=validators)
form.validate()
print form.data['a[]']
....
It prints:
['c']
When I changed the code to:
class A(formencode.Schema):
pass
A.add_field('a[]', formencode.ForEach(formencode.validators.String(max=16)))
def handler(request):
form = Form(request, schema=A())
form.validate()
print form.data['a[]']
....
It prints:
['a', 'b', 'c']
I think it is a bug of pyramid_simpleform
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.