Skip to content

Commit

Permalink
Enabled cached plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Jun 28, 2016
1 parent 096e1d4 commit 7d28e08
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.rst
Expand Up @@ -14,6 +14,7 @@ History
* Added global and per site posts count to BlogCategory.
* Added option to hide empty categories from menu.
* Added standalone documentation at https://djangocms-blog.readthedocs.io.
* Enabled cached version of BlogLatestEntriesPlugin.

******************
0.8.5 (2016-06-26)
Expand Down
5 changes: 5 additions & 0 deletions cms_helper.py
Expand Up @@ -96,6 +96,11 @@ def gettext(s): return s
HAYSTACK_CONNECTIONS={
'default': {}
},
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
)

try:
Expand Down
3 changes: 2 additions & 1 deletion djangocms_blog/cms_plugins.py
Expand Up @@ -47,7 +47,7 @@ class BlogLatestEntriesPluginCached(BlogPlugin):
"""
Cached plugin which returns the latest published posts
"""
name = get_setting('LATEST_ENTRIES_PLUGIN_NAME')
name = get_setting('LATEST_ENTRIES_PLUGIN_NAME_CACHED')
model = LatestPostsPlugin
form = LatestEntriesForm
filter_horizontal = ('categories',)
Expand Down Expand Up @@ -121,6 +121,7 @@ def render(self, context, instance, placeholder):


plugin_pool.register_plugin(BlogLatestEntriesPlugin)
plugin_pool.register_plugin(BlogLatestEntriesPluginCached)
plugin_pool.register_plugin(BlogAuthorPostsPlugin)
plugin_pool.register_plugin(BlogTagsPlugin)
plugin_pool.register_plugin(BlogArchivePlugin)
Expand Down
2 changes: 2 additions & 0 deletions djangocms_blog/settings.py
Expand Up @@ -114,6 +114,8 @@ def get_setting(name):
'BLOG_PLUGIN_MODULE_NAME': getattr(settings, 'BLOG_PLUGIN_MODULE_NAME', _('Blog')),
'BLOG_LATEST_ENTRIES_PLUGIN_NAME': getattr(
settings, 'BLOG_LATEST_ENTRIES_PLUGIN_NAME', _('Latest Blog Articles')),
'BLOG_LATEST_ENTRIES_PLUGIN_NAME_CACHED': getattr(
settings, 'BLOG_LATEST_ENTRIES_PLUGIN_NAME_CACHED', _('Latest Blog Articles - Cache')),
'BLOG_AUTHOR_POSTS_PLUGIN_NAME': getattr(
settings, 'BLOG_AUTHOR_POSTS_PLUGIN_NAME', _('Author Blog Articles')),
'BLOG_TAGS_PLUGIN_NAME': getattr(
Expand Down
37 changes: 37 additions & 0 deletions tests/test_plugins.py
Expand Up @@ -17,6 +17,43 @@

class PluginTest(BaseTest):

def test_plugin_latest_cached(self):
pages = self.get_pages()
posts = self.get_posts()
posts[0].tags.add('tag 1')
posts[0].publish = True
posts[0].save()
ph = pages[0].placeholders.get(slot='content')

plugin = add_plugin(
ph, 'BlogLatestEntriesPluginCached', language='en', app_config=self.app_config_1
)
context = self.get_plugin_context(pages[0], 'en', plugin, edit=True)
rendered = plugin.render_plugin(context, ph)
try:
self.assertTrue(rendered.find('cms_plugin-djangocms_blog-post-abstract-1') > -1)
except AssertionError:
self.assertTrue(rendered.find('cms-plugin-djangocms_blog-post-abstract-1') > -1)
self.assertTrue(rendered.find('<p>first line</p>') > -1)
self.assertTrue(rendered.find('<article id="post-first-post"') > -1)
self.assertTrue(rendered.find(posts[0].get_absolute_url()) > -1)

plugin_nocache = add_plugin(
ph, 'BlogLatestEntriesPlugin', language='en', app_config=self.app_config_1
)
with self.assertNumQueries(53):
plugin_nocache.render_plugin(context, ph)

with self.assertNumQueries(17):
rendered = plugin.render_plugin(context, ph)
try:
self.assertTrue(rendered.find('cms_plugin-djangocms_blog-post-abstract-1') > -1)
except AssertionError:
self.assertTrue(rendered.find('cms-plugin-djangocms_blog-post-abstract-1') > -1)
self.assertTrue(rendered.find('<p>first line</p>') > -1)
self.assertTrue(rendered.find('<article id="post-first-post"') > -1)
self.assertTrue(rendered.find(posts[0].get_absolute_url()) > -1)

def test_plugin_latest(self):
pages = self.get_pages()
posts = self.get_posts()
Expand Down

0 comments on commit 7d28e08

Please sign in to comment.