Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/creactiweb/_templates/+package+/controllers/index.py_tmpl
blob: 0f1f2de3d929119f7fa5078c031ee852b3700d1b (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# python import
import os

# gettext import
from gettext import gettext as _

# server import
from server.flask import app, logger, render, request, jsonify
# server tools import
from server.tools import storage


@app.route('/')
def index():
    # prepare result
    _content = {'content': _('atdw - Welcome!')}
    # render result
    return render('index.html', **_content)


@app.route('/<name>')
def page(name):
    # prepare result
    _content = {'content': _('atdw - Welcome on %s!' % name)}
    # render result
    return render('index.html', **_content)


@app.route('/ajax', methods=['GET', 'POST'])
def ajax():
    # POST
    if request.method == 'POST':
        if 'ajax-sample' in request.form:
            # prepare ajax result
            _ajax_content = {
                    'result': request.form['ajax-sample']
                    }
            # render ajax
            return jsonify(_ajax_content)
        # ?? should not happen
        else:
            _result = '??'
    # GET
    else:
        _result = ''
    # prepare result
    _content = {
                'title': _('Demo - Ajax sample'),
                'result': _result
                }
    # render result
    return render('{{package}}/ajax.html', **_content)


JNL_PATH = os.path.join('static', 'images', 'journal')
WEB_PATH = '/static/images/journal'

@app.route('/gallery')
def gallery():
    # list images
    _images_names = storage.list_dir(path=JNL_PATH)
    _images_urls  = ['%s/%s' % (WEB_PATH, _f) for _f in _images_names]
    # prepare result
    _content = {
                'title' : _('Demo - Gallery'),
                'images': enumerate(_images_urls)
                }
    # render result
    return render('{{package}}/gallery.html', **_content)