Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Get homepage working with username; #287, #680
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Apr 4, 2013
1 parent 553e656 commit 963be5d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
9 changes: 5 additions & 4 deletions gittip/models/elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class Elsewhere(db.Model):
__tablename__ = 'elsewhere'
__table_args__ = (
UniqueConstraint('platform', 'participant_id',
name='elsewhere_platform_participant_id_key'),
UniqueConstraint('platform', 'participant',
name='elsewhere_platform_participant_key'),
UniqueConstraint('platform', 'user_id',
name='elsewhere_platform_user_id_key')
)
Expand All @@ -18,7 +18,8 @@ class Elsewhere(db.Model):
user_id = Column(Text, nullable=False)
user_info = Column(HSTORE)
is_locked = Column(Boolean, default=False, nullable=False)
participant_id = Column(Text, ForeignKey("participants.id"), nullable=False)
participant = Column(Text, ForeignKey("participants.username"), \
nullable=False)

def resolve_unclaimed(self):
if self.platform == 'github':
Expand All @@ -27,4 +28,4 @@ def resolve_unclaimed(self):
out = '/on/twitter/%s/' % self.user_info['screen_name']
else:
out = None
return out
return out
4 changes: 2 additions & 2 deletions gittip/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class Participant(db.Model):

### Relations ###
accounts_elsewhere = relationship( "Elsewhere"
, backref="participant"
, backref="participant_orm"
, lazy="dynamic"
)
exchanges = relationship("Exchange", backref="participant")
exchanges = relationship("Exchange", backref="participant_orm")

# TODO: Once tippee/tipper are renamed to tippee_id/tipper_idd, we can go
# ahead and drop the foreign_keys & rename backrefs to tipper/tippee
Expand Down
38 changes: 19 additions & 19 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""This is a step on the way to ORM-ifying this simplate.
"""
for rec in raw:
out = Participant.query.get(rec['id'])
out = Participant.query.get(rec['username'])
if 'amount' in rec:
out.amount = rec['amount']
yield out
Expand All @@ -33,13 +33,13 @@

new_participants = _wrap(db.fetchall("""

SELECT id, claimed_time FROM (
SELECT DISTINCT ON (p.id)
p.id
SELECT username, claimed_time FROM (
SELECT DISTINCT ON (p.username)
p.username
, claimed_time
FROM participants p
JOIN elsewhere e
ON p.id = participant_id
ON p.username = participant
WHERE claimed_time IS NOT null
AND is_suspicious IS NOT true
) AS foo
Expand All @@ -51,21 +51,21 @@

givers = _wrap(db.fetchall("""

SELECT tipper AS id, anonymous, sum(amount) AS amount
SELECT tipper AS username, 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
JOIN participants p ON p.username = tipper
JOIN participants p2 ON p2.username = tippee
JOIN elsewhere ON elsewhere.participant = 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
JOIN participants p ON p.username = tipper
WHERE is_suspicious IS NOT true
GROUP BY tipper, anonymous
ORDER BY amount DESC
Expand All @@ -79,20 +79,20 @@

receivers = _wrap(db.fetchall("""

SELECT tippee AS id, claimed_time, sum(amount) AS amount
SELECT tippee AS username, 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
JOIN participants p ON p.username = tipper
JOIN elsewhere ON elsewhere.participant = 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
JOIN participants p ON p.username = tippee
WHERE is_suspicious IS NOT true
GROUP BY tippee, claimed_time
ORDER BY amount DESC
Expand Down Expand Up @@ -141,15 +141,15 @@ <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">
<a href="/{{ participant.username }}/" class="mini-user">
<span class="inner">
<span class="avatar"
style="background-image:
url('{{ participant.get_img_src() }}')">
<span class="rank">{{ i }}</span>
</span>
<span class="age">{{ _to_age(participant) }}</span>
<span class="name">{{ participant.id }}</span>
<span class="name">{{ participant.username }}</span>
</span>
</a>
</li>
Expand All @@ -172,15 +172,15 @@ <h2>Top Givers</h2>
</span>
</span>
{% else %}
<a href="/{{ giver.id }}/"
<a href="/{{ giver.username }}/"
class="mini-user{{ ' anonymous' if giver.anonymous else '' }}">
<span class="inner">
<span class="avatar"
style="background-image: url('{{ giver.get_img_src() }}')">
<span class="rank">{{ i }}</span>
</span>
<span class="money">${{ giver.amount }}</span>
<span class="name">{{ giver.id }}</span>
<span class="name">{{ giver.username }}</span>
</span>
</a>
{% end %}
Expand All @@ -193,7 +193,7 @@ <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.id }}/" class="mini-user">
<a href="/{{ receiver.username }}/" class="mini-user">
<span class="inner">
<span class="avatar"
style="background-image: url('{{ receiver.get_img_src() }}')">
Expand Down

0 comments on commit 963be5d

Please sign in to comment.