Skip to content

Commit

Permalink
Converted app into a package
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed May 2, 2010
1 parent ef7818e commit 904fe68
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 35 deletions.
14 changes: 14 additions & 0 deletions flask_website/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ <h2>Mailinglist Archive</h2>
</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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added flask_website/views/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions flask_website/views/general.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Module, render_template

general = Module(__name__)


@general.route('/')
def index():
return render_template('general/index.html')
46 changes: 14 additions & 32 deletions flask_website.py → flask_website/views/mailinglist.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -52,37 +53,32 @@ def __init__(self, d):
@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]
Expand All @@ -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)
8 changes: 8 additions & 0 deletions flask_website/views/snippets.py
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from flask_website import app
app.run(debug=True)

0 comments on commit 904fe68

Please sign in to comment.