Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
399 additions
and
440 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
default_app_config = "misago.menus.apps.MisagoMenusConfig" | ||
|
||
MENU_LINKS_CACHE = "menus" | ||
MENU_ITEMS_CACHE = "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 |
---|---|---|
@@ -1,49 +1,47 @@ | ||
from django import forms | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from ..models import MenuLink | ||
from ...admin.forms import YesNoSwitch | ||
from ..models import MenuItem | ||
from ..cache import clear_menus_cache | ||
|
||
|
||
class MenuLinkForm(forms.ModelForm): | ||
link = forms.URLField( | ||
label=_("Link"), | ||
help_text=_("URL where the link should point to."), | ||
required=True, | ||
class MenuItemForm(forms.ModelForm): | ||
title = forms.CharField(label=_("Title")) | ||
url = forms.URLField( | ||
label=_("URL"), help_text=_("URL where this item will point to.") | ||
) | ||
title = forms.CharField( | ||
label=_("Title"), help_text=_("Title that will be used"), required=True | ||
) | ||
position = forms.ChoiceField( | ||
label=_("Position"), | ||
choices=MenuLink.LINK_POSITION_CHOICES, | ||
help_text=_("Position/s the link should be located"), | ||
menu = forms.ChoiceField( | ||
label=_("Menu"), | ||
choices=MenuItem.MENU_CHOICES, | ||
help_text=_("Menu in which this item will be displayed."), | ||
) | ||
css_class = forms.CharField( | ||
label=_("CSS Class"), | ||
help_text=_( | ||
"Optional CSS class used to customize this link appearance in templates." | ||
), | ||
label=_("CSS class"), | ||
help_text=_('If you want to set custom value for link\'s "class".'), | ||
required=False, | ||
) | ||
target = forms.CharField( | ||
label=_("Target"), | ||
target_blank = YesNoSwitch( | ||
label=_("Open this link in new window"), | ||
help_text=_( | ||
"Optional target attribute that this link will use (ex. '_blank')." | ||
'Enabling this option will result in the target="_blank" attribute being ' | ||
"added to this link's HTML element." | ||
), | ||
required=False, | ||
) | ||
rel = forms.CharField( | ||
label=_("Rel"), | ||
help_text=_("Optional rel attribute that this link will use (ex. 'nofollow')."), | ||
label=_("Rel attribute"), | ||
help_text=_( | ||
'Optional "rel" attribute that this item will use (ex. "nofollow").' | ||
), | ||
required=False, | ||
) | ||
|
||
class Meta: | ||
model = MenuLink | ||
fields = ["link", "title", "position", "css_class", "target", "rel"] | ||
model = MenuItem | ||
fields = ["title", "url", "menu", "css_class", "target_blank", "rel"] | ||
|
||
def save(self): | ||
link = super().save() | ||
item = super().save() | ||
clear_menus_cache() | ||
return link | ||
return item |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from ..models import MenuLink | ||
from ..models import MenuItem | ||
|
||
|
||
def get_next_free_order(): | ||
last = MenuLink.objects.last() | ||
last = MenuItem.objects.last() | ||
if last: | ||
return last.order + 1 | ||
return 0 |
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 |
---|---|---|
@@ -1,32 +1,29 @@ | ||
import pytest | ||
from django.urls import reverse | ||
|
||
from ...models import MenuLink | ||
from ...models import MenuItem | ||
|
||
|
||
@pytest.fixture | ||
def list_url(admin_client): | ||
return reverse("misago:admin:settings:links:index") | ||
return reverse("misago:admin:settings:menu-items:index") | ||
|
||
|
||
@pytest.fixture | ||
def menu_link(superuser): | ||
return MenuLink.objects.create( | ||
position=MenuLink.POSITION_TOP, | ||
def menu_item(superuser): | ||
return MenuItem.objects.create( | ||
menu=MenuItem.MENU_NAVBAR, | ||
title="Test TMLA", | ||
link="https://top_menu_link_admin.com", | ||
url="https://top_menu_item_admin.com", | ||
order=0, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def other_menu_link(superuser): | ||
return MenuLink.objects.create( | ||
position=MenuLink.POSITION_BOTH, | ||
title="Other Menu Link", | ||
link="https://other_menu_link.com", | ||
css_class="other-menu-link", | ||
rel="noopener noreferrer", | ||
target="_blank", | ||
def other_menu_item(superuser): | ||
return MenuItem.objects.create( | ||
menu=MenuItem.MENU_BOTH, | ||
title="Other Menu Item", | ||
url="https://other_menu_item.com", | ||
order=1, | ||
) |
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.