Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for Issue #2 #4

Closed
wants to merge 1 commit into from

1 participant

@yeeland

avoiding duplicate route creation (e.g. 'message' for show, update, and delete actions) to address issue #2

@yeeland yeeland closed this
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)
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 3 deletions.
  1. +12 −3 pyramid_routehelper/__init__.py
View
15 pyramid_routehelper/__init__.py
@@ -228,6 +228,8 @@ def swap(dct, newdct):
collection_path = path
new_path = path + '/new'
member_path = path + '/:id'
+
+ added_route_names = []
def add_route_and_view(self, action, route_name, path, request_method='any'):
if request_method != 'any':
@@ -235,13 +237,20 @@ def add_route_and_view(self, action, route_name, path, request_method='any'):
else:
request_method = None
- self.add_route(route_name, path, **kwargs)
+ if route_name not in added_route_names: # Check if the route name has been added already
+ self.add_route(route_name, path, **kwargs)
+ added_route_names.append(route_name)
+
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)
+
+ if formatted_route_name not in added_route_names: # Check if the route name has been added already
+ added_route_names.append(formatted_route_name)
+ self.add_route(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.