Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for Issue 2 #5

Merged
merged 2 commits into from

2 participants

@yeeland

Now checking for duplicate routes before calling add_route

Yeeland Chen added some commits
@bbangert bbangert merged commit 040306a into Pylons:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 14, 2011
  1. track added routes to avoid duplicates (e.g. 'message' for show, upda…

    Yeeland Chen authored
    …te, and delete actions)
Commits on Jun 20, 2011
  1. changed to be more DRY

    Yeeland Chen authored
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 3 deletions.
  1. +11 −3 pyramid_routehelper/__init__.py
View
14 pyramid_routehelper/__init__.py
@@ -228,6 +228,13 @@ def swap(dct, newdct):
collection_path = path
new_path = path + '/new'
member_path = path + '/:id'
+
+ added_route_names = {}
+
+ def add_route_if_new(self, route_name, path, **kwargs):
+ if route_name not in added_route_names:
+ self.add_route(route_name, path, **kwargs)
+ added_route_names[route_name] = path
def add_route_and_view(self, action, route_name, path, request_method='any'):
if request_method != 'any':
@@ -235,13 +242,14 @@ def add_route_and_view(self, action, route_name, path, request_method='any'):
else:
request_method = None
- self.add_route(route_name, path, **kwargs)
+ add_route_if_new(self, route_name, path, **kwargs)
self.add_view(view=handler, attr=action, route_name=route_name, request_method=request_method, **action_kwargs.get(action, {}).get('default', {}))
for format_kwargs in action_kwargs.get(action, {}).get('formatted', []):
format = format_kwargs.pop('format')
- self.add_route("%s_formatted_%s" % (format, route_name),
- "%s.%s" % (path, format), **kwargs)
+ formatted_route_name = "%s_formatted_%s" % (format, route_name)
+
+ add_route_if_new(self, formatted_route_name, "%s.%s" % (path, format), **kwargs)
self.add_view(view=handler, attr=format_kwargs.pop('attr'), request_method=request_method,
route_name = "%s_formatted_%s" % (format, route_name), **format_kwargs)
Something went wrong with that request. Please try again.