From 31f9afa52076386e5a01ecb9edc3d2177ee3ba2e Mon Sep 17 00:00:00 2001 From: Kevin Owocki Date: Mon, 22 Jun 2020 06:18:24 -0600 Subject: [PATCH] only use a profiles most recent location to mark a location, for leaderboards (#6772) * only use a profiles most recent location to mark a location, for leaderboards * fixes for leaderboard / locations Co-authored-by: Aditya Anand M C Co-authored-by: Dan Lipert --- app/dashboard/models.py | 2 +- app/marketing/management/commands/assemble_leaderboards.py | 3 ++- .../tests/management/commands/test_assemble_leaderboards.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/dashboard/models.py b/app/dashboard/models.py index ddb635e44cd..c38a9e2ad24 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -4210,7 +4210,7 @@ def reassemble_profile_dict(self): def locations(self): from app.utils import get_location_from_ip locations = [] - for login in self.actions.filter(action='Login'): + for login in self.actions.filter(action='Login').order_by('-created_on'): if login.location_data: locations.append(login.location_data) else: diff --git a/app/marketing/management/commands/assemble_leaderboards.py b/app/marketing/management/commands/assemble_leaderboards.py index 03846bc6de0..4b65ceb7930 100644 --- a/app/marketing/management/commands/assemble_leaderboards.py +++ b/app/marketing/management/commands/assemble_leaderboards.py @@ -101,7 +101,8 @@ def profile_to_location_helper(handle): profiles = Profile.objects.filter(handle=handle.lower()) if handle and profiles.exists(): profile = profiles.first() - return profile.locations + if len(profile.locations): + return [profile.locations[0]] return [] diff --git a/app/marketing/tests/management/commands/test_assemble_leaderboards.py b/app/marketing/tests/management/commands/test_assemble_leaderboards.py index 9b9429be921..e3378e05824 100644 --- a/app/marketing/tests/management/commands/test_assemble_leaderboards.py +++ b/app/marketing/tests/management/commands/test_assemble_leaderboards.py @@ -148,7 +148,7 @@ def test_default_ranks(self): def test_bounty_index_terms(self): """Test bounty index terms list.""" index_terms = bounty_index_terms(self.bounty) - assert len(index_terms) == 15 + assert len(index_terms) == 12 assert 'USDT' in index_terms assert {self.bounty_payer_handle, self.bounty_earner_handle, 'gitcoinco'}.issubset(set(index_terms)) '''