#NEWLINE# @ register . as_tag #NEWLINE# def blog_months( * args ) : #NEWLINE# #INDENT# '\n    Put a list of dates for blog posts into the template context.\n    ' #NEWLINE# dates = BlogPost . objects . published ( ) . values_list ( 'publish_date' , flat = True ) #NEWLINE# date_dicts = [ { #NEWLINE# #INDENT# 'date' : datetime ( d . year , d . month , 1 ) , #NEWLINE# #UNINDENT# } for d in dates ] #NEWLINE# month_dicts = [ ] #NEWLINE# for date_dict in date_dicts : #NEWLINE# #INDENT# if ( date_dict not in month_dicts ) : #NEWLINE# #INDENT# month_dicts . append ( date_dict ) #NEWLINE# #UNINDENT# #UNINDENT# for ( i , date_dict ) in enumerate ( month_dicts ) : #NEWLINE# #INDENT# month_dicts [ i ] [ 'post_count' ] = date_dicts . count ( date_dict ) #NEWLINE# #UNINDENT# return args