Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

track added routes to avoid duplicates (e.g. 'message' for show, upda…

…te, and delete actions)
  • Loading branch information...
commit 3acef5e163986324f1e13b7e5ed35acdc103ff31 1 parent 033c05b
Yeeland Chen authored
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)
Please sign in to comment.
Something went wrong with that request. Please try again.