Converted app into a package

This commit is contained in:
Armin Ronacher 2010-05-02 16:52:15 +02:00
parent ef7818e10e
commit 904fe68d51
22 changed files with 49 additions and 35 deletions

View file

View file

@ -0,0 +1,8 @@
from flask import Module, render_template
general = Module(__name__)
@general.route('/')
def index():
return render_template('general/index.html')

View file

@ -0,0 +1,97 @@
from __future__ import with_statement
import os
from hashlib import md5
from werkzeug import parse_date
from jinja2.utils import urlize
from flask import Module, render_template, json, url_for, abort, Markup
mailinglist = Module(__name__)
THREADS_PER_PAGE = 15
MAILINGLIST_PATH = os.path.join(os.path.dirname(__file__), '..', '..', '_mailinglist')
class Mail(object):
def __init__(self, d):
self.msgid = d['msgid']
self.author_name, self.author_addr = d['author']
self.date = parse_date(d['date'])
self.subject = d['subject']
self.children = [Mail(x) for x in d['children']]
self.text = d['text']
@property
def rendered_text(self):
result = []
in_sig = False
for line in self.text.splitlines():
if line == u'-- ':
in_sig = True
if in_sig:
line = Markup(u'<span class=sig>%s</span>' % line)
elif line.startswith('>'):
line = Markup(u'<span class=quote>%s</span>' % line)
result.append(urlize(line))
return Markup(u'\n'.join(result))
@property
def id(self):
return md5(self.msgid.encode('utf-8')).hexdigest()
class Thread(object):
def __init__(self, d):
self.slug = d['slug'].rsplit('/', 1)[-1]
self.title = d['title']
self.reply_count = d['reply_count']
self.author_name, self.author_email = d['author']
self.date = parse_date(d['date'])
if 'root' in d:
self.root = Mail(d['root'])
@staticmethod
def get(year, month, day, slug):
try:
with open('%s/threads/%s-%02d-%02d/%s' %
(MAILINGLIST_PATH, year, month, day, slug)) as f:
return Thread(json.load(f))
except IOError:
pass
@staticmethod
def get_list():
with open('%s/threads/threadlist' % MAILINGLIST_PATH) as f:
return [Thread(x) for x in json.load(f)]
@property
def url(self):
return url_for('mailinglist.show_thread', year=self.date.year,
month=self.date.month, day=self.date.day,
slug=self.slug)
@mailinglist.route('/mailinglist/')
def index():
return render_template('mailinglist/index.html')
@mailinglist.route('/mailinglist/archive/', defaults={'page': 1})
@mailinglist.route('/mailinglist/archive/page/<int:page>/')
def archive(page):
all_threads = Thread.get_list()
offset = (page - 1) * THREADS_PER_PAGE
threads = all_threads[offset:offset + THREADS_PER_PAGE]
if page != 1 and not threads:
abort(404)
return render_template('mailinglist/archive.html',
page_count=len(threads) // THREADS_PER_PAGE + 1,
page=page, threads=threads)
@mailinglist.route('/mailinglist/archive/<int:year>/<int:month>/<int:day>/<slug>/')
def show_thread(year, month, day, slug):
thread = Thread.get(year, month, day, slug)
if thread is None:
abort(404)
return render_template('mailinglist/show_thread.html', thread=thread)

View file

@ -0,0 +1,8 @@
from flask import Module, render_template
snippets = Module(__name__, url_prefix='/snippets')
@snippets.route('/')
def index():
return render_template('snippets/index.html')