Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed to be more DRY

  • Loading branch information...
commit 9c6f331bb9aca75ac2440381c4c032781ff85ce1 1 parent 3acef5e
Yeeland Chen authored
Showing with 8 additions and 9 deletions.
  1. +8 −9 pyramid_routehelper/__init__.py
View
17 pyramid_routehelper/__init__.py
@@ -229,7 +229,12 @@ def swap(dct, newdct):
new_path = path + '/new'
member_path = path + '/:id'
- added_route_names = []
+ 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':
@@ -237,20 +242,14 @@ def add_route_and_view(self, action, route_name, path, request_method='any'):
else:
request_method = None
- 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)
-
+ 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')
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)
-
+ 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)
Please sign in to comment.
Something went wrong with that request. Please try again.