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

14
flask_website/__init__.py Normal file
View file

@ -0,0 +1,14 @@
from flask import Flask, render_template
app = Flask(__name__)
@app.errorhandler(404)
def not_found(error):
return render_template('404.html'), 404
from flask_website.views.general import general
from flask_website.views.mailinglist import mailinglist
from flask_website.views.snippets import snippets
app.register_module(general)
app.register_module(mailinglist)
app.register_module(snippets)

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Before After
Before After

View file

@ -13,13 +13,13 @@
</ul>
<div class=pagination>
{% if page > 1 %}
<a href="{{ url_for('mailinglist_archive', page=page - 1) }}">&laquo; Previous</a>
<a href="{{ url_for('mailinglist.archive', page=page - 1) }}">&laquo; Previous</a>
{% else %}
<span class=disabled>&laquo; Previous</span>
{% endif %}
| <strong>{{ page }}</strong> |
{% if page < page_count %}
<a href="{{ url_for('mailinglist_archive', page=page + 1) }}">Next &raquo;</a>
<a href="{{ url_for('mailinglist.archive', page=page + 1) }}">Next &raquo;</a>
{% else %}
<span class=disabled>Next &raquo;</span>
{% endif %}

View file

@ -14,7 +14,7 @@
confirmation mail.
<p>
The <a href="{{ url_for('mailinglist_archive') }}">mailinglist archive</a>
The <a href="{{ url_for('mailinglist.archive') }}">mailinglist archive</a>
is synched every hour. Go there to read up old discussions grouped by
thread.
{% endblock %}

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

@ -1,12 +1,13 @@
from __future__ import with_statement
import os
from hashlib import md5
from werkzeug import parse_date
from flask import Flask, render_template, json, url_for, abort, Markup
from jinja2.utils import urlize
app = Flask(__name__)
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):
@ -52,37 +53,32 @@ class Thread(object):
@staticmethod
def get(year, month, day, slug):
try:
with app.open_resource('_mailinglist/threads/%s-%02d-%02d/%s' %
(year, month, day, slug)) as f:
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 app.open_resource('_mailinglist/threads/threadlist') as f:
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,
return url_for('mailinglist.show_thread', year=self.date.year,
month=self.date.month, day=self.date.day,
slug=self.slug)
@app.route('/')
@mailinglist.route('/mailinglist/')
def index():
return render_template('index.html')
@app.route('/mailinglist/')
def mailinglist_index():
return render_template('mailinglist/index.html')
@app.route('/mailinglist/archive/', defaults={'page': 1})
@app.route('/mailinglist/archive/page/<int:page>/')
def mailinglist_archive(page):
@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]
@ -93,23 +89,9 @@ def mailinglist_archive(page):
page=page, threads=threads)
@app.route('/mailinglist/archive/<int:year>/<int:month>/<int:day>/<slug>/')
def mailinglist_show_thread(year, month, day, slug):
@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)
@app.route('/snippets/')
def snippets():
return render_template('snippets/index.html')
@app.errorhandler(404)
def not_found(error):
return render_template('404.html'), 404
if __name__ == '__main__':
app.run(debug=True)

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')

2
run.py Normal file
View file

@ -0,0 +1,2 @@
from flask_website import app
app.run(debug=True)