Better plugin templates

This commit is contained in:
Iacopo Spalletti 2016-06-26 12:48:40 +02:00
parent abf2c1bb61
commit 41834f6bf9
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
4 changed files with 12 additions and 8 deletions

View file

@ -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)

View file

@ -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)

View file

@ -1,5 +1,7 @@
{% spaceless %}{% if instance.publish %}
<div class="post" data-post-id="{{ instance.id }}">
<h3>{{ instance.title }}</h3>
<h4>{{ instance.creation_date|date:"D d M Y H:i" }}</h4>
{{ instance.content|safe }}
</div>
{% endif %}{% endspaceless %}

View file

@ -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()