Positive Incline Mike Burrows (@asplake) moving on up, positively

December 28, 2009

DRY up your routes – UPDATES

Filed under: Web Integration — Tags: — Mike @ 11:09 am

Two updates to the previous post:

Update 1: Routes fork on bitbucket

See http://bitbucket.org/asplake/routes/. I’ve sent a pull request with my changes (the prettyprinter included), but no response yet and I’m delighted to say that Ben has now incorporated them in the base Routes repo so expect to see them soon in Routes 1.12.

Update 2: Tidier collection() usage

The end-state of the last post

    with mapper.collection(
                    'releases',
                    'release',
                    member_options={
                        'requirements': {'id': 'd+'}}) as c:
        c.member.link(rel='notes', name='release_notes')

can be written as

    with mapper.collection(
                    'releases',
                    'release',
                    requirements={'id': 'd+'}) as c:
        c.member.link(rel='notes', name='release_notes')

Losing the with syntax, a vanilla collection resource with integer id’s looks like this:

    mapper.collection(
                'releases',
                'release',
                requirements={'id': 'd+'})

This applies requirements to the collection-level routes as well as the member-level routes but the overhead (unquantified) must be very small and I prefer this tidier form.  It would be easy enough though to provide a member_requirements argument if the performance difference proves to be significant.

1 Comment

  1. […] Incline Mike Burrows (asplake) moving on up « Prettyprinter for Pylons routes DRY up your routes – UPDATES […]

    Pingback by DRY up your routes - a Pylons routing refactoring « Positive Incline — December 28, 2009 @ 11:11 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress