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):
|
||||
"""
|
||||
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'
|
||||
name = _('Latest Blog Articles')
|
||||
model = LatestPostsPlugin
|
||||
|
@ -24,7 +45,7 @@ class BlogLatestEntriesPlugin(BlogPlugin):
|
|||
|
||||
def render(self, context, instance, placeholder):
|
||||
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')
|
||||
return context
|
||||
|
||||
|
|
|
@ -224,10 +224,10 @@ class BasePostPlugin(CMSPlugin):
|
|||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def post_queryset(self, request):
|
||||
def post_queryset(self, request=None):
|
||||
language = get_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()
|
||||
return posts
|
||||
|
||||
|
|
Loading…
Reference in a new issue