aboutsummaryrefslogtreecommitdiff
path: root/app/_main.py
blob: 3c2a973ee947f0fb6bb4af394c0b710159fd95a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3

from flask import (Blueprint as _Blueprint, render_template as _template,
	request as _r, current_app as _app)
from textoutpc import tohtml as _translate

__all__ = ["main"]

main = _Blueprint('main', __name__)

@main.route('/', methods = ['GET', 'POST'])
@main.route('/index.html', methods = ['GET', 'POST'])
def _process_page():
	""" Page avec entrée. """

	result = None
	text = ''

	if _r.method == 'POST' and 'text' in _r.form:
		text = _r.form['text'].strip()
		if text:
			result = _translate(text)
	else:
		text = _app.config['TEXT_DEFAULT']
		result = _app.config['TEXT_DEFAULT_TRANSLATED']

	return _template('page.html', text = text, result = result,
		url = _app.config['URL'])

@main.route('/guide.html', methods = ['GET'])
def _guide_page():
	""" Page de guide. """

	return _template('guide.html', content = _app.config['TEXT_GUIDE'],
		url = _app.config['URL'])

# End of file.