~fabrixxm/lesanaweb

ref: 169e88185e523c86f590494bb62cf3d73dc7aca6 lesanaweb/app.py -rw-r--r-- 904 bytes
169e8818 — fabrixxm First commit 1 year, 3 months ago
                                                                                
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
from flask import Flask
from flask import render_template, request
from lesana.collection import Collection


COLLECTIONPATH = "/home/fabio/progetti/glcomo/bookmarks"
PAGESIZE = 20

app = Flask("linkopedia")
collection = Collection(COLLECTIONPATH)


@app.route('/search.html')
def search(name=None):
    page = int(request.args.get('p', 1)) - 1
    q = request.args.get('q')

    collection.start_search(q)
    data = list(collection.get_search_results(page, PAGESIZE))
    return render_template('index.html', q=q, page=page, data=data)


@app.route('/', methods=['GET'])
def hello_world():
    pagestart = 0
    page = int(request.args.get('p', 1))
    pagestart = (page - 1) * PAGESIZE
    pageend = pagestart + PAGESIZE

    data = list(collection.get_all_documents())[pagestart:pageend]
    print(data[0].get_data()['added'].__class__)
    return render_template('index.html', page=page, data=data)