summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Yves Chibon <pingou@pingoured.fr>2012-03-19 20:17:07 +0100
committerPierre-Yves Chibon <pingou@pingoured.fr>2012-03-19 20:17:07 +0100
commit8fb918a69cfdbf62245397c1c298935f454021e4 (patch)
treea4d9a2c773b73f263ef69c8607f9114b39e246a9
parent6d634c00f71bad36006cad5766f913f649d6c1b3 (diff)
downloadhyperkitty-8fb918a69cfdbf62245397c1c298935f454021e4.tar.gz
hyperkitty-8fb918a69cfdbf62245397c1c298935f454021e4.tar.xz
hyperkitty-8fb918a69cfdbf62245397c1c298935f454021e4.zip
Let's try another way of getting for how long the archives are available
-rw-r--r--lib/mongo.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/mongo.py b/lib/mongo.py
index 8d71636..2ea0148 100644
--- a/lib/mongo.py
+++ b/lib/mongo.py
@@ -3,6 +3,7 @@
import pymongo
import re
from bunch import Bunch
+from datetime import datetime
connection = pymongo.Connection('localhost', 27017)
@@ -76,13 +77,16 @@ def get_archives_length(table):
db.mails.create_index('Date')
db.mails.ensure_index('Date')
archives = {}
- for date in db.mails.distinct('Date'):
- if date.year in archives:
- archives[date.year].add(date.month)
- else:
- archives[date.year] = set([date.month])
- for key in archives:
- archives[key] = list(archives[key])
+ entry = db.mails.find_one(sort=[('Date', pymongo.ASCENDING)])
+ date = entry['Date']
+ now = datetime.now()
+ year = date.year
+ month = date.month
+ while year < now.year:
+ archives[year] = range(1,13)[(month -1):]
+ year = year + 1
+ month = 1
+ archives[now.year] = range(1,13)[:now.month]
return archives