-
Notifications
You must be signed in to change notification settings - Fork 0
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
Main Menu Template Tags #85
base: main
Are you sure you want to change the base?
Conversation
for column in columns: | ||
self.assertIn("column", column) | ||
self.assertIn("linksList", column) | ||
self.assertIsInstance(column["linksList"], list) | ||
|
||
for section in column["linksList"]: | ||
self.assertIn("text", section) | ||
self.assertIn("url", section) | ||
self.assertIn("children", section) | ||
self.assertIsInstance(section["children"], list) | ||
|
||
for child in section["children"]: | ||
self.assertIn("text", child) | ||
self.assertIn("url", child) |
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.
Can you do the full check? that is
self.assertListEqual(columns, [...])
where [...]
is the expected output.
Ditto for highlights
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.
Done! I think I implemented what you envisioned!
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.
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.
LGTM - works as expected
cms/navigation/jinja2tags.py
Outdated
"""Extends the Jinja functionality with additional Django, Wagtail, | ||
and other package template tags. | ||
""" |
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.
"""Extends the Jinja functionality with additional Django, Wagtail, | |
and other package template tags. | |
""" | |
"""Extends Jinja templates with what's needed to render the navigation. | |
""" |
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.
Docstrings updated!
return highlights | ||
|
||
|
||
def _extract_url_item(value: "StructValue", request: Optional["HttpRequest"] = None) -> LinkItem: |
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.
Nit: This method looks almost identical to _extract_highlight_item
- could the logic be shared?
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.
Refactored and now there is one single function with shared logic.
class MainMenuTemplateTagTests(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.mock_request = Mock() |
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.
Suggestion: wagtail.coreutils.get_dummy_request
or django.test.RequestFactory
would be better here, so make sure it looks request-like 🦆
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.
Done!
from cms.navigation.models import MainMenu | ||
|
||
|
||
register = template.Library() |
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.
Issue: This appears to be unused
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.
Good spot. Removed!
linksList: list["LinkItem"] | ||
|
||
|
||
def _extract_highlight_item(value: "StructValue", request: Optional["HttpRequest"] = None) -> dict[str, str]: |
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.
@sanjeevz3009 Might it be simpler/easier to define this sort of thing as a method on the model class?
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.
@ababic Made some changes from Jake's comments above and now I have _extract_item
. Do you still think it may be worth adding _extract_item
to the model class?
The base branch was changed.
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.
Thanks @sanjeevz3009 I have functionally tested and it works well. Added one query to the template.
…navigation_template_tags added and navigation_tags refactored.
* Front-end hacked together to complete the back-end * Navigation app added, models created for navigation settings * Navigation bar on the front-end test * Front-end code reverted due to the front-end main menu being done separately * New line * Code formatted * Type hinted and code formatted * Code refactored, abstract link class created, validation messages added, section restricted to 3, URL label added, icon for navigation settings added and restricting it to so only 1 main menu can be created * Migration file * Main menu modelling complete, restricting user to be able to only create one main menu instance in the wagtail admin. Migration file added. * LinkBlock extracted out of core.blocks.related and moved to core.blocks.base to be reusable across the project. LinkBlock from core.blocks.base is being used instead of the abstract class originally defined in models.py. * Code formatted, zombie code removed, unused imports removed and MainMenuViewSet added to restrict creating more than one main menu instance * Front-end integrated * Type hints added * Nav template issues fixed * gettext_lazy added * Preview added * Use the title provided by the user over the default title from the page * help text update * Type hints added * Migration file regenerated * Tests added * TODO removed and translatable added * Description help text updated * Tests setup * Example StreamField value setting in test_highlights_streamfield_limit * Debug * Errors being raised when adding more than 3 highlights * Committing working factories to save * Clean method for ColumnBlock added and tests updated * Updated tests * test_section_streamfield_limit test working * Added more tests, factories updated * Removed tests * Max num code removed * Code formatted * Utilising pageurl to point to get internal wagtail pages * Code refactored * Reverting format for md files * Reverting md files formatting * Lint errors corrected * Unused import removed and base template updated * Base template update * Type checking added back in * Template code updated to make sure to only display live wagtail pages * Main menu live preview fixed * MegaLinter errors fixed * Using a preview template for live previews * Mark NavigationSettings as allowed for write in ExternalEnvRouter * Use our own BaseSiteSetting which works with the ExternalEnvRouter * RevisionMixin implementation and mypy fix * Blocks refactor * Code linted * Tests for main menu viewset added * Type ignore added * Duplicate page and external URL validation for sections and topic links within columns complete. * Duplicate page and URL for columns complete. * test_forms in place * Update test_clean_highlights_no_duplicate test * Tests complete for forms.py * test_forms.py code clean up * Example usage zombie code removed * Code formatted and refactored * Code refactored, type hinted, tests refactored. * gettext translation added * LinkBlock Factory moved * De-nest the blocks tests folder
…ion doc strings updated and unused code in navigation_tags file removed.
6f19227
to
f17986e
Compare
What is the context of this PR?
This is a follow-up PR to the #41.
This PR introduces template tags for the main menu, by removing front-end logic. By separating concerns, this ensures templates are focused on presentation while business logic remains in Python. This improves readability and testability, simplifying the template structure. Additionally, we will have a more maintainable code by reducing complexity and allowing for performance optimisations when the page is rendered.
How to review
Test the main menu per norm as instructed in #41 description. Everything should work normally when adding a main menu -> highlights -> columns - > sections -> topics.
Follow-up Actions
List any follow-up actions (if applicable), like needed documentation updates or additional testing.