Converted app into a package
14
flask_website/__init__.py
Normal 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)
|
||||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
|
@ -13,13 +13,13 @@
|
||||||
</ul>
|
</ul>
|
||||||
<div class=pagination>
|
<div class=pagination>
|
||||||
{% if page > 1 %}
|
{% if page > 1 %}
|
||||||
<a href="{{ url_for('mailinglist_archive', page=page - 1) }}">« Previous</a>
|
<a href="{{ url_for('mailinglist.archive', page=page - 1) }}">« Previous</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class=disabled>« Previous</span>
|
<span class=disabled>« Previous</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
| <strong>{{ page }}</strong> |
|
| <strong>{{ page }}</strong> |
|
||||||
{% if page < page_count %}
|
{% if page < page_count %}
|
||||||
<a href="{{ url_for('mailinglist_archive', page=page + 1) }}">Next »</a>
|
<a href="{{ url_for('mailinglist.archive', page=page + 1) }}">Next »</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class=disabled>Next »</span>
|
<span class=disabled>Next »</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
confirmation mail.
|
confirmation mail.
|
||||||
|
|
||||||
<p>
|
<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
|
is synched every hour. Go there to read up old discussions grouped by
|
||||||
thread.
|
thread.
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
0
flask_website/views/__init__.py
Normal file
8
flask_website/views/general.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
from flask import Module, render_template
|
||||||
|
|
||||||
|
general = Module(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@general.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('general/index.html')
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
import os
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from werkzeug import parse_date
|
from werkzeug import parse_date
|
||||||
from flask import Flask, render_template, json, url_for, abort, Markup
|
|
||||||
from jinja2.utils import urlize
|
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
|
THREADS_PER_PAGE = 15
|
||||||
|
MAILINGLIST_PATH = os.path.join(os.path.dirname(__file__), '..', '..', '_mailinglist')
|
||||||
|
|
||||||
|
|
||||||
class Mail(object):
|
class Mail(object):
|
||||||
|
|
@ -52,37 +53,32 @@ class Thread(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(year, month, day, slug):
|
def get(year, month, day, slug):
|
||||||
try:
|
try:
|
||||||
with app.open_resource('_mailinglist/threads/%s-%02d-%02d/%s' %
|
with open('%s/threads/%s-%02d-%02d/%s' %
|
||||||
(year, month, day, slug)) as f:
|
(MAILINGLIST_PATH, year, month, day, slug)) as f:
|
||||||
return Thread(json.load(f))
|
return Thread(json.load(f))
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_list():
|
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)]
|
return [Thread(x) for x in json.load(f)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
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,
|
month=self.date.month, day=self.date.day,
|
||||||
slug=self.slug)
|
slug=self.slug)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@mailinglist.route('/mailinglist/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/mailinglist/')
|
|
||||||
def mailinglist_index():
|
|
||||||
return render_template('mailinglist/index.html')
|
return render_template('mailinglist/index.html')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/mailinglist/archive/', defaults={'page': 1})
|
@mailinglist.route('/mailinglist/archive/', defaults={'page': 1})
|
||||||
@app.route('/mailinglist/archive/page/<int:page>/')
|
@mailinglist.route('/mailinglist/archive/page/<int:page>/')
|
||||||
def mailinglist_archive(page):
|
def archive(page):
|
||||||
all_threads = Thread.get_list()
|
all_threads = Thread.get_list()
|
||||||
offset = (page - 1) * THREADS_PER_PAGE
|
offset = (page - 1) * THREADS_PER_PAGE
|
||||||
threads = all_threads[offset:offset + THREADS_PER_PAGE]
|
threads = all_threads[offset:offset + THREADS_PER_PAGE]
|
||||||
|
|
@ -93,23 +89,9 @@ def mailinglist_archive(page):
|
||||||
page=page, threads=threads)
|
page=page, threads=threads)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/mailinglist/archive/<int:year>/<int:month>/<int:day>/<slug>/')
|
@mailinglist.route('/mailinglist/archive/<int:year>/<int:month>/<int:day>/<slug>/')
|
||||||
def mailinglist_show_thread(year, month, day, slug):
|
def show_thread(year, month, day, slug):
|
||||||
thread = Thread.get(year, month, day, slug)
|
thread = Thread.get(year, month, day, slug)
|
||||||
if thread is None:
|
if thread is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
return render_template('mailinglist/show_thread.html', thread=thread)
|
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
flask_website/views/snippets.py
Normal 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
|
|
@ -0,0 +1,2 @@
|
||||||
|
from flask_website import app
|
||||||
|
app.run(debug=True)
|
||||||