#!/usr/bin/env python2
# -*- coding:utf-8 -*-

import os
import codecs
import urlparse
import locale
locale.setlocale(locale.LC_ALL, '')

from c2cstats.generators import generate_json

from flask import Flask, request, g, redirect, url_for, \
     render_template, flash

# configuration
SECRET_KEY = 'development key'
FILES_DIR = '_output'
FILES_URL = '/files'

app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('C2CSTATS_SETTINGS', silent=True)


@app.route('/')
def index():
    return render_template('index.html')

@app.route('/user/')
def user_index():
    return redirect(url_for('index'))

@app.route('/user/<int:user_id>')
def show_user_stats(user_id):
    user_id = str(user_id)
    json_file = os.path.join(app.config['FILES_DIR'], user_id + '.json')

    context = {
        'json_url': app.config['FILES_URL'] + '/' + user_id + '.json',
        'user_id': user_id,
        }

    if not os.path.isfile(json_file):
        try:
            generate_json(user_id, json_file)
        except ParserError:
            flash('Error while loading page', 'error')
            return redirect(url_for('index'))

    return render_template('user.html', **context)


@app.route('/query', methods=['POST'])
def query_user():
    return redirect(url_for('show_user_stats',
                            user_id=int(request.form['user_id'])))

@@ -131,16 +131,56 @@
 L, '')%0A%0A
+from c2cstats.parser import ParserError%0A
 from c2c
@@ -1047,16 +1047,86 @@
 n_file)%0A
+            flash(u'Les statistiques ont %C3%A9t%C3%A9 calcul%C3%A9es avec succ%C3%A9s.')%0A
         
@@ -1167,28 +1167,41 @@
 ash(
+u
 'Err
-or while loading
+eur lors du chargement de la
  pag

add messages + convert to french