Files
www.gittip.com/www/index.html
Chad Whitacre e8be1932cf Make homepage box friendlier for ANON; #644
This takes the intimidating search-ish box on the homepage and only
shows it to non-ANON. ANON gets a join prompt that redirects to giving/.
2013-02-14 00:47:34 -05:00

241 lines
8.3 KiB
HTML

from aspen import Response
from gittip import db, AMOUNTS
from gittip.elsewhere import github
from aspen.utils import to_age
def _extract_avatar(participant_id):
# XXX This can be replaced with Participant.get_img_src when we convert
# this simplate to use the ORM.
# https://github.com/zetaweb/www.gittip.com/issues/541
out = '/assets/-/avatar-default.gif'
recs = db.fetchall("""
SELECT user_info
FROM elsewhere
WHERE participant_id=%s
ORDER BY platform
""", (participant_id,))
try:
rec = recs.next()
except StopIteration:
return out # XXX We need to take orphan accounts out of queries in the
# caller. See:
# https://github.com/zetaweb/www.gittip.com/issues/650
#raise Exception("%s has no elsewheres?" % participant_id)
user_info = rec.get('user_info', {})
if 'profile_image_url_https' in user_info:
# XXX Attack vector? Can someone inject this value? Don't think so,
# but ...
out = user_info['profile_image_url_https']
elif 'avatar_url' in user_info:
out = user_info['avatar_url']
return out
def _to_age(participant):
# XXX I can't believe I'm doing this. Evolve aspen.utils.to_age!
age = to_age(participant['claimed_time'], fmt_past="%(age)s")
age = age.replace('just a moment', 'just now')
age = age.replace('an ', '1 ').replace('a ', '1 ')
words = ('zero', 'one', 'two','three', 'four', 'five', 'six', 'seven',
'eight', 'nine')
for i, word in enumerate(words):
age = age.replace(word, str(i))
return age.replace(' ', ' <span class="unit">') + "</span>"
^L
try:
limit = min(int(qs.get('limit', 10)), 100)
offset = int(qs.get('offset', 0))
except ValueError:
raise Response(400)
new_participants = db.fetchall("""
SELECT id, claimed_time FROM (
SELECT DISTINCT ON (p.id)
p.id
, claimed_time
FROM participants p
JOIN elsewhere e
ON p.id = participant_id
WHERE claimed_time IS NOT null
AND is_suspicious IS NOT true
) AS foo
ORDER BY claimed_time DESC
LIMIT %s
OFFSET %s
""", (limit, offset))
givers = db.fetchall("""
SELECT tipper, anonymous, sum(amount) AS amount
FROM ( SELECT DISTINCT ON (tipper, tippee)
amount
, tipper
FROM tips
JOIN participants p ON p.id = tipper
JOIN participants p2 ON p2.id = tippee
JOIN elsewhere ON elsewhere.participant_id = tippee
WHERE p.last_bill_result = ''
AND p.is_suspicious IS NOT true
AND p2.claimed_time IS NOT NULL
AND elsewhere.is_locked = false
ORDER BY tipper, tippee, mtime DESC
) AS foo
JOIN participants p ON p.id = tipper
WHERE is_suspicious IS NOT true
GROUP BY tipper, anonymous
ORDER BY amount DESC
LIMIT %s
OFFSET %s
""", (limit, offset))
# XXX I'm nearly positive that one or both of givers and receivers can contain
# orphan accounts. See https://github.com/zetaweb/www.gittip.com/issues/650
receivers = db.fetchall("""
SELECT tippee, claimed_time, sum(amount) AS amount
FROM ( SELECT DISTINCT ON (tipper, tippee)
amount
, tippee
FROM tips
JOIN participants p ON p.id = tipper
JOIN elsewhere ON elsewhere.participant_id = tippee
WHERE last_bill_result = ''
AND elsewhere.is_locked = false
AND is_suspicious IS NOT true
AND claimed_time IS NOT null
ORDER BY tipper, tippee, mtime DESC
) AS foo
JOIN participants p ON p.id = tippee
WHERE is_suspicious IS NOT true
GROUP BY tippee, claimed_time
ORDER BY amount DESC
LIMIT %s
OFFSET %s
""", (limit, offset))
^L
{% extends templates/base.html %}
{% block head %}
<script>$(document).ready(Gittip.initJumpToPerson);</script>
{% end %}
{% block heading %}
<h2 class="top"><span>Weekly Cash Gifts</span></h2>
<h1>
<span>Inspiring Generosity</span>
</h1>
<h2 class="bottom">
<span class="button-container">
<a href="/about/"><button class="selected">About</button></a>
</span>
</h2>
{% end %}
{% block box %}
<div class="as-content">
<h1>Who inspires you?</h1>
{% if user.ANON %}
Join with
<a class="highlight" href="{{ twitter.oauth_url(website, u'opt-in', u'/about/me/giving/') }}">Twitter</a>
or
<a href="{{ github.oauth_url(website, u'opt-in', u'/about/me/giving/') }}">GitHub</a>
to give back.
{% else %}
<form id="jump">
<span class="luxury">Enter a</span> <select>
<option value="twitter">Twitter</option>
<option value="github">GitHub</option>
</select> username:
<span class="nowrap">
<input placeholder="" />
<button type="submit">Go</button>
</span>
</form>
{% end %}
</div>
{% end %}
{% block page %}
<div id="leaderboard">
<div class="new-participants">
<h2>New Participants</h2>
<ul class="group">
{% for i, participant in enumerate(new_participants, start=1) %}
<li{% if i > 6 %} class="luxury"{% end %}>
<a href="/{{ participant['id'] }}/" class="mini-user">
<span class="inner">
<span class="avatar"
style="background-image: url('{{ _extract_avatar(participant['id']) }}')">
<span class="rank">{{ i }}</span>
</span>
<span class="age">{{ _to_age(participant) }}</span>
<span class="name">{{ participant['id'] }}</span>
</span>
</a>
</li>
{% end %}
</ul>
</div>
<div class="top-givers">
<h2>Top Givers</h2>
<ul class="group">
{% for i, giver in enumerate(givers, start=1) %}
<li{% if i > 6 %} class="luxury"{% end %}>
{% if giver['anonymous'] and not user.is_admin %}
<span class="mini-user">
<span class="inner">
<span class="avatar">
<span class="rank">{{ i }}</span>
</span>
<span class="money">${{ giver['amount'] }}</span>
<span class="name">???</span>
</span>
</span>
{% else %}
<a href="/{{ giver['tipper'] }}/"
class="mini-user{{ ' anonymous' if giver['anonymous'] else '' }}">
<span class="inner">
<span class="avatar"
style="background-image: url('{{ _extract_avatar(giver['tipper']) }}')">
<span class="rank">{{ i }}</span>
</span>
<span class="money">${{ giver['amount'] }}</span>
<span class="name">{{ giver['tipper'] }}</span>
</span>
</a>
{% end %}
</li>
{% end %}
</ul>
</div>
<div class="top-receivers">
<h2>Top Receivers</h2>
<ul class="group">
{% for i, receiver in enumerate(receivers, start=1) %}
<li{% if i > 6 %} class="luxury"{% end %}>
<a href="/{{ receiver['tippee'] }}/" class="mini-user">
<span class="inner">
<span class="avatar"
style="background-image: url('{{ _extract_avatar(receiver['tippee']) }}')">
<span class="rank">{{ i }}</span>
</span>
<span class="money">${{ receiver['amount'] }}</span>
<span class="name">{{ receiver['tippee'] }}</span>
</span>
</a>
</li>
{% end %}
</ul>
</div>
</div>
{% end %}