Skip to content

Commit

Permalink
adding channel cloud on front page [#2 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
ericw committed Aug 12, 2008
1 parent 0a5627f commit 1da9205
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 1 addition & 3 deletions index.html
Expand Up @@ -15,9 +15,7 @@ <h1>Onelinr <span>by <a href="http://eric.wahlforss.com/2007/04/06/onelinr/">Eri
</script>
<h2>Active Onelinr Channels</h2>
<ul id="channel-cloud">
{% for ch in channels %}
<li class=""><a href="/{{ch.name}}">{{ch.name}}</a></li>
{% endfor %}
{{channelCloud}}
</ul>
<div id="changelog">
<h3>Changelog</h3>
Expand Down
2 changes: 1 addition & 1 deletion index.yaml
Expand Up @@ -28,7 +28,7 @@ indexes:
- name: post_id
direction: desc

# Used 6 times in query history.
# Used 25 times in query history.
- kind: Channel
properties:
- name: post_count
Expand Down
22 changes: 21 additions & 1 deletion onelinr.py
Expand Up @@ -36,7 +36,8 @@ class StartPage(webapp.RequestHandler):
def get(self):
channels = Channel.all()
channels.order("-post_count")
self.response.out.write(template.render('index.html', {'channels':channels}))
channelCloud = renderChannelCloud(channels);
self.response.out.write(template.render('index.html', {'channels':channels,'channelCloud':channelCloud}))

class ChannelPage(webapp.RequestHandler):

Expand Down Expand Up @@ -141,6 +142,25 @@ def main():

run_wsgi_app(application)

# display channel tag cloud
def renderChannelCloud(channels):
max, min = 0, 0
classes = ["size1","size2","size3","size4","size5"]

for c in channels:
if c.post_count > max:
max = c.post_count
if c.post_count < min:
min = c.post_count

divisor = ((max - min) / len(classes)) + 1

channelList = ""
for c in channels:
channelList += "<li class='" + classes[(c.post_count - min) / divisor] + "'><a href='/" + c.name + "'>" + c.name + "</a></li>"

return channelList


def url_to_channel_name(url):
url_array = url.split("/")
Expand Down

0 comments on commit 1da9205

Please sign in to comment.