Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds hackathon results to /results page #5069

Merged
merged 4 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/assets/v2/css/results.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
margin-right: 10px;
}

.navbar{
.navbar {
background-color: #0d023b;
}

Expand Down Expand Up @@ -160,7 +160,6 @@ p.single-stat__fineprint {
color: var(--gc-dark-grey);
}


.bounty-status-breakdown {
display: flex;
align-items: center;
Expand Down Expand Up @@ -228,6 +227,16 @@ p.single-stat__fineprint {
height: auto;
}

.hackathon-breakdown div {
width: 250px;
display: inline-block;
vertical-align: top;
}

.hackathon-breakdown div img {
max-width: 250px;
}

@media screen and (max-width: 768px) {

.content-block {
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class HackathonEventAdmin(admin.ModelAdmin):
"""The admin object for the HackathonEvent model."""

list_display = ['pk', 'img', 'name', 'start_date', 'end_date', 'explorer_link']
readonly_fields = ['img', 'explorer_link']
readonly_fields = ['img', 'explorer_link', 'stats']

def img(self, instance):
"""Returns a formatted HTML img node or 'n/a' if the HackathonEvent has no logo.
Expand Down
15 changes: 15 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3359,6 +3359,21 @@ def __str__(self):
"""
return f'{self.name} - {self.start_date}'

@property
def bounties(self):
return Bounty.objects.filter(event=self).current()

@property
def stats(self):
stats = {
'range': f"{self.start_date.strftime('%m/%d/%Y')} to {self.end_date.strftime('%m/%d/%Y')}",
'num_bounties': self.bounties.count(),
'num_bounties_done': self.bounties.filter(idx_status='done').count(),
'num_bounties_open': self.bounties.filter(idx_status='open').count(),
'total_volume': sum(self.bounties.values_list('_val_usd_db', flat=True)),
}
return stats

def save(self, *args, **kwargs):
"""Define custom handling for saving HackathonEvent."""
from django.utils.text import slugify
Expand Down
26 changes: 25 additions & 1 deletion app/retail/templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="content-block content-block--white">
<div class="container">
<h2 class="content-block__title">
${{ universe_total_usd|floatformat:2|intcomma }} of {% blocktrans %}
${{ universe_total_usd|floatformat:0|intcomma }} of {% blocktrans %}
Gross Marketplace Value
{% endblocktrans %}
{% if keyword %}({{keyword}}){%endif%}
Expand Down Expand Up @@ -133,6 +133,30 @@ <h3 class="single-stat__title">{{ alumni_count }}</h3>
</div>
</div>

<div class="content-block content-block--grey">
<div class="container" >
<h2 class="content-block__title">{{hackathons | length }} {% trans "Virtual Hackathons" %} worth ${{hackathon_total|floatformat:0|intcomma}}.</h2>

<div class="hackathon-breakdown">
{% for hackathon in hackathons %}
{% firstof hackathon.0.logo_svg or hackathon.0.logo as logo %}
<div>
{% if logo %}
<img src="{{MEDIA_URL}}{{logo}}"/>
{%endif %}
<h4>{{hackathon.0.name}}</h4>
{% if hackathon.1.num_bounties %}
<p>{{hackathon.1.num_bounties}} Bounties</p>
<p>${{hackathon.1.total_volume|floatformat:0|intcomma}} In Prizes</p>
{% endif %}
<p>{{hackathon.1.range}}</p>
<a href="{% url 'hackathon' hackathon.0.slug %}">View Prize Explorer</a>
</div>
{% endfor %}
</div>
</div>
</div>

<div class="content-block content-block--white" id="repo_transaction">
<div class="container" >
<h2 class="content-block__title">{% trans "Bounty Status Breakdown" %} {% if keyword %}({{keyword}}){%endif%}</h2>
Expand Down
5 changes: 4 additions & 1 deletion app/retail/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def build_stat_results(keyword=None):
Args:
keyword (str): The keyword to build statistic results.
"""
from dashboard.models import Bounty, Tip
from dashboard.models import Bounty, HackathonEvent, Tip
context = {
'active': 'results',
'title': _('Results'),
Expand Down Expand Up @@ -557,5 +557,8 @@ def build_stat_results(keyword=None):
context['last_month_amount'] = round(sum(bh)/1000)
context['last_month_amount_hourly'] = sum(bh) / 30 / 24
context['last_month_amount_hourly_business_hours'] = context['last_month_amount_hourly'] / 0.222
context['hackathons'] = [(ele, ele.stats) for ele in HackathonEvent.objects.all()]
context['hackathon_total'] = [ele[1]['total_volume'] for ele in context['hackathons']]


return context