-
Notifications
You must be signed in to change notification settings - Fork 0
/
word_map_page.py
executable file
·70 lines (50 loc) · 1.68 KB
/
word_map_page.py
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
70
#!/usr/bin/python
import cgi, cgitb
import json
from common import document
from common import flaf_db
from common import flaf_tracer
from common import flaf_types
from common import list_dao
from common import util
cgitb.enable()
tracer = flaf_tracer.Tracer('WordMapAction')
form = cgi.FieldStorage()
bookIdsString = form.getvalue('bookIds')
bookIds = map(int, bookIdsString.split(',')) if bookIdsString else None
listId = form.getvalue('listId')
conn = flaf_db.newConn()
dbDao = flaf_db.DbDao(conn)
cursor = conn.cursor()
if listId is not None:
listDao = list_dao.ListDao(conn)
bookIds = listDao.getBooksInList(listId)
util.dieIfNone(bookIds, 'No book ids specified.')
# tracer.log('Looking for [%s] in book %s' % (word, bookId))
data = {
'bookIds': bookIds,
'allBooks': dbDao.getAllBooks(),
'uncommonShared': dbDao.getUncommonShared(bookIds),
'commonUnsharedMap': dbDao.getCommonUnshared(bookIds, 7)
}
tracer.log('got data')
# Package the contexts into a single data object
# to pass down to the client
# Write it out in HTML for the browser.
# This is kept to the bare minimum:
# creates a single content div
# creates a single javascript page object with the data from the server
# ensures the page is scrolled to the top
doc = document.Document()
doc.addCommonDeps()
doc.setTitle('Word Map')
doc.require('word_map_page.js')
doc.bodyLine('<div id="main-content"></div>')
doc.bodyLine('<script>')
doc.bodyLine(' var page = new WordMapPage(%s);' % json.dumps(data))
doc.bodyLine(' page.render($(\'#main-content\')[0]);')
doc.bodyLine(' setTimeout(function(){$(\'body\').scrollTop(0);}, 0);')
doc.bodyLine('</script>')
tracer.log('writing')
doc.write()
tracer.log('wrote doc')