Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve displaying menu item info
Anna Siwikf461bbeb22cf
diff --git a/saleor/dashboard/menu/forms.py b/saleor/dashboard/menu/forms.pyindex f5322eea18..781cce9487 100644--- a/saleor/dashboard/menu/forms.py+++ b/saleor/dashboard/menu/forms.py@@ -36,10 +36,10 @@ class MenuItemForm(forms.ModelForm):def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)- dest = self.instance.destination- if dest:- obj_id = str(dest.pk) + '_' + dest.__class__.__name__- self.fields['linked_object'].set_initial(dest, obj_id=obj_id)+ obj = self.instance.linked_object+ if obj:+ obj_id = str(obj.pk) + '_' + obj.__class__.__name__+ self.fields['linked_object'].set_initial(obj, obj_id=obj_id)def clean(self):url = self.cleaned_data.get('url')diff --git a/saleor/menu/models.py b/saleor/menu/models.pyindex 7b071df79a..13de4eab43 100644--- a/saleor/menu/models.py+++ b/saleor/menu/models.py@@ -67,24 +67,29 @@ class MenuItem(MPTTModel):super().save(*args, **kwargs)@property- def destination(self):+ def linked_object(self):return self.category or self.collection or self.page- def get_destination_display(self):- dest = self.destination- prefix = ''+ @property+ def destination_display(self):+ linked_object = self.linked_object- if not dest:- return prefix+ if not linked_object:+ prefix = pgettext_lazy('Link object type description', 'URL: ')+ return prefix + self.url- if dest.__class__ == Collection:+ if linked_object.__class__ == Collection:prefix = pgettext_lazy('Link object type description', 'Collection: ')- elif dest.__class__ == Category:+ elif linked_object.__class__ == Category:prefix = pgettext_lazy('Link object type description', 'Category: ')- elif dest.__class__ == Page:+ else:prefix = pgettext_lazy('Link object type description', 'Page: ')- return prefix + str(dest)+ return prefix + str(linked_object)++ def get_url(self):+ linked_object = self.linked_object+ return linked_object.get_absolute_url() if linked_object else self.urldiff --git a/templates/dashboard/includes/_menu_items.html b/templates/dashboard/includes/_menu_items.htmlindex 494a003f04..3a675ab7fc 100644--- a/templates/dashboard/includes/_menu_items.html+++ b/templates/dashboard/includes/_menu_items.html@@ -27,9 +27,6 @@{% trans "Points to" context "Menu items list table header points to" as label %}{% sorting_header 'destination' label %}- {% trans "URL" context "Menu items list table header URL" as label %}- {% sorting_header 'url' label %}-{% if perms.menu.edit_menu %}<th></th>{% endif %}@@ -47,10 +44,7 @@{{ item.name }}</td><td>- {{ item.get_destination_display }}- </td>- <td>- {{ item.url }}+ {{ item.destination_display }}</td>{% if perms.menu.edit_menu %}<td class="right-align ignore-link">diff --git a/templates/dashboard/menu/item/detail.html b/templates/dashboard/menu/item/detail.htmlindex 125107dcfe..1f663ad4e4 100644--- a/templates/dashboard/menu/item/detail.html+++ b/templates/dashboard/menu/item/detail.html@@ -68,24 +68,14 @@{{ menu_item.name }}</span><div class="row">- <div class="col s12 m6">+ <div class="col s12"><h4>{% trans "Points to" context "Menu item field" %}</h4>- {% if menu_item.destination %}- <p>- <a href="{{ menu_item.destination.get_absolute_url }}" target="_blank">- {{ menu_item.get_destination_display }}- </a>- </p>- {% endif %}- </div>- <div class="col s12 m6">- <h4>- {% trans "URL" context "Menu item field" %}- </h4><p>- {{ menu_item.url }}+ <a href="{{ menu_item.get_url }}" target="_blank">+ {{ menu_item.destination_display }}+ </a></p></div></div>