--- /dev/null
+{%extends "base.html"%}
+{%block title%}PostgreSQL Mailing Lists: {{list.listname}}{%endblock%}
+{%load pgfilters%}
+{%block layoutblock%}
+<h1>{{list.listname}}</h1>
+{%regroup months by year as yearmonth %}
+<ul>
+{%for year in yearmonth%}
+ <li>{{year.grouper}}
+ <ul>
+ {%for month in year.list%}
+ <li><a href="/{{list.listname}}/{{month.year}}-{{month.month|stringformat:"02d"}}/">{{month.date|date:"F"}}</a></li>
+ {%endfor%}
+ </ul>
+ </li>
+{%endfor%}
+</ul>
+{%endblock%}
from models import *
+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()]
+
+ return render_to_response('monthlist.html', {
+ 'list': l,
+ 'months': months,
+ })
+
def render_datelist_from(request, l, d, title):
mlist = Message.objects.select_related().filter(date__gte=d).extra(where=["threadid IN (SELECT threadid FROM list_threads WHERE listid=%s)" % l.listid]).order_by('date')[:200]
return render_to_response('datelist.html', {
(r'^test/oldsite/([^/]+)/$', 'archives.mailarchives.views.oldsite'),
(r'^message-id/([^/]+)/', 'archives.mailarchives.views.message'),
+ (r'^([\w-]+)/$', 'archives.mailarchives.views.monthlist'),
(r'^([\w-]+)/(\d+)-(\d+)/$', 'archives.mailarchives.views.datelist'),
(r'^([\w-]+)/since/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})', 'archives.mailarchives.views.datelistsincetime'),
(r'^([\w-]+)/since/([^/]+)/$', 'archives.mailarchives.views.datelistsince'),
def store(self, conn, listid):
curs = conn.cursor()
+
+ # Potentially add the information that there exists a mail for
+ # this month. We do that this early since we're always going to
+ # make the check anyway, and this keeps the code in one place..
+ curs.execute("INSERT INTO list_months (listid, year, month) SELECT %(listid)s, %(year)s, %(month)s WHERE NOT EXISTS (SELECT listid FROM list_months WHERE listid=%(listid)s AND year=%(year)s AND month=%(month)s)", {
+ 'listid': listid,
+ 'year': self.date.year,
+ 'month': self.date.month,
+ })
+
curs.execute("SELECT threadid, EXISTS(SELECT threadid FROM list_threads lt WHERE lt.listid=%(listid)s AND lt.threadid=m.threadid) FROM messages m WHERE m.messageid=%(messageid)s", {
'messageid': self.msgid,
'listid': listid,
--- /dev/null
+\set ON_ERROR_STOP
+BEGIN;
+
+TRUNCATE TABLE list_months;
+
+INSERT INTO list_months(listid, year, month)
+SELECT DISTINCT listid, EXTRACT(year FROM date), EXTRACT(month FROM date)
+FROM messages INNER JOIN list_threads ON messages.threadid=list_threads.threadid;
+
+COMMIT;
CREATE TABLE lists(
listid int NOT NULL PRIMARY KEY,
- listname text NOT NULL
+ listname text NOT NULL,
+);
+
+CREATE TABLE list_months(
+ listid int NOT NULL,
+ year int NOT NULL,
+ month int NOT NULL,
+ CONSTRAINT list_months_pk PRIMARY KEY (listid, year, month)
);
CREATE TABLE list_threads(