def _add_publish_button(self):
     """Helper method to add a publish button to the toolbar
     """
     # Only add the publish button if the content type is registered
     # with versioning
     if not self._is_versioned():
         return
     # Add the publish button if in edit mode
     if self.toolbar.edit_mode_active:
         item = ButtonList(side=self.toolbar.RIGHT)
         proxy_model = self._get_proxy_model()
         version = Version.objects.get_for_content(self.toolbar.obj)
         publish_url = reverse('admin:{app}_{model}_publish'.format(
             app=proxy_model._meta.app_label,
             model=proxy_model.__name__.lower(),
         ),
                               args=(version.pk, ))
         item.add_button(
             _('Publish'),
             url=publish_url,
             disabled=False,
             extra_classes=[
                 'cms-btn-action', 'cms-versioning-js-publish-btn'
             ],
         )
         self.toolbar.add_item(item)
Exemple #2
0
 def add_sideframe_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
                side=LEFT, position=None, on_close=None):
     self.populate()
     item = ButtonList(extra_classes=extra_wrapper_classes, side=side)
     item.add_sideframe_button(name, url, active=active, disabled=disabled, extra_classes=extra_classes, on_close=on_close)
     self.add_item(item, position=position)
     return item
Exemple #3
0
 def add_sideframe_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
                side=LEFT, position=None, on_close=None):
     self.populate()
     item = ButtonList(extra_classes=extra_wrapper_classes, side=side)
     item.add_sideframe_button(name, url, active=active, disabled=disabled, extra_classes=extra_classes, on_close=on_close)
     self.add_item(item, position=position)
     return item
Exemple #4
0
    def _add_toolbar_button(self, name, url, disabled=False):
        toolbar = self.request.toolbar
        button_list = ButtonList(side=toolbar.RIGHT)

        # TODO: Use button_list.add_modal_button() and generate the right response for page reload!
        # button_list.add_modal_button(
        button_list.add_button(
            name=name,
            url=url,
            disabled=disabled,
            extra_classes=('cms-btn-action',),
        )
        toolbar.add_item(button_list)
Exemple #5
0
 def _add_edit_button(self, disabled=False):
     """Helper method to add an edit button to the toolbar
     """
     item = ButtonList(side=self.toolbar.RIGHT)
     proxy_model = self._get_proxy_model()
     version = Version.objects.get_for_content(self.toolbar.obj)
     edit_url = reverse('admin:{app}_{model}_edit_redirect'.format(
         app=proxy_model._meta.app_label,
         model=proxy_model.__name__.lower(),
     ),
                        args=(version.pk, ))
     item.add_button(
         _('Edit'),
         url=edit_url,
         disabled=disabled,
         extra_classes=['cms-btn-action', 'cms-versioning-js-edit-btn'],
     )
     self.toolbar.add_item(item)
Exemple #6
0
 def add_button_list(self,
                     identifier=None,
                     extra_classes=None,
                     side=LEFT,
                     position=None):
     self.populate()
     item = ButtonList(identifier, extra_classes=extra_classes, side=side)
     self.add_item(item, position=position)
     return item
Exemple #7
0
    def get_publish_button(self, classes=None):
        dirty = self.has_dirty_objects()
        classes = list(classes or [])

        if dirty and 'cms-btn-publish-active' not in classes:
            classes.append('cms-btn-publish-active')

        if self.dirty_statics or (self.page and self.page.is_published(self.current_lang)):
            title = _('Publish page changes')
        else:
            title = _('Publish page now')
            classes.append('cms-publish-page')

        item = ButtonList(side=self.toolbar.RIGHT)
        item.add_button(
            title,
            url=self.get_publish_url(),
            disabled=not dirty,
            extra_classes=classes,
        )
        return item
Exemple #8
0
    def get_publish_button(self, classes=None):
        dirty = self.has_dirty_objects()
        classes = list(classes or [])

        if dirty and 'cms-btn-publish-active' not in classes:
            classes.append('cms-btn-publish-active')

        if self.dirty_statics or (self.page and self.page.is_published(self.current_lang)):
            title = _('Publish page changes')
        else:
            title = _('Publish page now')
            classes.append('cms-publish-page')

        item = ButtonList(side=self.toolbar.RIGHT)
        item.add_button(
            title,
            url=self.get_publish_url(),
            disabled=not dirty,
            extra_classes=classes,
        )
        return item
Exemple #9
0
    def inner(self, **kwargs):
        # Only run this if model is versioned and in content mode.
        if not self._is_versioned() or not self.toolbar.content_mode_active:
            return

        # Check whether current toolbar object has a version lock.
        if content_is_unlocked_for_user(self.toolbar.obj, self.request.user):
            # No version lock. Call original func to render edit button.
            func(self, **kwargs)
            return

        # There is a version lock for the current object.
        # Add a disabled edit button.
        item = ButtonList(side=self.toolbar.RIGHT)
        item.add_button(
            format_html(
                '<span style="vertical-align:middle;position:relative;top:-1px" class="cms-icon cms-icon-lock"></span>{name}',
                name=_('Edit'),
            ),
            url='javascript:void(0)',
            disabled=True,
            extra_classes=['cms-btn-action', 'cms-version-locking-btn-icon'],
        )
        self.toolbar.add_item(item)
    def inner(self, **kwargs):
        # Only run this if model is versioned and in content mode.
        if not self._is_versioned() or not self.toolbar.content_mode_active:
            return

        # Check whether current toolbar object has a version lock.
        if content_is_unlocked_for_user(self.toolbar.obj, self.request.user):
            # No version lock. Call original func to render edit button.
            func(self, **kwargs)
            return

        # Populate a title with the locked author details
        html_attributes = {}
        version_lock = get_lock_for_content(self.toolbar.obj)
        if version_lock:
            # If the users name is available use it, otherwise use their username
            html_attributes['title'] = _("Locked with {name}").format(
                name=version_lock.created_by.get_full_name()
                or version_lock.created_by.username, )

        # There is a version lock for the current object.
        # Add a disabled edit button.
        item_list = ButtonList(side=self.toolbar.RIGHT)
        button = ButtonWithAttributes(
            format_html(
                '<span style="vertical-align:middle;position:relative;top:-1px" '
                'class="cms-icon cms-icon-lock"></span>{name}',
                name=_('Edit'),
            ),
            url='javascript:void(0)',
            disabled=True,
            extra_classes=['cms-btn-action', 'cms-version-locking-btn-icon'],
            html_attributes=html_attributes,
        )
        item_list.buttons.append(button)
        self.toolbar.add_item(item_list)
    def add_publish_button(self,
                           classes=(
                               'cms-btn-action',
                               'cms-btn-publish',
                           )):
        log.debug(
            "Edit mode: %r - has_publish_permission: %r",
            self.toolbar.edit_mode,
            self.has_publish_permission(),
        )

        if self.page is None:
            log.debug("Don't add publish buttons, because self.page is None")
            return

        if self.current_request is not None:
            log.debug(
                "Replace default 'publish page' button with 'review request' button"
            )
            can_publish = self.current_request.check_object_publish_permission(
                self.request.user, raise_exception=False)
            if can_publish:
                log.debug("Add 'reply' button")
                url = self.current_request.admin_reply_url()

                button_list = ButtonList(side=self.toolbar.RIGHT)
                button_list.add_button(
                    name=_("Reply publish page request"),
                    url=url,
                    disabled=False,
                    extra_classes=('cms-btn-action', ),
                )
                self.toolbar.add_item(button_list)
            else:
                log.debug(
                    "User has not publish permission: Add 'history' button")
                url = self.current_request.admin_history_url()

                button_list = ButtonList(side=self.toolbar.RIGHT)
                button_list.add_button(
                    name=_("pending {action} {state}").format(
                        action=self.current_request.action_name,
                        state=self.current_request.state_name,
                    ),
                    url=url,
                    disabled=False,
                    extra_classes=('cms-btn-action', ),
                )
                self.toolbar.add_item(button_list)
            return

        if not self.toolbar.edit_mode:
            log.debug("Not in edit mode: don't add buttons, ok.")
            return

        button_list = None

        if self.has_publish_permission():
            log.debug(
                "User %s has CMS publish permission: Add default CMS buttons",
                self.request.user)

            log.debug(
                ("has_dirty_objects: %r"
                 " - dirty_statics: %r"
                 " - page.is_published: %r"), self.has_dirty_objects(),
                self.dirty_statics,
                (self.page and self.page.is_published(self.current_lang)))

            button_list = self.get_publish_button(classes=classes)

        else:
            log.debug("User %s has not CMS publish permissions, ok.",
                      self.request.user)

            if self.current_request is not None:
                # Should never happen, see: self.request_hook()
                raise SuspiciousOperation()

            button_list = self.create_button_list()
            if self.is_page_dirty():
                log.debug("Dirty: Add request button")
                self.add_button(
                    button_list,
                    title=_("Request page publishing"),
                    url=PublisherStateModel.objects.admin_request_publish_url(
                        obj=self.page),
                    disabled=False)
            else:
                log.debug("Not dirty: Don't add request button")

            has_public_version = self.page.publisher_public is not None
            log.debug("page.publisher_public: %r (has_public_version: %r)",
                      self.page.publisher_public, has_public_version)
            if has_public_version:
                log.debug("has public version: Add request unpublish button")
                self.add_button(button_list,
                                title=_("Request page unpublishing"),
                                url=PublisherStateModel.objects.
                                admin_request_unpublish_url(obj=self.page),
                                disabled=False)
            else:
                log.debug(
                    "page hasn't public version: Don't add request unpublish button"
                )

        if button_list is not None:
            self.toolbar.add_item(button_list)
 def create_button_list(self):
     button_list = ButtonList(side=self.toolbar.RIGHT)
     return button_list
Exemple #13
0
 def add_buttons(self):
     container = ButtonList(side=self.toolbar.RIGHT)
     container.buttons.append(self.get_undo_button())
     container.buttons.append(self.get_redo_button())
     self.toolbar.add_item(container)
Exemple #14
0
 def add_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
                side=LEFT, position=None):
     item = ButtonList(extra_classes=extra_wrapper_classes, side=side)
     item.add_button(name, url, active=active, disabled=disabled, extra_classes=extra_classes)
     self.add_item(item, position=position)
     return item
 def add_compare_button(self):
     # only do dirty lookups if compare permission is granted else button isn't added
     if self.toolbar.edit_mode and self.has_compare_permission():
         button_list = ButtonList(side=self.toolbar.RIGHT)
         self.add_button(button_list, Action.DIFF)
         self.toolbar.add_item(button_list)