-
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 #41
base: main
Are you sure you want to change the base?
Main Menu #41
Conversation
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.
I know this is a draft. Thought I'd leave a few notes to boot
cms/navigation/models.py
Outdated
|
||
|
||
# Custom LinkBlock to support both pages and URLs | ||
class LinkBlock(StructBlock): |
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: extract https://github.com/ONSdigital/dis-wagtail/blob/main/cms/core/blocks/related.py#L22-L89 to core/blocks/base.py
and re-use
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
cms/navigation/models.py
Outdated
|
||
# Section StructBlock for columns | ||
class SectionBlock(StructBlock): | ||
section_link = LinkBlock(help_text="Main link for this section (Theme pages or external URLs).") |
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.
this may need a separate block definition as the requirement says the PageChooserBlock should be limited to Theme page (Wagtail docs)
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!
cms/navigation/models.py
Outdated
class Meta: | ||
verbose_name = "Main Menu" | ||
verbose_name_plural = "Main Menus" |
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.
These should not be needed. See https://docs.djangoproject.com/en/5.1/ref/models/options/#verbose-name
Howeve, if you want to make it translateable, then please follow https://docs.djangoproject.com/en/5.1/topics/i18n/translation/#model-verbose-names-values
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.
Removed and gettext_lazy added.
…ed, section restricted to 3, URL label added, icon for navigation settings added and restricting it to so only 1 main menu can be created
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 tested locally and it all functions well. A couple of small comments on the validation and example help text.
@helenb Will push my latest code up as I haven't done that. It should be way better =) Might resolve some of the issues raised by you. Thanks Helen, will sort out any issues not addressed already locally and then push it up. |
…ate one main menu instance in the wagtail admin. Migration file added.
…ks.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.
…enuViewSet added to restrict creating more than one main menu instance
Thanks for testing this. I fixed the link issues. As previously for highlights when a user selects a Wagtail page it didn't turn it into a link. Now it does. Same for the topic page. Also fixed some other edge cases I missed out on previously, so now all should be good on that side. Let me know if there are any further issues. Now adding main menu content and it being usable on the website menu should be all good. So now we are just left with front-end alignment issues.
Would be amazing if you could follow that up on a task. Happy to demo the front-end styling/ alignment issues to you. Thanks =) |
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.
A few more notes
|
||
{% set keyLinksList = [] %} | ||
|
||
{% if navigation_settings.main_menu and navigation_settings.main_menu.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.
these would be better off as properties on NavigationSettings
, then
% set navigation_settings = settings.navigation.NavigationSettings %}
{% set pageConfig = {
...
"keyLinksList": navigation_settings.main_menu_highlights,
"itemsList": navigation_settings.main_menu_items
}
%}
reads so much better in the template
def user_has_permission(self, user: Optional["User"] = None, action: str | None = None) -> bool: | ||
if action == "add" and MainMenu.objects.exists(): | ||
return False | ||
return user is not None and user.has_perm(self._get_permission_name(action)) |
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.
return user is not None and user.has_perm(self._get_permission_name(action)) | |
return super().user_has_permission(user) |
cms/navigation/models.py
Outdated
page = PageChooserBlock(required=False, page_type="themes.ThemePage") | ||
|
||
class Meta: | ||
label = "Theme Link" |
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.
as discussed, for consistency, we need to mark for translation any strings that will be displayed to the user
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!
Thanks @sanjeevz3009 - once you've merged this PR, you could re-assign the ticket to me to do the front-end tweaks. |
What is the context of this PR?
Add a navigation app in Wagtail to manage the main menu, allowing for structured, customisable navigation.
How to review
Loom walkthrough of the main menu: ATTACH LINK HERE
Follow-up Actions
List any follow-up actions (if applicable), like needed documentation updates or additional testing.