Giter Site home page Giter Site logo

pylons / pyramid_simpleform Goto Github PK

View Code? Open in Web Editor NEW
15.0 11.0 25.0 151 KB

Bindings to help integrate formencode with Pyramid.

License: Other

Python 99.64% Mako 0.36%
pyramid pyramid-framework form forms simpleform formencode webhelpers python

pyramid_simpleform's Introduction

pyramid_simpleform's People

Contributors

andrecp avatar antoniojesvs avatar areski avatar dannymidnight avatar digitalresistor avatar holiverh avatar lambacck avatar mcdonc avatar mmerickel avatar setn avatar stevepiercy avatar wushell avatar yothenberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyramid_simpleform's Issues

radio checked=checked comparing a string against a datetime?

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'})

Renderer.checkbox, checked attr is missing in tag.checkbox?

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)

Wrong behaviour with formencode.ForEach

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

AttributeError: 'str' object has no attribute 'get'

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.

Form method should inherit request.method

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.

CSRF method uses existing form value over correct session csrf value.

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.

Update readme to point to correct URL

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.

SyntaxError while using the library on Python 3.10.4

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?

Python 3.5 compatability

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.