Mercurial > code > home > repos > href
annotate lookup.py @ 8:be339aa223bf
tag/filter autocompelte
Ignore-this: f6235de879c1ce62a8fc41e890edd0d2
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Wed, 06 Mar 2013 23:22:24 -0800 |
parents | 93d94f327e82 |
children | e054949143e9 |
rev | line source |
---|---|
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
1 #!bin/python |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
2 """ |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
3 serve some queries over bookmarks: |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
4 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
5 /user |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
6 /user/tag+tag+tag |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
7 |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
8 and the add-bookmark stuff |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
9 |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
10 """ |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
11 import pymongo, bottle, time, urllib, datetime, json, restkit |
7
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
12 from collections import defaultdict |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
13 from urllib2 import urlparse |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
14 from dateutil.tz import tzlocal |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
15 from bottle import static_file |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
16 from jadestache import Renderer |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
17 from pagetitle import PageTitle |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
18 from link import Links, NotFound |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
19 db = pymongo.Connection('bang', tz_aware=True)['href'] |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
20 pageTitle = PageTitle(db) |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
21 links = Links(db) |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
22 renderer = Renderer(search_dirs=['template'], debug=bottle.DEBUG) |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
23 |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
24 siteRoot = 'https://bigasterisk.com/href' |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
25 |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
26 def getLoginBar(): |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
27 openidProxy = restkit.Resource("http://bang:9023/") |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
28 return openidProxy.get("_loginBar", |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
29 headers={"Cookie" : bottle.request.headers.get('cookie')}).body_string() |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
30 |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
31 def getUser(): |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
32 agent = bottle.request.headers.get('x-foaf-agent', None) |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
33 username = db['user'].find_one({'_id':agent})['username'] if agent else None |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
34 return username, agent |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
35 |
7
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
36 @bottle.route('/static/<path:path>') |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
37 def server_static(path): |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
38 return static_file(path, root='static') |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
39 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
40 def recentTags(user, tags=None): |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
41 out = {'links':[]} |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
42 t1 = time.time() |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
43 spec = {'user':user} |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
44 if tags: |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
45 spec['extracted.tags'] = {'$all' : tags} |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
46 for doc in db['links'].find(spec, sort=[('t', -1)], limit=50): |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
47 del doc['_id'] |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
48 doc['t'] = doc['t'].astimezone(tzlocal()).isoformat() |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
49 if not doc['description'].strip(): |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
50 doc['displayDescription'] = doc['href'] |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
51 else: |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
52 doc['displayDescription'] = doc['description'] |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
53 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
54 doc['tagWords'] = [{'word' : w} for w in doc['tag'].split(None)] |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
55 doc['domain'] = urlparse.urlparse(doc['href']).netloc |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
56 doc['editLink'] = 'addLink?' + urllib.urlencode([('url', doc['href'])]) |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
57 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
58 out['links'].append(doc) |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
59 out['stats'] = {'queryTimeMs' : round((time.time() - t1) * 1000, 2)} |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
60 return out |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
61 |
7
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
62 def allTags(user): |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
63 count = defaultdict(lambda: 0) # tag : count |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
64 for doc in db['links'].find({'user':user}, fields=['extracted.tags']): |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
65 for t in doc.get('extracted', {}).get('tags', []): |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
66 count[t] = count[t] + 1 |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
67 byFreq = [(n, t) for t,n in count.iteritems()] |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
68 byFreq.sort(key=lambda (n,t): (-n, t)) |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
69 return [{'label': t, 'count': n} for n, t in byFreq] |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
70 |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
71 def renderWithTime(name, data): |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
72 t1 = time.time() |
4 | 73 rendered = renderer.render_name(name, data) |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
74 dt = (time.time() - t1) * 1000 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
75 rendered = rendered.replace('TEMPLATETIME', "%.02f ms" % dt) |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
76 return rendered |
4 | 77 |
78 @bottle.route('/addLink') | |
79 def addLink(): | |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
80 out = { |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
81 'toRoot': '.', |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
82 'absRoot': siteRoot, |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
83 'user': getUser()[0], |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
84 'withKnockout': True, |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
85 'fillHrefJson': json.dumps(bottle.request.params.get('url', '')), |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
86 'loginBar': getLoginBar(), |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
87 } |
4 | 88 return renderWithTime('add.jade', out) |
89 | |
90 @bottle.route('/addOverlay') | |
91 def addOverlay(): | |
92 p = bottle.request.params | |
93 | |
94 return "" | |
95 | |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
96 |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
97 @bottle.route('/addLink/proposedUri') |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
98 def proposedUri(): |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
99 uri = bottle.request.params.uri |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
100 user, _ = getUser() |
4 | 101 |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
102 try: |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
103 prevDoc = links.find(uri) |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
104 except NotFound: |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
105 prevDoc = None |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
106 |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
107 return { |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
108 'description': prevDoc['description'] if prevDoc else pageTitle.pageTitle(uri), |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
109 'tag' : prevDoc['tag'] if prevDoc else '', |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
110 'extended' : prevDoc['extended'] if prevDoc else '', |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
111 'suggestedTags':['tag1', 'tag2'], |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
112 'existed':prevDoc is not None, |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
113 } |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
114 |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
115 if 0: |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
116 pass#proposal check existing links, get page title (stuff that in db), get tags from us and other serviecs. maybe the deferred ones ater |
4 | 117 |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
118 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
119 @bottle.route('/<user>/') |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
120 def userSlash(user): |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
121 bottle.redirect("/%s" % urllib.quote(user)) |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
122 |
4 | 123 @bottle.route('/<user>', method='GET') |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
124 def userAll(user): |
7
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
125 return userLinks(user, "", toRoot=".") |
4 | 126 |
127 @bottle.route('/<user>', method='POST') | |
128 def userAddLink(user): | |
129 p = bottle.request.params | |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
130 if getUser()[0] != user: |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
131 raise ValueError("not logged in as %s" % user) |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
132 links.insertOrUpdate(dict( |
4 | 133 user=user, |
134 description=p.description, | |
135 extended=p.extended, | |
136 href=p.href, | |
137 #private=p.private, == checked, | |
138 #shared ?? | |
139 tag=p.tag, | |
140 t=datetime.datetime.now(tzlocal()), | |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
141 )) |
4 | 142 |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
143 bottle.redirect(siteRoot + '/' + user) |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
144 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
145 @bottle.route('/<user>/<tags>') |
7
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
146 def userLinks(user, tags, toRoot=".."): |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
147 tags = tags.split('+') |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
148 data = recentTags(user, tags) |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
149 data['loginBar'] = getLoginBar() |
7
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
150 data['desc'] = ("%s's recent links" % user) + (" tagged %s" % (tags,) if tags else "") |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
151 data['toRoot'] = toRoot |
93d94f327e82
autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents:
5
diff
changeset
|
152 data['allTags'] = allTags(user) |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
153 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
154 data['pageTags'] = [{"word":t} for t in tags] |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
155 data['stats']['template'] = 'TEMPLATETIME' |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
156 return renderWithTime('links.jade', data) |
5
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
157 |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
158 @bottle.route('/') |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
159 def root(): |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
160 data = { |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
161 'loginBar': getLoginBar(), |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
162 'toRoot': ".", |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
163 'stats': {'template': 'TEMPLATETIME'}, |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
164 'users': [{'user':doc['username']} for doc in db['user'].find()], |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
165 } |
f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents:
4
diff
changeset
|
166 return renderWithTime('index.jade', data) |
2
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
167 |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
168 if __name__ == '__main__': |
80b11112c9e0
web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
169 bottle.run(server='gunicorn', host='0.0.0.0', port=10002, workers=4) |