-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlight active section in navigation. (#13)
Highlight, in the navigation bar, the section of the app that the user is currently using.
- Loading branch information
Showing
3 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from flask import session, url_for | ||
|
||
|
||
class NavBarItem: | ||
label = "" # Navigation link text | ||
route = "" # Route ("transfer.index" for example) | ||
|
||
def __init__(self, label, route): | ||
self.label = label | ||
self.route = route | ||
|
||
def get_url(self): | ||
return url_for(self.route) | ||
|
||
def is_active(self, request): | ||
# Determine request Blueprint | ||
rule = request.url_rule | ||
request_blueprint = rule.endpoint.split(".")[0] | ||
|
||
if rule.endpoint == self.route: | ||
# Found exact match between route and request | ||
return True | ||
elif request_blueprint != "reporter": | ||
# Determine route Blueprint | ||
route_blueprint = self.route.split(".")[0] | ||
|
||
# Found Blueprint-level match between route and request | ||
return request_blueprint == route_blueprint | ||
|
||
|
||
class NavBar: | ||
items = [] | ||
|
||
def add(self, label, route): | ||
self.items.append(NavBarItem(label, route)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters