From 5084428c9dea9cd8cfc5b16402ee687505bd0fd0 Mon Sep 17 00:00:00 2001 From: Justin McKay Date: Sat, 22 Mar 2014 23:57:48 +1100 Subject: [PATCH 1/6] Added the Route List panel to show the routes that are available within Flask. --- flask_debugtoolbar/__init__.py | 1 + flask_debugtoolbar/panels/route_list.py | 40 +++++++++++++++++++ .../templates/panels/route_list.html | 21 ++++++++++ 3 files changed, 62 insertions(+) create mode 100644 flask_debugtoolbar/panels/route_list.py create mode 100644 flask_debugtoolbar/templates/panels/route_list.html diff --git a/flask_debugtoolbar/__init__.py b/flask_debugtoolbar/__init__.py index b3e3264..367b4a0 100644 --- a/flask_debugtoolbar/__init__.py +++ b/flask_debugtoolbar/__init__.py @@ -101,6 +101,7 @@ class DebugToolbarExtension(object): 'flask_debugtoolbar.panels.template.TemplateDebugPanel', 'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel', 'flask_debugtoolbar.panels.logger.LoggingPanel', + 'flask_debugtoolbar.panels.route_list.RouteListDebugPanel', 'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel', ), } diff --git a/flask_debugtoolbar/panels/route_list.py b/flask_debugtoolbar/panels/route_list.py new file mode 100644 index 0000000..f97effc --- /dev/null +++ b/flask_debugtoolbar/panels/route_list.py @@ -0,0 +1,40 @@ +from flask_debugtoolbar.panels import DebugPanel +from flask import current_app + +_ = lambda x: x + + +class RouteListDebugPanel(DebugPanel): + """ + Panel that displays the time a response took in milliseconds. + """ + name = 'Route List' + has_content = True + routes = [] + + def nav_title(self): + return _('Route List') + + def title(self): + return _('Route List') + + def url(self): + return '' + + def nav_subtitle(self): + + # get the count of routes. We need to -1 to get an acurate route count + return "%s routes" % (len(current_app.url_map._rules) - 1) + + def process_request(self, request): + for rule in current_app.url_map.iter_rules(): + if rule.endpoint != 'static': + self.routes.append(str(rule.rule)) + + def content(self): + context = self.context.copy() + context.update({ + 'routes': self.routes, + }) + + return self.render('panels/route_list.html', context) diff --git a/flask_debugtoolbar/templates/panels/route_list.html b/flask_debugtoolbar/templates/panels/route_list.html new file mode 100644 index 0000000..64bc1fd --- /dev/null +++ b/flask_debugtoolbar/templates/panels/route_list.html @@ -0,0 +1,21 @@ + + + + + + + + + {% if routes %} + {% for route in routes %} + + + + {% endfor %} + {% else %} + + + + {% endif %} + +
Flask routes
{{ route }}
No routes have been configured.
\ No newline at end of file From 79717926a5bd3a43f3c9e0b194156cb426687bc5 Mon Sep 17 00:00:00 2001 From: = Date: Sun, 23 Mar 2014 15:12:31 +1100 Subject: [PATCH 2/6] Added endpoints, HTTP methods, Is alias and Redirect to columns to route list. --- flask_debugtoolbar/panels/route_list.py | 7 ++++++- .../templates/panels/route_list.html | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/flask_debugtoolbar/panels/route_list.py b/flask_debugtoolbar/panels/route_list.py index f97effc..d1f5db9 100644 --- a/flask_debugtoolbar/panels/route_list.py +++ b/flask_debugtoolbar/panels/route_list.py @@ -27,9 +27,14 @@ class RouteListDebugPanel(DebugPanel): return "%s routes" % (len(current_app.url_map._rules) - 1) def process_request(self, request): + # Clear existing routes + self.routes = [] + + # iterate through the routes for rule in current_app.url_map.iter_rules(): if rule.endpoint != 'static': - self.routes.append(str(rule.rule)) + print(rule) + self.routes.append(rule) def content(self): context = self.context.copy() diff --git a/flask_debugtoolbar/templates/panels/route_list.html b/flask_debugtoolbar/templates/panels/route_list.html index 64bc1fd..dfe13c0 100644 --- a/flask_debugtoolbar/templates/panels/route_list.html +++ b/flask_debugtoolbar/templates/panels/route_list.html @@ -2,14 +2,22 @@ - + + + + + {% if routes %} - {% for route in routes %} + {% for route in routes|sort(attribute='rule') %} - + + + + + {% endfor %} {% else %} From 81f8e34846d10b412c80068ec0d4952cd25e1bc0 Mon Sep 17 00:00:00 2001 From: = Date: Sun, 23 Mar 2014 15:14:28 +1100 Subject: [PATCH 3/6] Removed printing of routes to console. --- flask_debugtoolbar/panels/route_list.py | 1 - 1 file changed, 1 deletion(-) diff --git a/flask_debugtoolbar/panels/route_list.py b/flask_debugtoolbar/panels/route_list.py index d1f5db9..8321d07 100644 --- a/flask_debugtoolbar/panels/route_list.py +++ b/flask_debugtoolbar/panels/route_list.py @@ -33,7 +33,6 @@ class RouteListDebugPanel(DebugPanel): # iterate through the routes for rule in current_app.url_map.iter_rules(): if rule.endpoint != 'static': - print(rule) self.routes.append(rule) def content(self): From 95d7eb977f6697b8181130b7938806c61cd41467 Mon Sep 17 00:00:00 2001 From: Matt Good Date: Tue, 14 Apr 2015 14:57:47 -0700 Subject: [PATCH 4/6] Format route_list template with spaces --- .../templates/panels/route_list.html | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/flask_debugtoolbar/templates/panels/route_list.html b/flask_debugtoolbar/templates/panels/route_list.html index dfe13c0..11e3643 100644 --- a/flask_debugtoolbar/templates/panels/route_list.html +++ b/flask_debugtoolbar/templates/panels/route_list.html @@ -1,29 +1,28 @@ -
Flask routesURL routeEndpoint nameHTTP methodsIs aliasRedirect to
{{ route }}{{ route.rule }}{{ route.endpoint }}{{ route.methods|sort }}{{ route.alias }}{{ route.redirect_to }}
- - - - - - - - - - - {% if routes %} - {% for route in routes|sort(attribute='rule') %} - - - - - - - - {% endfor %} - {% else %} - - - - {% endif %} - -
URL routeEndpoint nameHTTP methodsIs aliasRedirect to
{{ route.rule }}{{ route.endpoint }}{{ route.methods|sort }}{{ route.alias }}{{ route.redirect_to }}
No routes have been configured.
\ No newline at end of file + + + URL route + Endpoint name + HTTP methods + Is alias + Redirect to + + + + {% if routes %} + {% for route in routes|sort(attribute='rule') %} + + {{ route.rule }} + {{ route.endpoint }} + {{ route.methods|sort }} + {{ route.alias }} + {{ route.redirect_to }} + + {% endfor %} + {% else %} + + No routes have been configured. + + {% endif %} + + From cfe16247306f130cffca1945250145f03cfcd732 Mon Sep 17 00:00:00 2001 From: Matt Good Date: Tue, 14 Apr 2015 14:58:31 -0700 Subject: [PATCH 5/6] Simplify route methods display Show just the names as text, without the Python list syntax formatting. --- flask_debugtoolbar/templates/panels/route_list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_debugtoolbar/templates/panels/route_list.html b/flask_debugtoolbar/templates/panels/route_list.html index 11e3643..d987d23 100644 --- a/flask_debugtoolbar/templates/panels/route_list.html +++ b/flask_debugtoolbar/templates/panels/route_list.html @@ -14,7 +14,7 @@ {{ route.rule }} {{ route.endpoint }} - {{ route.methods|sort }} + {{ route.methods|sort|join(', ') }} {{ route.alias }} {{ route.redirect_to }} From f7feecc7515ea0e18e70c1c21627b0e7b3c52ac3 Mon Sep 17 00:00:00 2001 From: Matt Good Date: Tue, 14 Apr 2015 15:07:08 -0700 Subject: [PATCH 6/6] Include the "static" route in the list While this is enabled for most apps, it's optional and might still be useful to display. --- flask_debugtoolbar/panels/route_list.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/flask_debugtoolbar/panels/route_list.py b/flask_debugtoolbar/panels/route_list.py index 8321d07..c396433 100644 --- a/flask_debugtoolbar/panels/route_list.py +++ b/flask_debugtoolbar/panels/route_list.py @@ -6,9 +6,9 @@ _ = lambda x: x class RouteListDebugPanel(DebugPanel): """ - Panel that displays the time a response took in milliseconds. + Panel that displays the URL routing rules. """ - name = 'Route List' + name = 'RouteList' has_content = True routes = [] @@ -22,23 +22,13 @@ class RouteListDebugPanel(DebugPanel): return '' def nav_subtitle(self): - - # get the count of routes. We need to -1 to get an acurate route count - return "%s routes" % (len(current_app.url_map._rules) - 1) + count = len(self.routes) + return '%s %s' % (count, 'route' if count == 1 else 'routes') def process_request(self, request): - # Clear existing routes - self.routes = [] - - # iterate through the routes - for rule in current_app.url_map.iter_rules(): - if rule.endpoint != 'static': - self.routes.append(rule) + self.routes = list(current_app.url_map.iter_rules()) def content(self): - context = self.context.copy() - context.update({ + return self.render('panels/route_list.html', { 'routes': self.routes, }) - - return self.render('panels/route_list.html', context)