diff --git a/HISTORY.rst b/HISTORY.rst index 0bcac81..b7f7856 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,12 +3,13 @@ History ------- -0.6.4 (unreleased) +0.7.0 (unreleased) ++++++++++++++++++ * Make categories non required * Fix tests with parler>=1.6 * Use all_languages_column to admin +* Add publish button 0.6.3 (2015-12-22) ++++++++++++++++++ diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index 99df7c8..d811d73 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -7,9 +7,12 @@ from aldryn_apphooks_config.admin import BaseAppHookConfig, ModelAppHookConfig from cms.admin.placeholderadmin import FrontendEditableAdminMixin, PlaceholderAdminMixin from django import forms from django.conf import settings +from django.conf.urls import url from django.contrib import admin +from django.core.urlresolvers import reverse, resolve +from django.http import HttpResponseRedirect from django.utils.six import callable -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, get_language_from_request from parler.admin import TranslatableAdmin from .cms_appconfig import BlogConfig @@ -73,6 +76,27 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin, 'default_published': 'publish' } + def get_urls(self): + urls = [ + url(r'^publish/([0-9]+)/$', self.admin_site.admin_view(self.publish_post), + name='djangocms_blog_publish_article'), + ] + urls.extend(super(PostAdmin, self).get_urls()) + return urls + + def publish_post(self, request, pk): + language = get_language_from_request(request, check_path=True) + try: + post = Post.objects.get(pk=int(pk)) + post.publish = True + post.save() + return HttpResponseRedirect(post.get_absolute_url(language)) + except Exception: + try: + return HttpResponseRedirect(request.META['HTTP_REFERER']) + except KeyError: + return HttpResponseRedirect(reverse('djangocms_blog:posts-latest')) + def languages(self, obj): return ','.join(obj.get_available_languages()) diff --git a/djangocms_blog/cms_toolbar.py b/djangocms_blog/cms_toolbar.py index b5d5d85..9892ed5 100644 --- a/djangocms_blog/cms_toolbar.py +++ b/djangocms_blog/cms_toolbar.py @@ -3,6 +3,8 @@ from __future__ import absolute_import, print_function, unicode_literals from cms.toolbar_base import CMSToolbar from cms.toolbar_pool import toolbar_pool +from cms.utils.i18n import force_language +from cms.utils.urlutils import admin_reverse, add_url_parameters from django.core.urlresolvers import reverse from django.utils.translation import override, ugettext_lazy as _ @@ -33,6 +35,19 @@ class BlogToolbar(CMSToolbar): 'admin:djangocms_blog_post_change', args=(current_post.pk,)), active=True) + def add_publish_button(self): + current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) + if (self.toolbar.edit_mode and current_post and + not current_post.publish and + self.request.user.has_perm('djangocms_blog.change_post') + ): # pragma: no cover # NOQA + classes = ['cms-btn-action', 'blog-publish'] + title = _('Publish {0} now').format(current_post.app_config.object_name) + + url = admin_reverse('djangocms_blog_publish_article', args=(current_post.pk,)) + + self.toolbar.add_button(title, url=url, extra_classes=classes, side=self.toolbar.RIGHT) + def post_template_populate(self): current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover # NOQA @@ -52,3 +67,4 @@ class BlogToolbar(CMSToolbar): menu.remove_item(pagetags) except ImportError: pass + self.add_publish_button()