Better plugin templates
This commit is contained in:
parent
abf2c1bb61
commit
41834f6bf9
4 changed files with 12 additions and 8 deletions
|
@ -15,12 +15,7 @@ class LiveblogPlugin(TextPlugin):
|
||||||
name = _('Liveblog item')
|
name = _('Liveblog item')
|
||||||
model = Liveblog
|
model = Liveblog
|
||||||
fields = ('title', 'body', 'publish')
|
fields = ('title', 'body', 'publish')
|
||||||
|
render_template = 'liveblog/plugins/liveblog.html'
|
||||||
def _get_render_template(self, context, instance, placeholder):
|
|
||||||
if instance.publish:
|
|
||||||
return 'liveblog/plugins/liveblog.html'
|
|
||||||
else:
|
|
||||||
return 'liveblog/plugins/unpublished.html'
|
|
||||||
|
|
||||||
def render(self, context, instance, placeholder):
|
def render(self, context, instance, placeholder):
|
||||||
context = super(LiveblogPlugin, self).render(context, instance, placeholder)
|
context = super(LiveblogPlugin, self).render(context, instance, placeholder)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from channels import Group
|
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 cms.utils.plugins import reorder_plugins
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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"
|
DATE_FORMAT = "%a %d %b %Y %H:%M"
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class LiveblogInterface(models.Model):
|
class LiveblogInterface(models.Model):
|
||||||
"""
|
"""
|
||||||
Abstract Liveblog plugin model, reusable to customize the liveblogging plugins.
|
Abstract Liveblog plugin model, reusable to customize the liveblogging plugins.
|
||||||
|
@ -31,6 +32,9 @@ class LiveblogInterface(models.Model):
|
||||||
verbose_name_plural = _('liveblog entries')
|
verbose_name_plural = _('liveblog entries')
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.pk)
|
||||||
|
|
||||||
def _post_save(self):
|
def _post_save(self):
|
||||||
if self.publish:
|
if self.publish:
|
||||||
self.send()
|
self.send()
|
||||||
|
@ -85,3 +89,6 @@ class Liveblog(LiveblogInterface, AbstractText):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Liveblog, self).save(*args, **kwargs)
|
super(Liveblog, self).save(*args, **kwargs)
|
||||||
self._post_save()
|
self._post_save()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return AbstractText.__str__(self)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
{% spaceless %}{% if instance.publish %}
|
||||||
<div class="post" data-post-id="{{ instance.id }}">
|
<div class="post" data-post-id="{{ instance.id }}">
|
||||||
<h3>{{ instance.title }}</h3>
|
<h3>{{ instance.title }}</h3>
|
||||||
<h4>{{ instance.creation_date|date:"D d M Y H:i" }}</h4>
|
<h4>{{ instance.creation_date|date:"D d M Y H:i" }}</h4>
|
||||||
{{ instance.content|safe }}
|
{{ instance.content|safe }}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}{% endspaceless %}
|
||||||
|
|
|
@ -165,7 +165,7 @@ try:
|
||||||
)
|
)
|
||||||
context = self.get_plugin_context(pages[0], 'en', plugin, edit=False)
|
context = self.get_plugin_context(pages[0], 'en', plugin, edit=False)
|
||||||
rendered = plugin.render_plugin(context, post.liveblog)
|
rendered = plugin.render_plugin(context, post.liveblog)
|
||||||
self.assertFalse(rendered)
|
self.assertFalse(rendered.strip())
|
||||||
|
|
||||||
plugin.publish = True
|
plugin.publish = True
|
||||||
plugin.save()
|
plugin.save()
|
||||||
|
|
Loading…
Reference in a new issue