Enabled cached plugin

This commit is contained in:
Iacopo Spalletti 2016-06-28 08:56:53 +02:00
commit 7d28e08f58
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
5 changed files with 47 additions and 1 deletions

View file

@ -14,6 +14,7 @@ History
* Added global and per site posts count to BlogCategory. * Added global and per site posts count to BlogCategory.
* Added option to hide empty categories from menu. * Added option to hide empty categories from menu.
* Added standalone documentation at https://djangocms-blog.readthedocs.io. * Added standalone documentation at https://djangocms-blog.readthedocs.io.
* Enabled cached version of BlogLatestEntriesPlugin.
****************** ******************
0.8.5 (2016-06-26) 0.8.5 (2016-06-26)

View file

@ -96,6 +96,11 @@ HELPER_SETTINGS = dict(
HAYSTACK_CONNECTIONS={ HAYSTACK_CONNECTIONS={
'default': {} 'default': {}
}, },
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
) )
try: try:

View file

@ -47,7 +47,7 @@ class BlogLatestEntriesPluginCached(BlogPlugin):
""" """
Cached plugin which returns the latest published posts 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 model = LatestPostsPlugin
form = LatestEntriesForm form = LatestEntriesForm
filter_horizontal = ('categories',) filter_horizontal = ('categories',)
@ -121,6 +121,7 @@ class BlogArchivePlugin(BlogPlugin):
plugin_pool.register_plugin(BlogLatestEntriesPlugin) plugin_pool.register_plugin(BlogLatestEntriesPlugin)
plugin_pool.register_plugin(BlogLatestEntriesPluginCached)
plugin_pool.register_plugin(BlogAuthorPostsPlugin) plugin_pool.register_plugin(BlogAuthorPostsPlugin)
plugin_pool.register_plugin(BlogTagsPlugin) plugin_pool.register_plugin(BlogTagsPlugin)
plugin_pool.register_plugin(BlogArchivePlugin) plugin_pool.register_plugin(BlogArchivePlugin)

View file

@ -114,6 +114,8 @@ def get_setting(name):
'BLOG_PLUGIN_MODULE_NAME': getattr(settings, 'BLOG_PLUGIN_MODULE_NAME', _('Blog')), 'BLOG_PLUGIN_MODULE_NAME': getattr(settings, 'BLOG_PLUGIN_MODULE_NAME', _('Blog')),
'BLOG_LATEST_ENTRIES_PLUGIN_NAME': getattr( 'BLOG_LATEST_ENTRIES_PLUGIN_NAME': getattr(
settings, 'BLOG_LATEST_ENTRIES_PLUGIN_NAME', _('Latest Blog Articles')), 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( 'BLOG_AUTHOR_POSTS_PLUGIN_NAME': getattr(
settings, 'BLOG_AUTHOR_POSTS_PLUGIN_NAME', _('Author Blog Articles')), settings, 'BLOG_AUTHOR_POSTS_PLUGIN_NAME', _('Author Blog Articles')),
'BLOG_TAGS_PLUGIN_NAME': getattr( 'BLOG_TAGS_PLUGIN_NAME': getattr(

View file

@ -17,6 +17,43 @@ from .base import BaseTest
class PluginTest(BaseTest): 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): def test_plugin_latest(self):
pages = self.get_pages() pages = self.get_pages()
posts = self.get_posts() posts = self.get_posts()