diff --git a/app/dashboard/utils.py b/app/dashboard/utils.py index f6bc5e6064a..8ceafeb8d48 100644 --- a/app/dashboard/utils.py +++ b/app/dashboard/utils.py @@ -863,7 +863,7 @@ def get_nonce(network, address, ignore_db=False): nonce_from_web3 = w3.eth.getTransactionCount(address) if ignore_db: return nonce_from_web3 - + # db storage key = f"nonce_{network}_{address}" view = 'get_nonce' @@ -998,3 +998,47 @@ def list_urls(lis, acc=None): def get_custom_avatars(profile): return CustomAvatar.objects.filter(profile=profile).order_by('-id') + + +def get_hackathon_event(title, event, network): + event_bounties = Bounty.objects.filter(event=event, network=network) + + return { + 'title': title, + 'hackathon': event, + 'value_in_usdt': sum( + prize_usdt.value_in_usdt_now + for prize_usdt + in event_bounties + ), + 'registrants': HackathonRegistration.objects.filter(hackathon=event).count() + } + + +def get_tribe(display_name, logo_path, handle): + return { + 'display_name': display_name, + 'logo_path': logo_path, + 'members': list(Profile.objects.filter(handle=handle, is_org=True).values_list('follower_count', flat=True))[0], + 'path': list(Profile.objects.filter(handle=handle, is_org=True))[0].absolute_url + } + + +def tribe_fields(network): + return { + (bounty.org_display_name, bounty.avatar_url, bounty.org_name) + for bounty in list(Bounty.objects.current()\ + .filter(event__isnull=False, network=network) + ) + } + +# count distinct hackathon events in which a tribe has participated +def hackathons_funded(funding_organisation, network, hackathons): + return Bounty.objects.current()\ + .filter( + funding_organisation=funding_organisation, + network=network, + event__in=list(hackathons) + )\ + .distinct('event')\ + .count() diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 9c48d4c3974..95a171c3267 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -109,7 +109,8 @@ from .utils import ( apply_new_bounty_deadline, get_bounty, get_bounty_id, get_context, get_custom_avatars, get_unrated_bounties_count, get_web3, has_tx_mined, is_valid_eth_address, re_market_bounty, record_user_action_on_interest, - release_bounty_to_the_public, sync_payout, web3_process_bounty, + release_bounty_to_the_public, sync_payout, web3_process_bounty, get_hackathon_event, get_tribe, + tribe_fields, hackathons_funded ) logger = logging.getLogger(__name__) @@ -4111,50 +4112,6 @@ def hackathon_registration(request): return JsonResponse({'redirect': redirect}) -def get_hackathon_event(title, event, network): - event_bounties = Bounty.objects.filter(event=event, network=network) - - return { - 'title': title, - 'hackathon': event, - 'value_in_usdt': sum( - prize_usdt.value_in_usdt_now - for prize_usdt - in event_bounties - ), - 'registrants': HackathonRegistration.objects.filter(hackathon=event).count() - } - - -def get_tribe(display_name, logo_path, handle): - return { - 'display_name': display_name, - 'logo_path': logo_path, - 'members': list(Profile.objects.filter(handle=handle, is_org=True).values_list('follower_count', flat=True))[0], - 'path': list(Profile.objects.filter(handle=handle, is_org=True))[0].absolute_url - } - - -def tribe_fields(network): - return { - (bounty.org_display_name, bounty.avatar_url, bounty.org_name) - for bounty in list(Bounty.objects.current()\ - .filter(event__isnull=False, network=network) - ) - } - -# count distinct hackathon events in which a tribe has participated -def hackathons_funded(funding_organisation, network, hackathons): - return Bounty.objects.current()\ - .filter( - funding_organisation=funding_organisation, - network=network, - event__in=list(hackathons) - )\ - .distinct('event')\ - .count() - - def get_hackathons(request): """Handle rendering all Hackathons."""