Don't generate mbox links for months where there is no mbox file
authorMagnus Hagander <magnus@hagander.net>
Sat, 13 Apr 2013 15:10:02 +0000 (17:10 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 13 Apr 2013 15:10:02 +0000 (17:10 +0200)
This can happen because some emails are in the wrong mbox file based
on their date, so just generating the mbox linked based on which dates
are present in the database can generate extra links.

django/archives/mailarchives/templates/monthlist.html
django/archives/mailarchives/views.py
django/archives/settings.py

index 897bae024c1bacc5b3c9457dd36a78df9e54053e..599d14b47a2ca3b1edc931e25706b2fd29062afe 100644 (file)
@@ -11,7 +11,7 @@
  <li>{{year.grouper}}
   <ul>
    {%for month in year.list%}
-    <li><a href="/list/{{list.listname}}/{{month.year}}-{{month.month|stringformat:"02d"}}/">{{month.date|date:"F"}}</a> (<a href="/list/{{list.listname}}/mbox/{{list.listname}}.{{month.year}}{{month.month|stringformat:"02d"}}">mbox</a>)</li>
+    <li><a href="/list/{{list.listname}}/{{month.year}}-{{month.month|stringformat:"02d"}}/">{{month.date|date:"F"}}</a>{%if month.hasmbox%} (<a href="/list/{{list.listname}}/mbox/{{list.listname}}.{{month.year}}{{month.month|stringformat:"02d"}}">mbox</a>){%endif%}</li>
    {%endfor%}
   </ul>
  </li>
index 720b56ca634c438fa1cc3f48a022aa84884f592e..4d1ce3cf6b9ca2960a2dd04c45055badc6eb40f6 100644 (file)
@@ -102,12 +102,18 @@ def groupindex(request, groupid):
                        'groups': mygroups,
                        }, NavContext(request, all_groups=groups, expand_groupid=groupid))
 
+def _has_mbox(listname, year, month):
+       return os.path.isfile("%s/%s/files/public/archive/%s.%04d%02d" % (
+                       settings.MBOX_ARCHIVES_ROOT,
+                       listname,
+                       listname, year, month))
+
 @cache(hours=8)
 def monthlist(request, listname):
        l = get_object_or_404(List, listname=listname)
        curs = connection.cursor()
        curs.execute("SELECT year, month FROM list_months WHERE listid=%(listid)s ORDER BY year DESC, month DESC", {'listid': l.listid})
-       months=[{'year':r[0],'month':r[1], 'date':datetime(r[0],r[1],1) }for r in curs.fetchall()]
+       months=[{'year':r[0],'month':r[1], 'date':datetime(r[0],r[1],1), 'hasmbox': _has_mbox(listname, r[0], r[1])} for r in curs.fetchall()]
 
        return render_to_response('monthlist.html', {
                        'list': l,
index 25f13a4ceaadcc12343e1f82df5818112112c1a4..e468892ca07141e20a4b5fb4db0ecfea77fb2d55 100644 (file)
@@ -150,6 +150,9 @@ LOGGING = {
 # Required for lighttpd
 FORCE_SCRIPT_NAME=""
 
+# Always override!
+MBOX_ARCHIVES_ROOT="/dev/null"
+
 try:
        from settings_local import *
 except ImportError: