From 7701835ece85b05d828503883707b65a102060d1 Mon Sep 17 00:00:00 2001 From: str4d Date: Wed, 19 Dec 2012 12:39:53 +0000 Subject: [PATCH] Moved root file views into i2p2www.views, and committed this file (which was missed earlier) --- i2p2www/__init__.py | 21 ++++--------------- i2p2www/views.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 i2p2www/views.py diff --git a/i2p2www/__init__.py b/i2p2www/__init__.py index bda0cc09..20477fb6 100644 --- a/i2p2www/__init__.py +++ b/i2p2www/__init__.py @@ -88,6 +88,10 @@ url('/_.html', 'legacy.legacy_show') url('//', 'legacy.legacy_show') url('/.html', 'legacy.legacy_show') +url('/hosts.txt', 'views.hosts') +url('/robots.txt', 'views.robots') +url('/favicon.ico', 'views.favicon') + ################# # Babel selectors @@ -337,22 +341,5 @@ def downloads_redirect(protocol, file, mirror): return redirect(mirrors[mirror]['url'] % data) return redirect(mirrors[randint(0, len(mirrors) - 1)]['url'] % data) - -############ -# Root files - -@app.route('/hosts.txt') -def hosts(): - return send_from_directory(STATIC_DIR, 'hosts.txt', mimetype='text/plain') - -@app.route('/robots.txt') -def robots(): - return send_from_directory(STATIC_DIR, 'robots.txt', mimetype='text/plain') - -@app.route('/favicon.ico') -def favicon(): - return send_from_directory(os.path.join(app.root_path, 'static'), - 'favicon.ico', mimetype='image/vnd.microsoft.icon') - if __name__ == '__main__': app.run(debug=True) diff --git a/i2p2www/views.py b/i2p2www/views.py new file mode 100644 index 00000000..dc94ae5d --- /dev/null +++ b/i2p2www/views.py @@ -0,0 +1,50 @@ +from flask import abort, redirect, render_template, safe_join, send_from_directory, url_for +import os.path + +from i2p2www import STATIC_DIR, TEMPLATE_DIR +from i2p2www.blog.helpers import get_blog_entries + + +####################### +# General page handlers + +# Index - redirects to en homepage +def main_index(): + return redirect(url_for('site_show', lang='en')) + +# Site pages +def site_show(page): + if page.endswith('.html'): + return redirect(url_for('site_show', page=page[:-5])) + name = 'site/%s.html' % page + page_file = safe_join(TEMPLATE_DIR, name) + + if not os.path.exists(page_file): + # Could be a directory, so try index.html + name = 'site/%s/index.html' % page + page_file = safe_join(TEMPLATE_DIR, name) + if not os.path.exists(page_file): + # bah! those damn users all the time! + abort(404) + + options = { + 'page': page, + } + if (page == 'index'): + options['blog_entries'] = get_blog_entries(8) + + # hah! + return render_template(name, **options) + + +############ +# Root files + +def hosts(): + return send_from_directory(STATIC_DIR, 'hosts.txt', mimetype='text/plain') + +def robots(): + return send_from_directory(STATIC_DIR, 'robots.txt', mimetype='text/plain') + +def favicon(): + return send_from_directory(STATIC_DIR, 'favicon.ico', mimetype='image/vnd.microsoft.icon')