-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Main Nav] Nav Settings [TP1-38](#12137)
* Better panels on NavMenu * Add SiteNavMenu setting * Show only default locale nav menus on settings * Fix donate banner test * Add title and locale to NavDropdownFactory * Remove print statements
- Loading branch information
1 parent
e141850
commit 1d76c60
Showing
6 changed files
with
154 additions
and
2 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
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,42 @@ | ||
# Generated by Django 4.2.11 on 2024-04-02 12:26 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("wagtailcore", "0089_log_entry_data_json_null_to_object"), | ||
("nav", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="SiteNavMenu", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
( | ||
"active_nav_menu", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
related_name="site_nav_menu", | ||
verbose_name="Active Navigation Menu", | ||
to="nav.navmenu", | ||
), | ||
), | ||
( | ||
"site", | ||
models.OneToOneField( | ||
editable=False, on_delete=django.db.models.deletion.CASCADE, to="wagtailcore.site" | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Navigation Menu", | ||
"verbose_name_plural": "Navigation Menus", | ||
}, | ||
), | ||
] |
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,58 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from wagtail.admin.viewsets import viewsets as wagtail_admin_viewsets | ||
from wagtail.admin.viewsets.chooser import ChooserViewSet | ||
from wagtail.models import Locale | ||
from wagtail.test.utils import WagtailTestUtils | ||
|
||
from networkapi.nav import factories as nav_factories | ||
from networkapi.nav import models as nav_models | ||
|
||
|
||
class TestNavMenuSnippetChooser(WagtailTestUtils, TestCase): | ||
def is_nav_menu_chooser_viewset(self, viewset): | ||
return viewset.model == nav_models.NavMenu and issubclass(viewset.__class__, ChooserViewSet) | ||
|
||
def get_chooser_viewset(self): | ||
# Get the last registered ChooserViewSet for the NavMenu model. | ||
# Note: There can be multiple ChooserViewSets registered for a model. | ||
wagtail_admin_viewsets.populate() | ||
model_viewsets = [x for x in wagtail_admin_viewsets.viewsets if self.is_nav_menu_chooser_viewset(x)] | ||
return model_viewsets[-1] | ||
|
||
def setUp(self): | ||
# Get the chooser url from the viewsets registry. | ||
# Would have been easier to get from model.snippet_viewset, but | ||
# that does not work somehow. | ||
chooser_viewset = self.get_chooser_viewset() | ||
self.chooser_url = reverse(f"{chooser_viewset.name}:choose") | ||
|
||
User = get_user_model() | ||
self.user = User.objects.create_superuser("admin-user", "[email protected]", "password") | ||
self.client.force_login(self.user) | ||
|
||
self.default_locale = Locale.get_default() | ||
self.fr_locale = Locale.objects.create(language_code="fr") | ||
self.menus = [ | ||
nav_factories.NavMenuFactory.create(title="Generic"), | ||
nav_factories.NavMenuFactory.create(title="Foundation"), | ||
nav_factories.NavMenuFactory.create(title="Mozfest"), | ||
] | ||
|
||
def test_menu_chooser_exclude_locale(self): | ||
translated_menu = self.menus[0].copy_for_translation(self.fr_locale) | ||
translated_menu.save() | ||
all_menus = nav_models.NavMenu.objects.all() | ||
default_menus = nav_models.NavMenu.objects.filter(locale=self.default_locale) | ||
response = self.client.get(self.chooser_url) | ||
results = response.context["results"] | ||
|
||
# Chooser does not include every menu, but only the default language ones | ||
self.assertNotEqual(len(results), all_menus.count()) | ||
self.assertEqual(len(results), default_menus.count()) | ||
self.assertNotIn(translated_menu, results) | ||
self.assertIn(self.menus[0], results) | ||
|
||
# Menu chooser should not contain locale filter | ||
self.assertNotContains(response, "id_locale") |
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