From 41834f6bf931beb903cac8618a88cd5993910a9f Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 26 Jun 2016 12:48:40 +0200 Subject: [PATCH] Better plugin templates --- djangocms_blog/liveblog/cms_plugins.py | 7 +------ djangocms_blog/liveblog/models.py | 9 ++++++++- .../liveblog/templates/liveblog/plugins/liveblog.html | 2 ++ tests/test_liveblog.py | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/djangocms_blog/liveblog/cms_plugins.py b/djangocms_blog/liveblog/cms_plugins.py index 6c1895d..75a90ba 100644 --- a/djangocms_blog/liveblog/cms_plugins.py +++ b/djangocms_blog/liveblog/cms_plugins.py @@ -15,12 +15,7 @@ class LiveblogPlugin(TextPlugin): name = _('Liveblog item') model = Liveblog fields = ('title', 'body', 'publish') - - def _get_render_template(self, context, instance, placeholder): - if instance.publish: - return 'liveblog/plugins/liveblog.html' - else: - return 'liveblog/plugins/unpublished.html' + render_template = 'liveblog/plugins/liveblog.html' def render(self, context, instance, placeholder): context = super(LiveblogPlugin, self).render(context, instance, placeholder) diff --git a/djangocms_blog/liveblog/models.py b/djangocms_blog/liveblog/models.py index 0f50605..87fa8d1 100644 --- a/djangocms_blog/liveblog/models.py +++ b/djangocms_blog/liveblog/models.py @@ -4,7 +4,7 @@ from __future__ import absolute_import, print_function, unicode_literals import json from channels import Group -from cms.models import CMSPlugin +from cms.models import CMSPlugin, python_2_unicode_compatible from cms.utils.plugins import reorder_plugins from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -16,6 +16,7 @@ from djangocms_blog.models import Post, thumbnail_model DATE_FORMAT = "%a %d %b %Y %H:%M" +@python_2_unicode_compatible class LiveblogInterface(models.Model): """ Abstract Liveblog plugin model, reusable to customize the liveblogging plugins. @@ -31,6 +32,9 @@ class LiveblogInterface(models.Model): verbose_name_plural = _('liveblog entries') abstract = True + def __str__(self): + return str(self.pk) + def _post_save(self): if self.publish: self.send() @@ -85,3 +89,6 @@ class Liveblog(LiveblogInterface, AbstractText): def save(self, *args, **kwargs): super(Liveblog, self).save(*args, **kwargs) self._post_save() + + def __str__(self): + return AbstractText.__str__(self) diff --git a/djangocms_blog/liveblog/templates/liveblog/plugins/liveblog.html b/djangocms_blog/liveblog/templates/liveblog/plugins/liveblog.html index 402a2a5..2fdd5a6 100644 --- a/djangocms_blog/liveblog/templates/liveblog/plugins/liveblog.html +++ b/djangocms_blog/liveblog/templates/liveblog/plugins/liveblog.html @@ -1,5 +1,7 @@ +{% spaceless %}{% if instance.publish %}

{{ instance.title }}

{{ instance.creation_date|date:"D d M Y H:i" }}

{{ instance.content|safe }}
+{% endif %}{% endspaceless %} diff --git a/tests/test_liveblog.py b/tests/test_liveblog.py index 09ab014..e9b06ed 100644 --- a/tests/test_liveblog.py +++ b/tests/test_liveblog.py @@ -165,7 +165,7 @@ try: ) context = self.get_plugin_context(pages[0], 'en', plugin, edit=False) rendered = plugin.render_plugin(context, post.liveblog) - self.assertFalse(rendered) + self.assertFalse(rendered.strip()) plugin.publish = True plugin.save()