diff --git a/flask_website/__init__.py b/flask_website/__init__.py new file mode 100644 index 00000000..13fa2ef1 --- /dev/null +++ b/flask_website/__init__.py @@ -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) diff --git a/static/logo.png b/flask_website/static/logo.png similarity index 100% rename from static/logo.png rename to flask_website/static/logo.png diff --git a/static/mailinglist.js b/flask_website/static/mailinglist.js similarity index 100% rename from static/mailinglist.js rename to flask_website/static/mailinglist.js diff --git a/static/mailinglist.png b/flask_website/static/mailinglist.png similarity index 100% rename from static/mailinglist.png rename to flask_website/static/mailinglist.png diff --git a/static/mask.png b/flask_website/static/mask.png similarity index 100% rename from static/mask.png rename to flask_website/static/mask.png diff --git a/static/ship.png b/flask_website/static/ship.png similarity index 100% rename from static/ship.png rename to flask_website/static/ship.png diff --git a/static/snippets.png b/flask_website/static/snippets.png similarity index 100% rename from static/snippets.png rename to flask_website/static/snippets.png diff --git a/static/style.css b/flask_website/static/style.css similarity index 100% rename from static/style.css rename to flask_website/static/style.css diff --git a/templates/404.html b/flask_website/templates/404.html similarity index 100% rename from templates/404.html rename to flask_website/templates/404.html diff --git a/templates/index.html b/flask_website/templates/general/index.html similarity index 100% rename from templates/index.html rename to flask_website/templates/general/index.html diff --git a/templates/layout.html b/flask_website/templates/layout.html similarity index 100% rename from templates/layout.html rename to flask_website/templates/layout.html diff --git a/templates/mailinglist/archive.html b/flask_website/templates/mailinglist/archive.html similarity index 86% rename from templates/mailinglist/archive.html rename to flask_website/templates/mailinglist/archive.html index 541d7287..c251aeb5 100644 --- a/templates/mailinglist/archive.html +++ b/flask_website/templates/mailinglist/archive.html @@ -13,13 +13,13 @@
- The mailinglist archive
+ The mailinglist archive
is synched every hour. Go there to read up old discussions grouped by
thread.
{% endblock %}
diff --git a/templates/mailinglist/layout.html b/flask_website/templates/mailinglist/layout.html
similarity index 100%
rename from templates/mailinglist/layout.html
rename to flask_website/templates/mailinglist/layout.html
diff --git a/templates/mailinglist/show_thread.html b/flask_website/templates/mailinglist/show_thread.html
similarity index 100%
rename from templates/mailinglist/show_thread.html
rename to flask_website/templates/mailinglist/show_thread.html
diff --git a/templates/snippets/index.html b/flask_website/templates/snippets/index.html
similarity index 100%
rename from templates/snippets/index.html
rename to flask_website/templates/snippets/index.html
diff --git a/templates/snippets/layout.html b/flask_website/templates/snippets/layout.html
similarity index 100%
rename from templates/snippets/layout.html
rename to flask_website/templates/snippets/layout.html
diff --git a/flask_website/views/__init__.py b/flask_website/views/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/flask_website/views/general.py b/flask_website/views/general.py
new file mode 100644
index 00000000..b0023d1e
--- /dev/null
+++ b/flask_website/views/general.py
@@ -0,0 +1,8 @@
+from flask import Module, render_template
+
+general = Module(__name__)
+
+
+@general.route('/')
+def index():
+ return render_template('general/index.html')
diff --git a/flask_website.py b/flask_website/views/mailinglist.py
similarity index 70%
rename from flask_website.py
rename to flask_website/views/mailinglist.py
index a65d3580..47bedc8a 100644
--- a/flask_website.py
+++ b/flask_website/views/mailinglist.py
@@ -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/