Created
December 15, 2011 11:27
-
-
Save mikeywaites/1480779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_archives(self): | |
""" get all post objects grouped by year/month """ | |
archives = {} | |
posts = self.active(Post.ACTIVE).published().order_by('-publish_date') | |
for p in posts: | |
year = p.publish_date.year | |
month = p.publish_date.month | |
try: | |
archives[year][month-1][1]=True | |
except KeyError: | |
# catch the KeyError, and set up list for that year | |
archives[year]=[[datetime.date(year,m,1),False, 0] for m in xrange(1,13)] | |
archives[year][month-1][1]=True | |
if archives[year][month-1][1] == True: | |
archives[year][month-1][2] +=1 | |
for year in archives: | |
archives[year].sort(reverse=True) | |
archives = sorted(archives.items(),reverse=True) | |
return archives |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment