forked from Princeton-CDH/cdh-web
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
show current page in primary nav #133
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,12 @@ | |
from django.template.loader import render_to_string | ||
from django.utils import timezone | ||
|
||
from cdhweb.pages.snippets import Footer, PrimaryNavigation, SecondaryNavigation, SiteAlert | ||
from cdhweb.pages.snippets import ( | ||
Footer, | ||
PrimaryNavigation, | ||
SecondaryNavigation, | ||
SiteAlert, | ||
) | ||
|
||
register = template.Library() | ||
|
||
|
@@ -77,14 +82,22 @@ def _get_primary_nav_items(): | |
return l1_menu_items | ||
|
||
|
||
@register.simple_tag() | ||
def primary_nav_dict(): | ||
@register.simple_tag(takes_context=True) | ||
def primary_nav_dict(context): | ||
""" | ||
Return the primary navigation data as a dict, for use with the 'json_script' filter. | ||
""" | ||
primary_nav_items = _get_primary_nav_items() | ||
l1_menu_item_data = [_l1_item_to_dict(item) for item in primary_nav_items] | ||
|
||
current_path = context["request"].path | ||
|
||
for item in l1_menu_item_data: | ||
if current_path.startswith(item["link_url"]): | ||
item["is_current"] = True | ||
else: | ||
item["is_current"] = False | ||
|
||
primary_nav_data = { | ||
"primary_nav": { | ||
"l1_menu_items": l1_menu_item_data, | ||
|
@@ -187,4 +200,14 @@ def site_alerts(context): | |
.exclude(display_until__lt=now) | ||
) | ||
data = {"site_alerts": site_alerts, "request": context.get("request")} | ||
return data | ||
return data | ||
|
||
|
||
@register.filter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wild that this isn't a default tag (given some of the things that are) |
||
def starts_with(value, arg): | ||
""" | ||
Usage, {% if value|starts_with:"arg" %} | ||
""" | ||
if value: | ||
return value.startswith(arg) | ||
return None |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to do this, given we've used a different approach in the template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're asking whether we need it in both the template and the JSON blob, then the answer is yes :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. In my head we were using the same data for both