Skip to content
Browse files

cleanup style, improve accessibility and add text for home page.

  • Loading branch information...
1 parent ad29c14 commit 338d195ecf29ba14979567817b2641e024d06a39 @anandology committed Apr 20, 2009
View
2 config.py
@@ -5,4 +5,4 @@
search_db = "db"
maproot = "http://maps.electionspot.in/KMAP"
-
+cache = True
View
14 db.py
@@ -33,13 +33,19 @@ def storify(d):
return d
def list_parties():
- result = getdb().query("SELECT * FROM party").list()
+ result = getdb().query("SELECT * FROM party ORDER BY shortname").list()
for row in result:
row.id = "party/" + row.id
return result
-
-def list_constituencies():
- pass
+
+def list_states():
+ return getdb().query("SELECT * FROM state ORDER BY union_teritory, name").list()
+
+def list_constituencies(state_id):
+ result = getdb().query("SELECT * FROM constituency WHERE state=$state_id ORDER BY name", vars=locals()).list()
+ for row in result:
+ row.id = state_id + "/" + row.id
+ return result
def get_party(id):
def parse(d):
View
19 scripts/parse.py
@@ -54,12 +54,25 @@ def extract_text(soup):
return ''.join([htmlunquote(str(e).strip()) for e in soup.recursiveChildGenerator() if isinstance(e,unicode)])
def parse_table(table):
- return [[extract_text(td) for td in tr.findAll("td")] for tr in table.findAll("tr")]
+ return [[extract_text(td) for td in tr.findAll("td")] for tr in table.findAll(["tr", "tr ", "tr "])]
def extract_tables(filename):
soup = BeautifulSoup(open(filename).read())
return [parse_table(t) for t in soup.findAll("table")]
+def parse_affidavit(filename):
+ """Parse affidavit data from myneta.info
+ """
+ soup = BeautifulSoup(open(filename).read())
+
+ for t in soup.findAll(["h2", "h3", "table"]):
+ if t.name in ["h2", "h3"]:
+ print "---"
+ print "**", extract_text(t)
+ print
+ elif t.name == "table":
+ pprint.pprint(parse_table(t))
+
def parse_summary(filename):
"""Parse election analysis summary file..
@@ -143,7 +156,9 @@ def main(filetype, filename):
elif filetype == "summary":
print simplejson.dumps(parse_election_analysis(filename), indent=4)
elif filetype == "report":
- print simplejson.dumps(parse_report(filetype), indent=4)
+ print simplejson.dumps(parse_report(filename), indent=4)
+ elif filetype == "affidavit":
+ print simplejson.dumps(parse_affidavit(filename), indent=4)
elif filetype == "summary_json":
print parse_summary_json(filename)
else:
View
44 static/css/style.css
@@ -135,28 +135,26 @@ h1, h2, h3, h4 {
}
#content {
- clear: both;
+ clear: both;
min-height: 350px;
}
#facts {
- width: 58%;
- float: left;
- margin: 5px;
+ margin: 5px;
}
#map {
- width: 38%;
- float: left;
- margin: 5px;
- border: 1px dotted #064B4C;
- height: 500px;
+ width: 360px;
+ float: right;
+ margin: 5px;
}
+
#map iframe {
- width: 100%;
- height: 100%;
- border: 0px;
+ width: 350px;
+ height: 400px;
+ border: 1px dotted #064B4C;
}
+
#footer {
margin-top: 10px;
border-top: 1px solid #064B4C;
@@ -172,24 +170,24 @@ h1, h2, h3, h4 {
}
.infoTable {
- margin: 10px;
- width: 90%;
- border: 1px solid #8CC9CA;
+ width: 500px;
+ margin: 10px;
+ border: 1px solid #8CC9CA;
}
.infoTable th {
- text-align: left;
- padding: 5px;
- background-color: #8CC9CA;
+ text-align: left;
+ padding: 5px;
+ background-color: #8CC9CA;
}
.infoTable td {
- padding: 5px;
+ padding: 5px;
}
.infoTable .key {
- text-align: right;
- border-right: 1px dotted #8CC9CA;
+ text-align: right;
+ border-right: 1px dotted #8CC9CA;
}
#footerMenu {
@@ -212,7 +210,7 @@ h1, h2, h3, h4 {
clear: both;
padding: 5px;
}
-tr { height: 50px;}
+tr { padding: 2px 0px; }
tr.odd {background-color: #eee; }
tr.even { }
tr.header { color: #9C3236;}
@@ -237,4 +235,4 @@ div .searchresult a {
.party-logo {
width: 20px;
height: 20px;
-}
+}
View
0 static/images/bjp.gif → static/images/party/BJP.gif
File renamed without changes
View
BIN static/images/party/INC.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN static/logos/bjp.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 templates/candidate.html
@@ -2,8 +2,14 @@
$var title: $d.name
+<div id="map">
+ <iframe src="$maproot/kmap.html?w=350&h=400">
+ </iframe>
+ <div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
+</div>
+
<div id="facts">
-<h2>$d.name</h2>
+ <h2>$d.name</h2>
<div id="photo"></div>
@@ -34,9 +40,3 @@
<div class="disclaimer">Election data from <a href="http://eci.nic.in">http://eci.nic.in</a></div>
</div>
</div>
-
-<div id="map">
- <iframe src="$maproot/kmap.html">
- </iframe>
- <div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
-</div>
View
19 templates/constituency.html
@@ -8,11 +8,17 @@
onerror="this.src = '/static/images/notfound.gif';"/></a>
<a href="/$c.party.id">$c.party.shortname</a>
-<!-- Breadcrumbs -->
-<div id="breadcrumbs">
- <a href="/">Home</a> » <a href="/states">States</a> » <a href="/$d.state.id">$d.state.name</a> » $d.name
+<div id="map">
+ <iframe src="$maproot/kmap.html?w=350&h=400&s=$d.state.id.lower()&c=$d.id.split('/')[-1]">
+ </iframe>
+ <div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
+
+ <h3>Constituencies in $d.state.name</h3>
+ $for c in list_constituencies(d.state.id):
+ $if not loop.first: |
+ $if c.id == d.id: <b>$c.name</b>
+ $else: <a href="/$c.id">$c.name</a>
</div>
-<!-- Breadcrumbs end -->
<div id="facts">
<h2>$d.name, <a href="/$d.state.id.lower()">$d.state.name</a></h2>
@@ -62,8 +68,3 @@ <h3 class='section-label'>Election History</h3>
</div>
-<div id="map">
-<iframe src="$maproot/kmap.html?w=350&h=500&s=$d.state.id.lower()&c=$d.id.split('/')[-1]">
-</iframe>
-<div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
-</div>
View
41 templates/home.html
@@ -2,15 +2,42 @@
$var title: Welcome
+<div id="map">
+ <iframe src="$maproot/kmap.html?w=350&h=400"></iframe>
+ <div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
+
+ <div>
+ <h3>States/Union Teritories</h3>
+ $for s in list_states():
+ $if not loop.first: |
+ <a href="/$s.id">$s.name</a>
+ </div>
+</div>
<div id="facts">
-<h2>India</h2>
+<h2>Welcome</h2>
-Summary comes here.
+ <p>
+ electionspot.in is a small beginning towards providing information on
+ the Indian elections freely and openly on the Internet. Most of the
+ data currently on this site is from reports of the election
+ commission. These were hitherto embedded volumes in pdf
+ documents. We have crawlled the data, parsed it, curated it and
+ presented present them in tables, charts and maps that will be
+ intuitive and attractive to the common man.
+ </p>
+
+ <p>
+ The data deployed on the site is freely available to all using JSON
+ APIs.
+ </p>
+ <p>
+ Our motives go beyond the current elections. We believe we have a
+ platform and technology where we can attractive provide data on the
+ Indian sub-continent for strengthening the Indian democratic
+ system. We solicit collaboration and cooperation of individuals,
+ interested groups, NGOS, Government and corporates.
+ </p>
+
</div>
-<!-- Map -->
-<div id="map">
- <iframe id="map" src="$maproot/kmap.html?w=350&h=500"></iframe>
-</div>
-<!-- Map ends -->
View
74 templates/layout.html
@@ -2,47 +2,35 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
- <head>
- <link rel="stylesheet" href="/static/css/style.css"/>
- <title>$page.get("title", "Welcome") - Electionspot</title>
- </head>
- <body>
- <!-- Wrapper -->
- <div id="wrapper">
- <!-- Header -->
- <div id="header">
- <div id="branding">
- <a href="/"><img src="/static/images/logo.png" alt="Election Spot"></a>
- <div id="byline">Information on Election Constituencies in India</div>
- </div>
-
- <div id="searchBox">
- <form action="/search">
- <input type="text" name="q" class="searchInput" />
- <input type="submit" value="Search" />
- </form>
- </div>
- </div>
- <!-- Header ends -->
- <!-- Menu -->
- <div id="menu">
- <ul>
- <li><a href="/">Home</a></li>
- <li><a href="/about">About</a></li>
- <!--<li><a href="states.html">States &amp; Union Territories</a></li>
- <li><a href="list.html">Alphabetical List of Lok Sabha Constituencies</a></li>-->
- </ul>
- </div>
- <!-- Menu ends -->
- <!-- Content -->
- <div id="content">
- $:page
- </div>
- <!-- Content ends -->
- <!-- Footer -->
- <br style="clear:both;"/>
- <!-- Footer ends -->
- </div>
- <!-- Wrapper ends -->
- </body>
+ <head>
+ <link rel="stylesheet" href="/static/css/style.css"/>
+ <title>$page.get("title", "Welcome") - Electionspot</title>
+ </head>
+<body>
+ <div id="wrapper">
+ <div id="header">
+ <div id="branding">
+ <a href="/"><img src="/static/images/logo.png" alt="Election Spot"></a>
+ <div id="byline">Information on Election Constituencies in India</div>
+ </div>
+
+ <div id="searchBox">
+ <form action="/search">
+ <input type="text" name="q" class="searchInput" />
+ <input type="submit" value="Search" />
+ </form>
+ </div>
+ </div>
+ <div id="menu">
+ <ul>
+ <li><a href="/">Home</a></li>
+ <li><a href="/about">About</a></li>
+ </ul>
+ </div>
+ <div id="content">
+ $:page
+ <br style="clear:both;"/>
+ </div>
+ </div>
+</body>
</html>
View
17 templates/party.html
@@ -28,7 +28,13 @@
chart.set_axis_labels("x", [p.year for p in d.performance][::-1])
chart.set_axis_labels("y", range(0, ymax+1, ystep))
-<!-- Facts -->
+<div id="map">
+ <iframe src="$maproot/kmap.html?w=350&h=400"></iframe>
+ <div class="disclaimer">
+ Map provided by <a href="http://www.gslab.com/">GS Lab</a>
+ </div>
+</div>
+
<div id="facts">
<h2>$d.name</h2>
<div class="subtitle">Political Party</div>
@@ -54,12 +60,3 @@
<div class="disclaimer">Election data from <a href="http://eci.nic.in">http://eci.nic.in</a></div>
</div>
-<!-- Facts end -->
-
-
-<!-- Map -->
-<div id="map">
- <iframe id="map" src="$maproot/kmap.html?w=350&h=500"></iframe>
-<div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
-</div>
-<!-- Map ends -->
View
23 templates/state.html
@@ -9,9 +9,20 @@
chart.set_pie_labels([data.party.shortname for data in year_data])
<img src="$chart.get_url()"/>
-<!-- Breadcrumbs -->
-<div id="breadcrumbs">
- <a href="/">Home</a> » <a href="/states">States</a> » $d.name
+<div id="map">
+ <iframe src="$maproot/kmap.html?w=350&h=400&s=$d.id.lower()"></iframe>
+ <div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
+ <h3>Constituencies in $d.name</h3>
+ $for c in list_constituencies(d.id):
+ $if not loop.first: |
+ <a href="/$c.id">$c.name</a>
+ <div>
+ <h3>States/Union Teritories</h3>
+ $for s in list_states():
+ $if not loop.first: |
+ $if s.id == d.id: <b>$s.name</b>
+ $else: <a href="/$s.id">$s.name</a>
+ </div>
</div>
<div id="facts">
@@ -40,9 +51,3 @@
<div class="disclaimer">Election data from <a href="http://eci.nic.in">http://eci.nic.in</a></div>
</div>
-<!-- Map -->
-<div id="map">
- <iframe src="$maproot/kmap.html?w=350&h=500&s=$d.id.lower()"></iframe>
-<div class="disclaimer">Map provided by <a href="http://www.gslab.com/">GS Lab</a></div>
-</div>
-<!-- Map ends -->
View
4 utils.py
@@ -2,6 +2,8 @@
import simplejson
import re
+import config
+
def json_processor(handler):
if web.ctx.path.endswith('.json'):
web.ctx.path = web.ctx.path[:-len(".json")]
@@ -21,7 +23,7 @@ def cache_processor(handler):
Inspired by django.middleware.gzip.GZipMiddleware
"""
ae = web.ctx.env.get('HTTP_ACCEPT_ENCODING', '')
- if web.ctx.method in ["GET", "GET_json"] and re_accepts_gzip.search(ae):
+ if config.cache and web.ctx.method in ["GET", "GET_json"] and re_accepts_gzip.search(ae):
if web.ctx.path not in cache:
data = handler()
cache[web.ctx.fullpath] = compress(web.safestr(data))
View
15 webapp.py
@@ -29,6 +29,9 @@
"changequery": web.changequery,
"GroupedVerticalBarChart": pygooglechart.GroupedVerticalBarChart,
"PieChart": pygooglechart.PieChart2D,
+ "list_states": db.list_states,
+ "list_parties": db.list_parties,
+ "list_constituencies": db.list_constituencies,
}
render = web.template.render("templates", base="layout", globals=tglobals)
app.notfound = lambda: web.notfound(render.notfound(""))
@@ -50,10 +53,15 @@ def GET(self):
class party:
def GET(self, name):
d = db.get_party(name)
+ if d is None:
+ raise web.notfound()
return render.party(d)
def GET_json(self, name):
- return db.get_party(name)
+ d = db.get_party(name)
+ if d is None:
+ raise web.notfound()
+ return d
class candidate:
def GET(self, name):
@@ -76,10 +84,15 @@ def GET(self, name):
class constituency:
def GET(self, state, name):
d = db.get_constituency(state, name)
+ if d is None:
+ raise web.notfound()
return render.constituency(d)
def GET_json(self, state, name):
d = db.get_constituency(state, name)
+ if d is None:
+ raise web.notfound()
+ return d
class do_search:
def GET(self):

0 comments on commit 338d195

Please sign in to comment.
Something went wrong with that request. Please try again.