annotate lookup.py @ 13:ca98a7dacb9f

start makefile for doing deps Ignore-this: e3bf8f95797a6cd473490283e444e4a1
author drewp@bigasterisk.com
date Sat, 16 Mar 2013 23:19:36 -0700
parents e054949143e9
children d44d3e4d415b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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):
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
47 out['links'].append(links.forDisplay(doc))
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
48 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
49 return out
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
50
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
51 def allTags(user, withTags=[]):
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
52 """withTags limits results to other tags that have been used with
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
53 those tags"""
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
54 withTags = set(withTags)
7
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
55 count = defaultdict(lambda: 0) # tag : count
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
56 for doc in db['links'].find({'user':user}, fields=['extracted.tags']):
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
57 docTags = set(doc.get('extracted', {}).get('tags', []))
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
58 if withTags and not withTags.issubset(docTags):
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
59 continue
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
60 for t in docTags.difference(withTags):
7
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
61 count[t] = count[t] + 1
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
62 byFreq = [(n, t) for t,n in count.iteritems()]
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
63 byFreq.sort(key=lambda (n,t): (-n, t))
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
64 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
65
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
66 def renderWithTime(name, data):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
67 t1 = time.time()
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
68 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
69 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
70 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
71 return rendered
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
72
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
73 @bottle.route('/addLink')
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
74 def addLink():
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
75 out = {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
76 'toRoot': '.',
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
77 'absRoot': siteRoot,
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
78 'user': getUser()[0],
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
79 'withKnockout': True,
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
80 '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
81 'loginBar': getLoginBar(),
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
82 }
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
83 return renderWithTime('add.jade', out)
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
84
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
85 @bottle.route('/addOverlay')
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
86 def addOverlay():
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
87 p = bottle.request.params
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
88
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
89 return ""
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
90
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
91
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
92 @bottle.route('/addLink/proposedUri')
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
93 def proposedUri():
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
94 uri = bottle.request.params.uri
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
95 user, _ = getUser()
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
96
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
97 try:
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
98 prevDoc = links.find(uri)
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
99 except NotFound:
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
100 prevDoc = None
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
101
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
102 return {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
103 '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
104 'tag' : prevDoc['tag'] if prevDoc else '',
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
105 'extended' : prevDoc['extended'] if prevDoc else '',
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
106 'shareWith' : prevDoc.get('shareWith', []) if prevDoc else [],
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
107 'suggestedTags': ['tag1', 'tag2'],
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
108 'existed': prevDoc is not None,
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
109 }
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
110
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
111 if 0:
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
112 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
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
113
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
114
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
115 @bottle.route('/tags')
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
116 def tagFilterComplete():
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
117 params = bottle.request.params
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
118 haveTags = filter(None, params['have'].split(','))
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
119 return {'tags' : [
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
120 {'id': t['label'],
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
121 'text': "%s (%s%s)" % (t['label'], t['count'], " left" if haveTags else "")}
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
122 for t in allTags(params.user,
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
123 withTags=haveTags)]}
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
124
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
125 @bottle.route('/<user>/')
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
126 def userSlash(user):
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
127 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
128
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
129 @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
130 def userAll(user):
7
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
131 return userLinks(user, "", toRoot=".")
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
132
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
133 @bottle.route('/<user>', method='POST')
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
134 def userAddLink(user):
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
135 if getUser()[0] != user:
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
136 raise ValueError("not logged in as %s" % user)
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
137 print repr(bottle.request.params.__dict__)
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
138 doc = links.fromPostdata(bottle.request.params,
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
139 user,
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
140 datetime.datetime.now(tzlocal()))
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
141 links.insertOrUpdate(doc)
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
142
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
143 print "notify about sharing to", repr(doc['shareWith'])
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
144
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
145 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
146
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
147 @bottle.route('/<user>/<tags>')
7
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
148 def userLinks(user, tags, toRoot=".."):
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
149 tags = filter(None, tags.split('+'))
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
150 data = recentTags(user, tags)
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
151 data['loginBar'] = getLoginBar()
7
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
152 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
153 data['toRoot'] = toRoot
93d94f327e82 autocomplete in link page box
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
154 data['allTags'] = allTags(user)
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
155 data['user'] = user
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
156
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
157 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
158 data['stats']['template'] = 'TEMPLATETIME'
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
159 return renderWithTime('links.jade', data)
10
e054949143e9 reworking addlink and shareWith support
drewp@bigasterisk.com
parents: 7
diff changeset
160
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
161 @bottle.route('/')
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
162 def root():
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
163 data = {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
164 'loginBar': getLoginBar(),
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
165 'toRoot': ".",
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
166 'stats': {'template': 'TEMPLATETIME'},
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
167 '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
168 }
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
169 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
170
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
171 if __name__ == '__main__':
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
172 bottle.run(server='gunicorn', host='0.0.0.0', port=10002, workers=4)