Merge pull request #64 from nephila/fix/plugins
If using the request to filter posts, plugin cannot be cached
This commit is contained in:
commit
eaae535896
2 changed files with 24 additions and 3 deletions
|
@ -15,7 +15,28 @@ class BlogPlugin(CMSPluginBase):
|
||||||
|
|
||||||
|
|
||||||
class BlogLatestEntriesPlugin(BlogPlugin):
|
class BlogLatestEntriesPlugin(BlogPlugin):
|
||||||
|
"""
|
||||||
|
Non cached plugin which returns the latest posts taking into account the
|
||||||
|
user / toolbar state
|
||||||
|
"""
|
||||||
|
render_template = 'djangocms_blog/plugins/latest_entries.html'
|
||||||
|
name = _('Latest Blog Articles')
|
||||||
|
model = LatestPostsPlugin
|
||||||
|
form = LatestEntriesForm
|
||||||
|
filter_horizontal = ('categories',)
|
||||||
|
cache = False
|
||||||
|
|
||||||
|
def render(self, context, instance, placeholder):
|
||||||
|
context['instance'] = instance
|
||||||
|
context['posts_list'] = instance.get_posts(context['request'])
|
||||||
|
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class BlogLatestEntriesPluginCached(BlogPlugin):
|
||||||
|
"""
|
||||||
|
Cached plugin which returns the latest published posts
|
||||||
|
"""
|
||||||
render_template = 'djangocms_blog/plugins/latest_entries.html'
|
render_template = 'djangocms_blog/plugins/latest_entries.html'
|
||||||
name = _('Latest Blog Articles')
|
name = _('Latest Blog Articles')
|
||||||
model = LatestPostsPlugin
|
model = LatestPostsPlugin
|
||||||
|
@ -24,7 +45,7 @@ class BlogLatestEntriesPlugin(BlogPlugin):
|
||||||
|
|
||||||
def render(self, context, instance, placeholder):
|
def render(self, context, instance, placeholder):
|
||||||
context['instance'] = instance
|
context['instance'] = instance
|
||||||
context['posts_list'] = instance.get_posts(context['request'])
|
context['posts_list'] = instance.get_posts()
|
||||||
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
|
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
|
@ -224,10 +224,10 @@ class BasePostPlugin(CMSPlugin):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def post_queryset(self, request):
|
def post_queryset(self, request=None):
|
||||||
language = get_language()
|
language = get_language()
|
||||||
posts = Post._default_manager.active_translations(language_code=language)
|
posts = Post._default_manager.active_translations(language_code=language)
|
||||||
if not getattr(request, 'toolbar', False) or not request.toolbar.edit_mode:
|
if not request or not getattr(request, 'toolbar', False) or not request.toolbar.edit_mode:
|
||||||
posts = posts.published()
|
posts = posts.published()
|
||||||
return posts
|
return posts
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue