diff --git a/app/marketing/mails.py b/app/marketing/mails.py index a383bbd4c63..22c463647e9 100644 --- a/app/marketing/mails.py +++ b/app/marketing/mails.py @@ -2018,20 +2018,22 @@ def tribe_hackathon_prizes(hackathon): from dashboard.models import TribeMember, Sponsor from marketing.utils import generate_hackathon_email_intro - sponsors = hackathon.sponsors.all() - tribe_members_in_sponsors = TribeMember.objects.filter(org__in=[sponsor.tribe for sponsor in sponsors]).exclude(status='rejected').exclude(profile__user=None).only('profile') + sponsors = hackathon.sponsor_profiles.all() + tribe_members_in_sponsors = TribeMember.objects.filter(org__in=[sponsor for sponsor in sponsors]).exclude(status='rejected').exclude(profile__user=None).only('profile') for tribe_member in tribe_members_in_sponsors.distinct('profile'): + # Get all records of this tribe_member for each sponsor he is a member of tribe_member_records = tribe_members_in_sponsors.filter(profile=tribe_member.profile) sponsors_prizes = [] - for sponsor in sponsors.filter(tribe__in=[tribe_member_record.org for tribe_member_record in tribe_member_records]): - prizes = hackathon.get_current_bounties.filter(bounty_owner_profile=sponsor.tribe) - sponsor_prize = { - "sponsor": sponsor, - "prizes": prizes - } - sponsors_prizes.append(sponsor_prize) + for sponsor in sponsors: + if sponsor in [tribe_member_record.org for tribe_member_record in tribe_member_records]: + prizes = hackathon.get_current_bounties.filter(bounty_owner_profile=sponsor) + sponsor_prize = { + "sponsor": sponsor, + "prizes": prizes + } + sponsors_prizes.append(sponsor_prize) subject_begin = generate_hackathon_email_intro(sponsors_prizes) subject = f"{subject_begin} participating in {hackathon.name} on Gitcoin 🚀" diff --git a/app/retail/emails.py b/app/retail/emails.py index 6233f500347..6447fde6a49 100644 --- a/app/retail/emails.py +++ b/app/retail/emails.py @@ -1712,8 +1712,8 @@ def tribe_hackathon_prizes(request): hackathon = HackathonEvent.objects.filter(start_date__date=(timezone.now()+timezone.timedelta(days=3))).first() sponsors_prizes = [] - for sponsor in hackathon.sponsors.all()[:3]: - prizes = hackathon.get_current_bounties.filter(bounty_owner_profile=sponsor.tribe) + for sponsor in hackathon.sponsor_profiles.all()[:3]: + prizes = hackathon.get_current_bounties.filter(bounty_owner_profile=sponsor) sponsor_prize = { "sponsor": sponsor, "prizes": prizes