from django.template import RequestContext
from django.http import HttpResponse, HttpResponseForbidden, Http404
+from django.http import HttpResponsePermanentRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.db import connection
from django.db.models import Q
r = HttpResponse(s, mimetype='text/plain')
r['Content-Length'] = len(s)
return r
+
+@cache(hours=8)
+def legacy(request, listname, year, month, msgnum):
+ curs = connection.cursor()
+ curs.execute("SELECT msgid FROM legacymap WHERE listid=(SELECT listid FROM lists WHERE listname=%(list)s) AND year=%(year)s AND month=%(month)s AND msgnum=%(msgnum)s", {
+ 'list': listname,
+ 'year': year,
+ 'month': month,
+ 'msgnum': msgnum,
+ })
+ r = curs.fetchall()
+ if len(r) != 1:
+ print "Meh, not found!"
+ raise Http404('Message does not exist')
+ return HttpResponsePermanentRedirect('/message-id/%s' % r[0][0])
(r'^message-id/attachment/(\d+)/.*$', 'archives.mailarchives.views.attachment'),
+ # Legacy forwarding from old archives site
+ (r'^message-id/legacy/([\w-]+)/(\d+)-(\d+)/msg(\d+).php$', 'archives.mailarchives.views.legacy'),
+
# Normally served by the webserver, but needed for development installs
(r'^media/(.*)$', 'django.views.static.serve', {
'document_root': '../media',
# Scan the old archives, including all subdirs, and generate
# a mapping table on the format:
-# <listname>;<year>;<month>;num;<messageid>
+# <listid>;<year>;<month>;num;<messageid>
# Used to map from the old site
FOR EACH ROW EXECUTE PROCEDURE messages_fti_trigger_func();
CREATE INDEX messages_fti_idx ON messages USING gin(fti);
+CREATE TABLE legacymap(
+ listid int not null,
+ year int not null,
+ month int not null,
+ msgnum int not null,
+ msgid text not null,
+CONSTRAINT legacymap_pk PRIMARY KEY (listid, year, month, msgnum)
+);
+
\echo Dont forget to commit!