Skip to content

Commit b539fa7

Browse files
committed
Cleaned up the publish button logic on page toolbar
1 parent 647d92d commit b539fa7

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

cms/cms_toolbars.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from cms.api import get_page_draft, can_change_page
1313
from cms.constants import TEMPLATE_INHERITANCE_MAGIC, PUBLISHER_STATE_PENDING
1414
from cms.models import CMSPlugin, Title, Page
15-
from cms.toolbar.items import TemplateItem, REFRESH_PAGE
15+
from cms.toolbar.items import ButtonList, TemplateItem, REFRESH_PAGE
1616
from cms.toolbar_base import CMSToolbar
1717
from cms.toolbar_pool import toolbar_pool
1818
from cms.utils.i18n import get_language_tuple, force_language, get_language_dict, get_default_language
@@ -364,25 +364,30 @@ def has_dirty_objects(self):
364364
def add_publish_button(self, classes=('cms-btn-action', 'cms-btn-publish',)):
365365
# only do dirty lookups if publish permission is granted else button isn't added anyway
366366
if self.toolbar.edit_mode and self.has_publish_permission():
367-
classes = list(classes or [])
368-
dirty = self.has_dirty_objects()
367+
button = self.get_publish_button(classes=classes)
368+
self.toolbar.add_item(button)
369369

370-
if dirty:
371-
classes.append('cms-btn-publish-active')
370+
def get_publish_button(self, classes=None):
371+
dirty = self.has_dirty_objects()
372+
classes = list(classes or [])
372373

373-
if self.dirty_statics or (self.page and self.page.is_published(self.current_lang)):
374-
title = _('Publish page changes')
375-
else:
376-
title = _('Publish page now')
377-
classes.append('cms-publish-page')
378-
379-
self.toolbar.add_button(
380-
name=title,
381-
url=self.get_publish_url(),
382-
extra_classes=classes,
383-
side=self.toolbar.RIGHT,
384-
disabled=not dirty,
385-
)
374+
if dirty and 'cms-btn-publish-active' not in classes:
375+
classes.append('cms-btn-publish-active')
376+
377+
if self.dirty_statics or (self.page and self.page.is_published(self.current_lang)):
378+
title = _('Publish page changes')
379+
else:
380+
title = _('Publish page now')
381+
classes.append('cms-publish-page')
382+
383+
item = ButtonList(side=self.toolbar.RIGHT)
384+
item.add_button(
385+
title,
386+
url=self.get_publish_url(),
387+
disabled=not dirty,
388+
extra_classes=classes,
389+
)
390+
return item
386391

387392
def get_publish_url(self):
388393
pk = self.page.pk if self.page else 0

0 commit comments

Comments
 (0)