Skip to content
This repository
Newer
Older
100755 486 lines (408 sloc) 16.449 kb
42db4a6f »
2008-04-16 use env instead of usr/bin
1 #!/usr/bin/env python
dcb7d7f7 » jdthomas
2008-10-13 Add a basic page for earmarks.
2 import re, sys
53080492 » Aaron Swartz
2008-04-04 reorganize
3 import web
ef757cc4 »
2008-08-03 template fixes
4
0c13f960 » asldevi
2008-11-27 -wyr mails sent to senators also
5 from utils import zip2rep, simplegraphs, apipublish, users, writerep, se, wyrapp
b89f8444 » Aaron Swartz
2008-04-11 add a blog
6 import blog
82ae3f36 » Devi
2008-06-10 petitions - first cut
7 import petition
6fb49894 » asldevi
2008-07-01 javascript to add petition URL
8 import settings
2dba2db6 » asldevi
2008-10-13 using production mode from environment, use the same for writerep too
9 from settings import db, render, production_mode
ece0a706 »
2008-09-02 first try at using smartersql; apipublish still broken
10 import schema
5858fbb3 » asldevi
2008-10-13 Send email on crashes - #67
11 import config
53080492 » Aaron Swartz
2008-04-04 reorganize
12
57f54c03 » asldevi
2008-10-20 Don't autoreload in production mode;
13 if not production_mode:
14 web.config.debug = True
15
a067eb2c »
2008-04-15 add API export support for major pages
16 options = r'(?:\.(html|xml|rdf|n3|json))'
d6e03b5e » Aaron Swartz
2008-04-04 add web.py to REQUISITES
17 urls = (
a067eb2c »
2008-04-15 add API export support for major pages
18 r'/', 'index',
19 r'/us/(?:index%s)?' % options, 'find',
20 r'/us/([A-Z][A-Z])', 'redistrict',
21 r'/us/([a-z][a-z])%s?' % options, 'state',
22 r'/us/([A-Z][A-Z]-\d+)', 'redistrict',
23 r'/us/([a-z][a-z]-\d+)%s?' % options, 'district',
e3e3e680 »
2008-10-03 show votepcts
24 r'/(us|p)/by/(.*)/distribution\.png', 'sparkdist',
08827f06 »
2008-04-17 add speech information to pol pages
25 r'/(us|p)/by/(.*)', 'dproperty',
17089c77 » jdthomas
2008-11-06 Add by politician lobbyist page.
26 r'/p/(.*?)/lobby', 'politician_lobby',
cd5bad1c » jdthomas
2008-10-14 Fix url for politician specific earmarks. Bug 162.
27 r'/p/(.*?)/earmarks', 'politician_earmarks',
670b7e46 »
2008-06-13 add more links for bills, aligned groups
28 r'/p/(.*?)/introduced', 'politician_introduced',
29 r'/p/(.*?)/groups', 'politician_groups',
30 r'/p/(.*?)/(\d+)', 'politician_group',
a067eb2c »
2008-04-15 add API export support for major pages
31 r'/p/(.*?)%s?' % options, 'politician',
dcb7d7f7 » jdthomas
2008-10-13 Add a basic page for earmarks.
32 r'/e/(.*?)%s?' % options, 'earmark',
3ef7d529 » A.S.L. Devi
2008-06-04 first cut at individual pages for bills
33 r'/b/(.*?)%s?' % options, 'bill',
3be04aa2 »
2008-10-01 import rolls, allow staggered import of bills
34 r'/r/us/(.*?)%s?' % options, 'roll',
417b9d2b »
2008-06-18 web.py upgrade
35 r'/c', petition.app,
a62c1c18 » asldevi
2008-09-15 move all user related URLs to be /u/*
36 r'/u', users.app,
59484d78 » jdthomas
2008-10-27 Some initial pages for lobbyist stuff.
37 r'/l/c/?(.*?)', 'lob_contrib',
38 r'/l/f/?(.*?)', 'lob_filing',
39 r'/l/o/?(.*?)', 'lob_org',
40 r'/l/pa/?(.*?)', 'lob_pac',
41 r'/l/pe/?(.*?)', 'lob_person',
0c13f960 » asldevi
2008-11-27 -wyr mails sent to senators also
42 r'/writerep', wyrapp.app,
a067eb2c »
2008-04-15 add API export support for major pages
43 r'/about(/?)', 'about',
50572a09 » Rebecca Malamud
2008-10-25 webchick redesign
44 r'/about/team', 'aboutteam',
45 r'/about/help', 'abouthelp',
37659f42 »
2008-04-15 add list of politicians, API docs
46 r'/about/api', 'aboutapi',
a067eb2c »
2008-04-15 add API export support for major pages
47 r'/about/feedback', 'feedback',
417b9d2b »
2008-06-18 web.py upgrade
48 r'/blog', blog.app,
0aca1e4f » asldevi
2008-10-12 share page/petition
49 r'/share', 'petition.share',
5daa1d37 »
2008-06-12 add yauth code
50 r'/data/(.*)', 'staticdata',
12361663 » asldevi
2008-09-15 support for MSN contacts import
51 r'/bbauth/', 'contacts.auth_yahoo',
52 r'/authsub', 'contacts.auth_google',
53 r'/auth/msn', 'contacts.auth_msn',
d6e03b5e » Aaron Swartz
2008-04-04 add web.py to REQUISITES
54 )
55
56 class index:
57 def GET(self):
58 return render.index()
59
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
60 class about:
24959170 » Aaron Swartz
2008-04-11 make feedback work, add about redirect
61 def GET(self, endslash=None):
62 if not endslash: raise web.seeother('/about/')
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
63 return render.about()
64
37659f42 »
2008-04-15 add list of politicians, API docs
65 class aboutapi:
66 def GET(self):
67 return render.about_api()
68
50572a09 » Rebecca Malamud
2008-10-25 webchick redesign
69 class aboutteam:
70 def GET(self):
71 return render.about_team()
72
73 class abouthelp:
74 def GET(self):
75 return render.about_help()
76
24959170 » Aaron Swartz
2008-04-11 make feedback work, add about redirect
77 class feedback:
78 def GET(self):
19fdd2c5 »
2008-10-31 minor bug fixes
79 return render.feedback()
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
80
24959170 » Aaron Swartz
2008-04-11 make feedback work, add about redirect
81 def POST(self):
82 i = web.input(email='info@watchdog.net')
83 web.sendmail('Feedback <%s>' % i.email, 'Watchdog <info@watchdog.net>',
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
84 'watchdog.net feedback',
24959170 » Aaron Swartz
2008-04-11 make feedback work, add about redirect
85 i.content +'\n\n' + web.ctx.ip)
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
86
24959170 » Aaron Swartz
2008-04-11 make feedback work, add about redirect
87 return render.feedback_thanks()
88
320eb4d6 » Aaron Swartz
2008-04-04 add about, zip2rep
89 class find:
a067eb2c »
2008-04-15 add API export support for major pages
90 def GET(self, format=None):
5680b856 »
2008-04-14 clean up address finding errors
91 i = web.input(address=None)
d667b365 »
2008-08-02 support zip+4
92 pzip5 = re.compile(r'\d{5}')
93 pzip4 = re.compile(r'\d{5}-\d{4}')
94 pdist = re.compile(r'[a-zA-Z]{2}\-\d{2}')
776fe4c5 »
2008-09-08 get most important pages using smartersql
95
96 dists = None
623fed21 » Aaron Swartz
2008-11-10 use xapian for search
97 if not i.get('q'):
98 i.q = i.get('zip')
99
100 if i.q:
101 if pzip4.match(i.q):
102 zip, plus4 = i.q.split('-')
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
103 dists = [x.district for x in
d667b365 »
2008-08-02 support zip+4
104 db.select('zip4', where='zip=$zip and plus4=$plus4', vars=locals())]
776fe4c5 »
2008-09-08 get most important pages using smartersql
105
623fed21 » Aaron Swartz
2008-11-10 use xapian for search
106 elif pzip5.match(i.q):
c03b9168 » btbytes
2008-06-06 handle zip5 and district identifier entry to the search box using RE …
107 try:
623fed21 » Aaron Swartz
2008-11-10 use xapian for search
108 dists = zip2rep.zip2dist(i.q, i.address)
c03b9168 » btbytes
2008-06-06 handle zip5 and district identifier entry to the search box using RE …
109 except zip2rep.BadAddress:
623fed21 » Aaron Swartz
2008-11-10 use xapian for search
110 return render.find_badaddr(i.q, i.address)
776fe4c5 »
2008-09-08 get most important pages using smartersql
111
112 if dists:
113 d_dists = schema.District.select(where=web.sqlors('name=', dists))
114 out = apipublish.publish(d_dists, format)
115 if out: return out
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
116
c03b9168 » btbytes
2008-06-06 handle zip5 and district identifier entry to the search box using RE …
117 if len(dists) == 1:
118 raise web.seeother('/us/%s' % dists[0].lower())
119 elif len(dists) == 0:
623fed21 » Aaron Swartz
2008-11-10 use xapian for search
120 return render.find_none(i.q)
8207ebc7 » btbytes
2008-06-06 representative search by name; resolve multiple resutls for rep search
121 else:
623fed21 » Aaron Swartz
2008-11-10 use xapian for search
122 return render.find_multi(i.q, d_dists)
123
124 if pdist.match(i.q):
125 raise web.seeother('/us/%s' % i.q)
126
127 results = se.query(i.q)
128 reps = db.select('politician', where=web.sqlors('id=', results))
129 if len(reps) > 1:
130 return render.find_multi_reps(reps)
131 else:
132 try:
133 rep = reps[0]
134 web.seeother('/p/%s' % rep.id)
135 except IndexError:
136 raise web.notfound
8207ebc7 » btbytes
2008-06-06 representative search by name; resolve multiple resutls for rep search
137
320eb4d6 » Aaron Swartz
2008-04-04 add about, zip2rep
138 else:
776fe4c5 »
2008-09-08 get most important pages using smartersql
139 index = schema.District.select(order='name asc')
140 out = apipublish.publish(index, format)
141 if out: return out
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
142
776fe4c5 »
2008-09-08 get most important pages using smartersql
143 return render.districtlist(index)
320eb4d6 » Aaron Swartz
2008-04-04 add about, zip2rep
144
d23baf89 »
2008-04-14 add state pages (very slow at the moment)
145 class state:
a067eb2c »
2008-04-15 add API export support for major pages
146 def GET(self, state, format=None):
d23baf89 »
2008-04-14 add state pages (very slow at the moment)
147 try:
776fe4c5 »
2008-09-08 get most important pages using smartersql
148 state = schema.State.where(code=state.upper())[0]
d23baf89 »
2008-04-14 add state pages (very slow at the moment)
149 except IndexError:
150 raise web.notfound
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
151
776fe4c5 »
2008-09-08 get most important pages using smartersql
152 out = apipublish.publish([state], format)
153 if out: return out
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
154
776fe4c5 »
2008-09-08 get most important pages using smartersql
155 return render.state(state)
d23baf89 »
2008-04-14 add state pages (very slow at the moment)
156
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
157 class redistrict:
158 def GET(self, district):
159 return web.seeother('/us/' + district.lower())
160
d6e03b5e » Aaron Swartz
2008-04-04 add web.py to REQUISITES
161 class district:
a067eb2c »
2008-04-15 add API export support for major pages
162 def GET(self, district, format=None):
d6e03b5e » Aaron Swartz
2008-04-04 add web.py to REQUISITES
163 try:
776fe4c5 »
2008-09-08 get most important pages using smartersql
164 d = schema.District.where(name=district.upper())[0]
d6e03b5e » Aaron Swartz
2008-04-04 add web.py to REQUISITES
165 except IndexError:
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
166 raise web.notfound
776fe4c5 »
2008-09-08 get most important pages using smartersql
167
168 out = apipublish.publish([d], format)
169 if out: return out
170
75110f0f » jdthomas
2008-10-15 Move call to sparkpos into template file.
171 return render.district(d, sparkpos)
d6e03b5e » Aaron Swartz
2008-04-04 add web.py to REQUISITES
172
670b7e46 »
2008-06-13 add more links for bills, aligned groups
173 def group_politician_similarity(politician_id, qmin=None):
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
174 """Find the interest groups that vote most like a politician."""
175 query_min = lambda mintotal, politician_id=politician_id: db.select(
176 'group_politician_similarity'
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
177 ' JOIN interest_group ON (interest_group.id = group_id)',
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
178 what='*, cast(agreed as float)/total as agreement',
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
179 where='total >= $mintotal AND politician_id=$politician_id ',
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
180 vars=locals()).list()
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
181
670b7e46 »
2008-06-13 add more links for bills, aligned groups
182 if qmin:
183 q = query_min(qmin)
184 else:
185 q = query_min(5)
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
186 if not q:
670b7e46 »
2008-06-13 add more links for bills, aligned groups
187 q = query_min(3)
188 if not q:
189 q = query_min(1)
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
190
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
191 q.sort(lambda x, y: cmp(x.agreement, y.agreement), reverse=True)
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
192 return q
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
193
76ada988 » asldevi
2008-06-17 paginate bills list, real name for bill sponsor, votes by party on bi…
194 def bill_list(format, page=0, limit=50):
776fe4c5 »
2008-09-08 get most important pages using smartersql
195 bills = schema.Bill.select(limit=limit, offset=page*limit, order='session desc, introduced desc, number desc')
196
197 out = apipublish.publish(bills, format)
198 if out: return out
199 #@@ add link to next page
200
76ada988 » asldevi
2008-06-17 paginate bills list, real name for bill sponsor, votes by party on bi…
201 return render.bill_list(bills, limit)
202
3be04aa2 »
2008-10-01 import rolls, allow staggered import of bills
203 class roll:
204 def GET(self, roll_id, format=None):
205 try:
206 b = schema.Roll.where(id=roll_id)[0]
207 votes = schema.Vote.where(roll_id=b.id)
208 except IndexError:
209 raise web.notfound
210
211 out = apipublish.publish([b], format)
212 if out: return out
e3e3e680 »
2008-10-03 show votepcts
213
214 def votepct(pvotes):
215 s = (float(pvotes.get(1, 0)) / sum(pvotes.values()))
216 return str(s * 100)[:4].rstrip('.') + '%'
3be04aa2 »
2008-10-01 import rolls, allow staggered import of bills
217
e3e3e680 »
2008-10-03 show votepcts
218 return render.roll(b, votes, votepct)
3be04aa2 »
2008-10-01 import rolls, allow staggered import of bills
219
3ef7d529 » A.S.L. Devi
2008-06-04 first cut at individual pages for bills
220 class bill:
221 def GET(self, bill_id, format=None):
222 if bill_id == "" or bill_id == "index":
76ada988 » asldevi
2008-06-17 paginate bills list, real name for bill sponsor, votes by party on bi…
223 i = web.input(page=0)
224 return bill_list(format, int(i.page))
776fe4c5 »
2008-09-08 get most important pages using smartersql
225
3ef7d529 » A.S.L. Devi
2008-06-04 first cut at individual pages for bills
226 try:
7f1f0605 »
2008-09-15 fix crashing typo
227 b = schema.Bill.where(id=bill_id)[0]
3ef7d529 » A.S.L. Devi
2008-06-04 first cut at individual pages for bills
228 except IndexError:
229 raise web.notfound
776fe4c5 »
2008-09-08 get most important pages using smartersql
230
231 out = apipublish.publish([b], format)
232 if out: return out
233
3ef7d529 » A.S.L. Devi
2008-06-04 first cut at individual pages for bills
234 return render.bill(b)
235
dcb7d7f7 » jdthomas
2008-10-13 Add a basic page for earmarks.
236 def earmark_list(format, page=0, limit=50):
237 earmarks = schema.Earmark.select(limit=limit, offset=page*limit, order='id')
238
239 out = apipublish.publish(earmarks, format)
240 if out: return out
8f890189 » jdthomas
2008-10-14 Add list of earmarks by politician.
241 return render.earmark_list(earmarks, limit)
242 def earmark_pol_list(pol_id, format, page=0, limit=50):
3528f21c » jdthomas
2008-10-26 Order politician's earmarks by cost. (Bug 186)
243 earmarks = db.select(['earmark_sponsor', 'earmark'], what='earmark.*',
244 where='politician_id = $pol_id AND earmark_id=earmark.id',
245 order='final_amt desc', vars=locals())
246 if not earmarks:
e9f45850 » jdthomas
2008-10-14 Fix problem for people with NoneType data. For instance john_mccain's…
247 # @@TODO: something better here.
248 raise web.notfound
8f890189 » jdthomas
2008-10-14 Add list of earmarks by politician.
249 out = apipublish.publish(earmarks, format)
250 if out: return out
dcb7d7f7 » jdthomas
2008-10-13 Add a basic page for earmarks.
251 return render.earmark_list(earmarks, limit)
252
cd5bad1c » jdthomas
2008-10-14 Fix url for politician specific earmarks. Bug 162.
253 class politician_earmarks:
254 def GET(self, polid, format=None):
255 try:
256 em = schema.Politician.where(id=polid)[0]
257 except IndexError:
258 raise web.notfound
259 return earmark_pol_list(polid, format)
dcb7d7f7 » jdthomas
2008-10-13 Add a basic page for earmarks.
260 class earmark:
261 def GET(self, earmark_id, format=None):
8f890189 » jdthomas
2008-10-14 Add list of earmarks by politician.
262 # No earmark id, show list
dcb7d7f7 » jdthomas
2008-10-13 Add a basic page for earmarks.
263 if earmark_id == "" or earmark_id == "index":
264 # Show earmark list
265 i = web.input(page=0)
266 return earmark_list(format, int(i.page))
8f890189 » jdthomas
2008-10-14 Add list of earmarks by politician.
267 # Display the specific earmark
268 try:
269 em = schema.Earmark.where(id=int(earmark_id))[0]
270 except IndexError:
271 raise web.notfound
272 except ValueError:
dcb7d7f7 » jdthomas
2008-10-13 Add a basic page for earmarks.
273 raise web.notfound
274 return render.earmark(em)
275
276
8dfd496c »
2008-04-13 add initial politician data from govtrack
277 class politician:
a067eb2c »
2008-04-15 add API export support for major pages
278 def GET(self, polid, format=None):
8dfd496c »
2008-04-13 add initial politician data from govtrack
279 if polid != polid.lower():
280 raise web.seeother('/p/' + polid.lower())
58c2be13 »
2008-09-18 look up by ID
281
282 i = web.input()
283 idlookup = False
284 for k in ['votesmartid', 'bioguideid', 'opensecretsid', 'govtrackid']:
285 if i.get(k):
286 idlookup = True
287 ps = schema.Politician.where(**{k: i[k]})
288 if ps: raise web.seeother('/p/' + ps[0].id)
289
290 if idlookup:
291 # we were looking up by ID but nothing matched
292 raise web.notfound
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
293
37659f42 »
2008-04-15 add list of politicians, API docs
294 if polid == "" or polid == "index":
776fe4c5 »
2008-09-08 get most important pages using smartersql
295 p = schema.Politician.select(order='district_id asc')
296
297 out = apipublish.publish(p, format)
298 if out: return out
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
299
37659f42 »
2008-04-15 add list of politicians, API docs
300 return render.pollist(p)
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
301
a067eb2c »
2008-04-15 add API export support for major pages
302 try:
776fe4c5 »
2008-09-08 get most important pages using smartersql
303 p = schema.Politician.where(id=polid)[0]
a067eb2c »
2008-04-15 add API export support for major pages
304 except IndexError:
305 raise web.notfound
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
306
776fe4c5 »
2008-09-08 get most important pages using smartersql
307 #@@move into schema
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
308 p.fec_ids = [x.fec_id for x in db.select('politician_fec_ids', what='fec_id',
b6037ccd »
2008-07-23 add FEC data
309 where='politician_id=$polid', vars=locals())]
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
310
c1face8d » asldevi
2008-06-18 added related_groups and sponsored_bills to politician API
311 p.related_groups = group_politician_similarity(polid)
776fe4c5 »
2008-09-08 get most important pages using smartersql
312
313 out = apipublish.publish([p], format)
314 if out: return out
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
315
75110f0f » jdthomas
2008-10-15 Move call to sparkpos into template file.
316 return render.politician(p, sparkpos)
8dfd496c »
2008-04-13 add initial politician data from govtrack
317
17089c77 » jdthomas
2008-11-06 Add by politician lobbyist page.
318 class politician_lobby:
319 def GET(self, polid, format=None):
320 limit = 50
321 page = int(web.input(page=0).page)
322 #c = schema.lob_contribution.select(where='politician_id=$polid', limit=limit, offset=page*limit, order='amount desc', vars=locals())
323 c = db.select(['lob_organization', 'lob_filing', 'lob_contribution', 'lob_person'],
324 where="politician_id = $polid and lob_filing.id = filing_id and lob_organization.id = org_id and lob_person.id = lobbyist_id",
325 order='amount desc;', vars=locals())
326 return render.politician_lobby(c, limit)
59484d78 » jdthomas
2008-10-27 Some initial pages for lobbyist stuff.
327 class lob_filing:
328 def GET(self, filing_id):
329 limit = 50
330 page = int(web.input(page=0).page)
331 if filing_id:
332 f = schema.lob_filing.select(where='id=$filing_id', limit=limit, offset=page*limit, vars=locals())
333 else:
334 f = schema.lob_filing.select(limit=limit, offset=page*limit)
335 return render.lob_filings(f,limit)
336 class lob_contrib:
337 def GET(self, filing_id):
338 limit = 50
339 page = int(web.input(page=0).page)
340 if filing_id:
341 c = schema.lob_contribution.select(where='filing_id=$filing_id', limit=limit, offset=page*limit, order='amount desc', vars=locals())
342 else:
343 c = schema.lob_contribution.select(limit=limit, offset=page*limit, order='amount desc')
344 return render.lob_contributions(c, limit)
345 class lob_pac:
346 def GET(self, pac_id):
347 limit = 50
348 i = web.input(page=0)
349 page = int(i.page)
350 if 'filing_id' in i:
351 p = [x.pac for x in schema.lob_pac_filings.select(where='filing_id=$i.filing_id',limit=limit, offset=page*limit, vars=locals())]
352 elif pac_id:
353 p = schema.lob_pac.select(where='id=$pac_id',limit=limit, offset=page*limit, vars=locals())
354 else:
355 p = schema.lob_pac.select(limit=limit, offset=page*limit)
356 return render.lob_pacs(p,limit)
357 class lob_org:
358 def GET(self, org_id):
359 limit = 50
360 i = web.input(page=0)
361 page = int(i.page)
362 if org_id:
363 o = schema.lob_organization.select(where='id=$org_id', limit=limit, offset=page*limit, order='name asc', vars=locals())
364 else:
365 o = schema.lob_organization.select(limit=limit, offset=page*limit, order='name asc')
366 return render.lob_orgs(o,limit)
367 class lob_person:
368 def GET(self, person_id):
369 limit = 50
370 i = web.input(page=0)
371 page = int(i.page)
372 if person_id:
373 p = schema.lob_person.select(where='id=$person_id', limit=limit, offset=page*limit, order='lastname asc', vars=locals())
374 else:
375 p = schema.lob_person.select(limit=limit, offset=page*limit, order='lastname asc')
376 return render.lob_person(p,limit)
377
670b7e46 »
2008-06-13 add more links for bills, aligned groups
378 class politician_introduced:
379 def GET(self, politician_id):
776fe4c5 »
2008-09-08 get most important pages using smartersql
380 pol = schema.Politician.where(id=politician_id)[0]
381 return render.politician_introduced(pol)
670b7e46 »
2008-06-13 add more links for bills, aligned groups
382
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
383 class politician_groups:
670b7e46 »
2008-06-13 add more links for bills, aligned groups
384 def GET(self, politician_id):
385 related = group_politician_similarity(politician_id, qmin=1)
57f54c03 » asldevi
2008-10-20 Don't autoreload in production mode;
386 pol = schema.Politician.where(id=politician_id)[0]
387 return render.politician_groups(pol, related)
670b7e46 »
2008-06-13 add more links for bills, aligned groups
388
389 class politician_group:
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
390 def GET(self, politician_id, group_id):
3be04aa2 »
2008-10-01 import rolls, allow staggered import of bills
391 votes = db.select(['position', 'interest_group_bill_support', 'bill'],
392 where="interest_group_bill_support.bill_id = position.bill_id AND "
393 "position.bill_id = bill.id AND "
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
394 "politician_id = $politician_id AND group_id = $group_id",
395 order='vote = support desc',
396 vars=locals())
397
398 return render.politician_group(votes)
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
399
a04e88fd »
2008-06-05 List interest group alignment, bills introduced
400
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
401 r_safeproperty = re.compile('^[a-z0-9_]+$')
08827f06 »
2008-04-17 add speech information to pol pages
402 table_map = {'us': 'district', 'p': 'politician'}
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
403
7c658677 » Aaron Swartz
2008-04-05 more data, some first stabs at graphs
404 class dproperty:
08827f06 »
2008-04-17 add speech information to pol pages
405 def GET(self, table, what):
406 try:
407 table = table_map[table]
408 except KeyError:
409 raise web.notfound
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
410 if not r_safeproperty.match(what): raise web.notfound
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
411
14c0d2e4 » asldevi
2008-06-18 bug fixes
412 #if `what` is not there in the `table` (provide available options rather than 404???)
413 try:
414 maxnum = float(db.select(table,
acaa3371 » Kragen Javier Sitaker
2008-04-17 Test-covered and reformatted more of webapp.py.
415 what='max(%s) as m' % what,
416 vars=locals())[0].m)
14c0d2e4 » asldevi
2008-06-18 bug fixes
417 except:
418 raise web.notfound
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
419
08827f06 »
2008-04-17 add speech information to pol pages
420 items = db.select(table,
acaa3371 » Kragen Javier Sitaker
2008-04-17 Test-covered and reformatted more of webapp.py.
421 what="*, 100*(%s/$maxnum) as pct" % what,
422 order='%s desc' % what,
423 where='%s is not null' % what,
08827f06 »
2008-04-17 add speech information to pol pages
424 vars=locals()).list()
425 for item in items:
426 if table == 'district':
427 item.id = 'd' + item.name
428 item.path = '/us/' + item.name.lower()
429 elif table == 'politician':
67822efd »
2008-06-17 typos and small fixes
430 item.name = '%s %s (%s-%s)' % (item.firstname, item.lastname,
5d972e80 »
2008-09-20 fix crasher
431 (item.party or 'I')[0], item.district_id.split('-')[0])
08827f06 »
2008-04-17 add speech information to pol pages
432 item.path = '/p/' + item.id
433 return render.dproperty(items, what)
320eb4d6 » Aaron Swartz
2008-04-04 add about, zip2rep
434
f0292a20 » jdthomas
2008-10-14 Add sparkline numbers to district pages.
435 def sparkpos(table, what, id):
436 if table == 'district':
437 id_col = 'name'
438 id = id.upper()
439 elif table == 'politician':
440 id_col= 'id'
441 else: return 0
917d8a5a »
2008-10-14 fix sql injection; show earmark recipients
442 assert table in table_map.values()
443 if not r_safeproperty.match(what): raise web.notfound
444
445 item = db.query("select count(*) as position from %(table)s, \
446 (select * from %(table)s where %(id_col)s=$id) as a \
447 where %(table)s.%(what)s > a.%(what)s" %
448 {'table':table, 'what':what, 'id_col':id_col}, vars={'id': id})[0]
7445e5a8 » jdthomas
2008-10-13 Add number ranking to sparklines.
449 return item.position + 1 # '#1' looks better than '#0'
450
7c658677 » Aaron Swartz
2008-04-05 more data, some first stabs at graphs
451 class sparkdist:
08827f06 »
2008-04-17 add speech information to pol pages
452 def GET(self, table, what):
453 try:
454 table = table_map[table]
455 except KeyError:
456 raise web.notfound
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
457 if not r_safeproperty.match(what): raise web.notfound
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
458
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
459 inp = web.input(point=None)
dabdbd04 »
2008-04-24 flip order of the sparklines to be less confusing
460 points = db.select(table, what=what, order=what+' asc', where=what+' is not null')
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
461 points = [x[what] for x in points.list()]
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
462
7c658677 » Aaron Swartz
2008-04-05 more data, some first stabs at graphs
463 web.header('Content-Type', 'image/png')
4eee6b06 » Aaron Swartz
2008-04-11 add population, distribution pages for each, code and url cleanup
464 return simplegraphs.sparkline(points, inp.point)
7c658677 » Aaron Swartz
2008-04-05 more data, some first stabs at graphs
465
798035f8 »
2008-04-14 add support for photos
466 class staticdata:
467 def GET(self, path):
468 if not web.config.debug:
469 raise web.notfound
470
471 assert '..' not in path, 'security'
472 return file('data/' + path).read()
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
473
d6e03b5e » Aaron Swartz
2008-04-04 add web.py to REQUISITES
474 app = web.application(urls, globals())
50572a09 » Rebecca Malamud
2008-10-25 webchick redesign
475 def notfound():
476 web.ctx.status = '404 Not Found'
477 return getattr(render, '404')()
478
03d027e7 »
2008-11-18 better 500 messages
479 def internalerror():
b33a4ee3 » asldevi
2008-12-11 use web.internalerror for internal error
480 return web.internalerror(file('templates/500.html').read())
03d027e7 »
2008-11-18 better 500 messages
481
50572a09 » Rebecca Malamud
2008-10-25 webchick redesign
482 app.notfound = notfound
2dba2db6 » asldevi
2008-10-13 using production mode from environment, use the same for writerep too
483 if production_mode:
03d027e7 »
2008-11-18 better 500 messages
484 app.internalerror = web.emailerrors(config.send_errors_to, internalerror)
c3bc5331 » Simon Carstensen
2008-09-05 Petition UI: require sign up to create a new petition, new petition page
485
145202c6 » Aaron Swartz
2008-04-05 add newlines; fix gmaps api key
486 if __name__ == "__main__": app.run()
Something went wrong with that request. Please try again.