Skip to content

Commit

Permalink
move functions to dashboard.utils
Browse files Browse the repository at this point in the history
`get_hackathon_event`, `get_tribe`, `tribe_fields`,
and `hackathons_funded`
  • Loading branch information
walidmujahid committed Apr 14, 2020
1 parent 819946f commit 134dac3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
46 changes: 45 additions & 1 deletion app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
47 changes: 2 additions & 45 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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."""

Expand Down

0 comments on commit 134dac3

Please sign in to comment.