4 # Kot: a quote engine for TdCT
5 # Copyright (C) 2011 Paul Bazin
7 # This file is part of Kot.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 from random import random as rand
27 {'func': 'index', 'label': u'Index'},
28 {'func': 'last', 'label': u'Derniers ajouts'},
29 {'func': 'random', 'label': u'Aléatoire'},
30 {'func': 'top', 'label': u'Top'},
31 {'func': 'zero', 'label': u'Aléatoire > 0'},
34 app = flask.Flask(__name__)
36 @app.route('/kot/<ukid>')
38 kot = pick.by_id(ukid)
41 return flask.render_template('kot.xhtml', nav=nav, kot=kot)
43 @app.route('/kot/<ukid>', methods=['POST'])
45 return '<p>%s</p><p>%s</p>' % (flask.request.form['kom'],
46 flask.request.form['poster']) + ukid
50 return flask.redirect(flask.url_for('index'))
54 return flask.render_template('index.xhtml', nav=nav,
59 return flask.render_template('last.xhtml', nav=nav,
60 kots=pick.by_key(lambda k: k.id))
64 return flask.render_template('random.xhtml', nav=nav,
65 kots=pick.by_key(lambda k: rand()))
69 return flask.render_template('top.xhtml', nav=nav,
70 kots=pick.by_key(lambda k: k.rating()))
74 return flask.render_template('zero.xhtml', nav=nav,
75 kots=pick.by_key(lambda k: rand(), lambda k: k.rating() >
80 return flask.request.args['kot'] + ('up' if
81 int(flask.request.args['up']) else 'down')
83 if __name__ == '__main__':