Skip to content

Instantly share code, notes, and snippets.

"""
For Pylons 0.97, optionally with asplake's Routes fork with {.format} parameter support
1) fill_render(), a render() that encodes repeating groups properly
2) A refactored @validate with
a) JSON support
b) cleaned-up form_errors that render properly in the presence of repeating groups
c) some possibility of extensibility
3) JSON-related helpers: sent_json(), accepts_json(), render_json()
4) formatted_url(), a url() that remembers any format extension on the request
5) BaseSchema, a formencode.Schema with sensible defaults
"""
UPDATED 2010-03-02 - remove duplicated on_get handling, incorporate simplifications from Pylons 1.0b
For Pylons 0.97 with asplake's Routes fork with {.format} parameter support
1) fill_render(), a render() that encodes repeating groups properly
2) A refactored @validate with
a) JSON support
b) cleaned-up form_errors that render properly in the presence of repeating groups
c) some possibility of extensibility
3) JSON-related helpers: sent_json(), accepts_json(), render_json()
@asplake
asplake / gist:264659
Created December 28, 2009 12:58
Easy 405's and OPTIONS in Pylons
# Changes to your config/middleware.py:
# -from pylons.wsgiapp import PylonsApp
# +from pylons.wsgiapp import PylonsApp as _PylonsApp
# +from webob.exc import HTTPMethodNotAllowed, HTTPNotFound, HTTPOk
# Then:
methods = ['GET', 'PUT', 'POST', 'DELETE']
@asplake
asplake / gist:260907
Created December 21, 2009 11:14
Routes enhancements
"Fixes and enhancements to Routes 1.11 - see http://positiveincline.com/?p=561"
# NB: superceded by http://bitbucket.org/asplake/routes/
import routes.mapper
COLLECTION_ACTIONS = ['index', 'create', 'new']
MEMBER_ACTIONS = ['show', 'update', 'delete', 'edit']
class SubMapperParent(object):