Ticket #64 (new enhancement)

Opened 5 months ago

Last modified 5 months ago

Advanced "show last comments" in sidebar.

Reported by: igorekk Assigned to:
Priority: major Milestone:
Component: blog Version:
Keywords: comments Cc:

Description

If we want show last commented posts:

Add to settings.py

ADVANCED_COMMENTS_COUNT=True

Add to apps/blog/templatetags/sidebar.py

def sidebar(context):
    if settings.ADVANCED_COMMENTS_COUNT:
	cursor = connection.cursor()
	cursor.execute("select max(comment_nodes.id) from comment_nodes where approved = 1 group by comment_nodes.object_id order by comment_nodes.pub_date desc limit 5")
	comments=CommentNode.objects.select_related().extra(where=['comment_nodes.id in (%s)'%(','.join([str(m[0]) for m in cursor.fetchall()]))])
    else:
        comments = CommentNode.objects.filter(approved=True).select_related().order_by('-pub_date')[:5] 
	last_posts = Post.objects.all().order_by('-date')[:5]
    # TODO: return all variables from RequestContext dictionary
    return {'STATIC_URL': context['STATIC_URL'], 'request': context['request'], 'last_posts': last_posts, 'comments': comments} 

Change History

04/07/08 09:40:47 changed by igorekk

  • type changed from defect to enhancement.
Ohloh project report for byteflow