Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Introduction

A routes implementation for Plone. What drives the route implementation is querying the portal catalog.

Example Route:

/posts/{effective:year}/{effective:month}/{effective:day}

To add a route:

 from collective.routes import addRoute
 addRoute('BlogItems',
        '/posts/{effective:year}/{effective:month}/{effective:day}',
        defaultQuery={'portal_type': 'News Item'},
allowPartialMatch=True)

Enable it

Before the route is usable, you need to first enable the route on the site you’d like to use it for. This can be done via the route configuration panel in Site Setup.

Out of the box routes

collective.routes has a couple example routes that it comes pre-packaged with.

blog posts

Blog Posts

/posts/{effective:year}/{effective:month}/{effective:day}

Exmaple Urls:

/posts/2011 ~ Show all posts from 2011
/posts/2011/10 ~ Show all from 2011 and the month of October
/posts/2011/10/5 ~ Show the blog posted October 5, 2011

Definition:

addRoute('Blog Posts',
  '/posts/{effective:year}/{effective:month}/{effective:day}',
  defaultQuery={'portal_type': 'News Item',
                  'sort_on': 'effective',
                  'sort_order': 'reverse'},
  allowPartialMatch=True)

tagged content

Tagged

/tagged/{Subject}/{Subject}/{Subject}

Example Urls:

/tagged/foo ~ Show all posts tagged `foo`
/tagged/foo/bar ~ Show all posts tagged `foo` and `bar`
/tagged/foo/bar/woo ~ Show all posts tagged `foo`, `bar` and `woo`

Definition:

addRoute('Tagged',
     '/tagged/{Subject}/{Subject}/{Subject}',
     defaultQuery={'portal_type': 'News Item',
                   'sort_on': 'effective',
                   'sort_order': 'reverse'},
     allowPartialMatch=True)

Route Syntax

The syntax is really basic and only has a few variations.

Literal

Literal string match:

/string-to-match

Will match “string-to-match”

Query

Match anything and maintain it as a query parameter:

/{Subject}

Will match any string and then keep the value as a query parameter to be used for a portal_catalog query.

Date Query

Has three sub-directives to match part parts:

/{effective:year}/{effective:month}/{effective:day}

Which will then put together a query for the portal_catalog to use.

Customize Object Retrieval

If you’d prefer to bypass the normal portal_catalog query to retrieve your object, you can provide your own object finder method.

Example:

def customObjectFinder(context, **kwargs):
    query = context.query
    site = getSite()
    return site[query['id']]

addRoute('My Route',
     '/my-route/{id}',
     objectFinder=customObjectFinder)

Fiddle with published object

If you’d like to be able to add interfaces at the last moment before the traversal is published, this is what you’d use.

This can be useful for adding interfaces since the actual published object is wrapped so breadcrumbs are maintained on publishing.

Example:

from interfaces import IMySpecialContext
from zope.interface import alsoProvides

def myMungeMethod(context):
    alsoProvides(context, IMySpecialContext)

addRoute('My Route',
     '/foo/{bar}',
     mungeObject=myMungeMethod)

Customize view rendered

You can customize the view that is rendered for the found object also:

addRoute('My Route',
     '/foo/{bar}',
     customViewName='@@custom-view')

addRoute Signature

Allow arguments

routeName(required)

Name of route

route(required)

Actual route specification

defaultQuery(defaults to {})

Default query to provide the finder with

objectFinder(defaults to collective.routes.finders.catalogObjectFinder)

The method used to find the result published object

mungeObject(defaults to None)

Since the real published is a wrapper object, this is a method to be able to mess with the temporary wrapper object before publication

customViewName(defaults to None)

Custom view to render for the found object

allowPartialMatch(defaults to False)

If the whole url is not matched, you can still attempt to publish it. This can be useful for catalog finder routes where you want to allow the user to provide partial urls and still find objects.

breadcrumbFactory(defaults to None)

Override breadcrumb generation. Must return a tuple of {‘absolute_url’: url, ‘Title’: title} values.

customPredicates(defaults to [])

An iterable of custom predicate functions(s) to check against the incoming request that they match. A predicate must take 2 parameters(request, query) where request is the current request object and query is the currently generated query from the route. The function must return a boolean. True if it matches, False it doesn’t.

Changelog

1.1a2 (2014-08-29)

  • Added Italian translation [giacomos]

  • Added some i18n strings and 2 script for i18n rebuild [giacomos]

  • plone 4.3 compat imports [Lewicki]

1.1a1 (2012-02-28)

  • Added Spanish and Brazilian Portuguese translations [hvelarde]

  • Move to using plone.app.registry [saibatizoku]

  • Make work with plone.locking [vangheem]

  • provide ability to specify the view to traverse to in route configuration [vangheem]

  • do not apply IWrappedContext interface [vangheem]

  • add IRoutedRequest layer dynamically to request when routing request so you can override specific parts of plone only when routed. [vangheem]

  • add ability to provide custom predicates [vangheem]

  • add ability to provide a custom breadcrumb factory [vangheem]

  • added addRoute parameter of allowPartialMatch so that you do not have to match an entire url when matching url against a route. [vangheem]

1.0a1 (2011-10-07)

  • Initial release

Release files for collective.routes 1.1a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for collective.routes 1.1a2
File Size Uploaded
collective.routes-1.1a2.zip 43.9 kB Details

Release files / collective.routes-1.1a2.zip

Download URL collective.routes-1.1a2.zip
Size 43.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fe2571c0771b7305d73f8b7725dbfd781baa5274c8ae9947914e029efca8845f
BLAKE2b-256 checksum
How to use checksums
9088ebb71258ea48582be6b0f2bdc8ef6191e6df4da590dbbb7343fbda2a7b3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1a2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page