From 963be5db9acc761efd1ea6336e515c623abef89b Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 3 Apr 2013 21:57:35 -0400 Subject: [PATCH] Get homepage working with username; #287, #680 --- gittip/models/elsewhere.py | 9 +++++---- gittip/models/participant.py | 4 ++-- www/index.html | 38 ++++++++++++++++++------------------ 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/gittip/models/elsewhere.py b/gittip/models/elsewhere.py index e45dd785da..d4d2a1156b 100644 --- a/gittip/models/elsewhere.py +++ b/gittip/models/elsewhere.py @@ -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') ) @@ -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': @@ -27,4 +28,4 @@ def resolve_unclaimed(self): out = '/on/twitter/%s/' % self.user_info['screen_name'] else: out = None - return out \ No newline at end of file + return out diff --git a/gittip/models/participant.py b/gittip/models/participant.py index 72d333c151..c02d1c53b2 100644 --- a/gittip/models/participant.py +++ b/gittip/models/participant.py @@ -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 diff --git a/www/index.html b/www/index.html index c4dd56ed69..fdae90ebde 100644 --- a/www/index.html +++ b/www/index.html @@ -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 @@ -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 @@ -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 @@ -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 @@ -141,7 +141,7 @@

New Participants