Skip to content

Commit

Permalink
Add flag to display showcase (#7087)
Browse files Browse the repository at this point in the history
* Add flag to display showcase

* Display showcase on the hackathon cards

* Fix performance issues on calc winners

* Add admin action to update showcase info

* Add cache function in `create_page_cache`

* Fix migration

* fix isort

Co-authored-by: Dan Lipert <[email protected]>
  • Loading branch information
zoek1 and danlipert authored Jul 28, 2020
1 parent d6b795a commit 0745546
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
path('hackathon/onboard/<str:hackathon>', dashboard.views.hackathon_onboard, name='hackathon_onboard2'),
path('hackathon/onboard/<str:hackathon>/', dashboard.views.hackathon_onboard, name='hackathon_onboard3'),
path('hackathon/<str:hackathon>/projects/', dashboard.views.hackathon_projects, name='hackathon_projects'),
path('hackathon/<str:hackathon>/showcase/', dashboard.views.hackathon, name='hackathon_showcase_proxy'),
path('hackathon/<str:hackathon>/prizes/', dashboard.views.hackathon, name='hackathon_prizes'),
path(
'hackathon/projects/<str:hackathon>/<str:project>', dashboard.views.hackathon_project, name='hackathon_project'
Expand Down
3 changes: 2 additions & 1 deletion app/assets/v2/js/pages/dashboard-hackathon.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@
hackathonObj: document.hackathonObj,
hackathonSponsors: document.hackathonSponsors,
hackathonProjects: [],
chatURL: document.chatURL
chatURL: document.chatURL,
hackHasEnded: document.displayShowcase
})
});
});
Expand Down
7 changes: 7 additions & 0 deletions app/assets/v2/js/vue-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ Vue.component('showcase', {
vm.spotlights.push(spotlight);
}
},
removeSpotlight: function(index) {
let vm = this;

if (index > -1) {
vm.spotlights.splice(index, 1);
}
},
saveShowcase: function() {
let vm = this;
const resource_url = `/api/v0.1/hackathon/${document.hackathonObj.id}/showcase/`;
Expand Down
8 changes: 8 additions & 0 deletions app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ class HackathonEventAdmin(admin.ModelAdmin):
list_display = ['pk', 'img', 'name', 'start_date', 'end_date', 'explorer_link']
list_filter = ('sponsor_profiles', )
readonly_fields = ['img', 'explorer_link', 'stats', 'view_count']
actions = ['calculate_winners']

def calculate_winners(self, request, queryset):
for hackathon in queryset:
hackathon.get_total_prizes(force=True)
hackathon.get_total_winners(force=True)

calculate_winners.short_description = "Showcase - Update winners and bounties"

def view_count(self, instance):
return instance.get_view_count
Expand Down
19 changes: 19 additions & 0 deletions app/dashboard/migrations/0131_auto_20200727_1511.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.4 on 2020-07-27 15:11

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0130_auto_20200727_0628'),
]

operations = [
migrations.AddField(
model_name='hackathonevent',
name='display_showcase',
field=models.BooleanField(default=False),
),
]
18 changes: 18 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import logging
from datetime import datetime, timedelta
from decimal import Decimal
from functools import reduce
from urllib.parse import urlsplit

from django.conf import settings
Expand Down Expand Up @@ -4707,6 +4708,7 @@ class HackathonEvent(SuperModel):
visible = models.BooleanField(help_text=_('Can this HackathonEvent be seeing on /hackathons ?'), default=True)
default_channels = ArrayField(models.CharField(max_length=255), blank=True, default=list)
objects = HackathonEventQuerySet.as_manager()
display_showcase = models.BooleanField(default=False)
showcase = JSONField(default=dict, blank=True, null=True)

def __str__(self):
Expand Down Expand Up @@ -4734,6 +4736,22 @@ def get_absolute_url(self):
"""
return settings.BASE_URL + self.relative_url

def get_total_prizes(self, force=False):
if force or self.showcase.get('prizes_count') is None:
prizes_count = Bounty.objects.filter(event=self).distinct().count()
self.showcase['prizes_count'] = prizes_count
self.save()

return self.showcase.get('prizes_count', 0)

def get_total_winners(self, force=False):
if force or self.showcase.get('winners_count') is None:
bounties = Bounty.objects.filter(event=self).distinct()
self.showcase['winners_count'] = reduce(lambda total, prize: total + len(prize.paid), bounties, 0)
self.save()

return self.showcase.get('winners_count', 0)

@property
def onboard_url(self):
return self.get_onboard_url()
Expand Down
8 changes: 8 additions & 0 deletions app/dashboard/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class Meta:
class HackathonEventSerializer(serializers.ModelSerializer):
"""Handle serializing the hackathon object."""
sponsor_profiles = ProfileSerializer(many=True)
prizes = serializers.SerializerMethodField()
winners = serializers.SerializerMethodField()

def get_prizes(self, obj):
return obj.get_total_prizes()

def get_winners(self, obj):
return obj.get_total_winners()

class Meta:
"""Define the hackathon serializer metadata."""
Expand Down
6 changes: 6 additions & 0 deletions app/dashboard/templates/dashboard/hackathon/hackathons.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ <h5 class="font-subheader font-weight-semibold">
Projects
</a>
{% endif %}
{% if hackathon.display_showcase %}
<a href="{% url 'hackathon_showcase_proxy' hackathon.slug %}" class="btn btn-gc-blue font-caption font-weight-semibold px-3 mb-2">
<i class="fas fa-rocket mr-2 d-none d-sm-inline"></i>
Showcase
</a>
{% endif %}
</div>
</div>
</div>
Expand Down
12 changes: 8 additions & 4 deletions app/dashboard/templates/dashboard/index-vue.html
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ <h6 class="font-weight-bold mb-3">Invite [[numUsers]] Users to the Bounty</h6>
</div>
</user-directory>
</b-tab>
<b-tab class="col-12" title-item-class="navigation">
<b-tab class="col-12" title-item-class="navigation" v-if="hackHasEnded">
<template v-slot:title>
<div class="mt-4">
{% trans "Showcase" %}
Expand Down Expand Up @@ -678,7 +678,7 @@ <h4 class="font-bigger-1 font-weight-bold">#HackGoals</h4>
</div>
<div class="spotlight">
<h4 class="font-bigger-1 font-weight-bold mb-sm-3">Hacking Spotlights</h4>
<div v-for="spotlight in spotlights">
<div v-for="(spotlight, index) in spotlights">
<div class="d-md-flex pt-2" v-if="!isEditing">
<div class="col-12 col-md-3 my-3 text-center" style="margin-top: auto !important; margin-bottom: auto !important;">
<div class="d-flex text-center mb-3 justify-content-center align-items-center">
Expand All @@ -695,11 +695,14 @@ <h4 class="font-bigger-1 font-weight-bold mb-sm-3">Hacking Spotlights</h4>
</div>

<div class="d-flex" v-if="isEditing">
<select class="d-flex col-12 col-md-3 form-control" v-model="spotlight.sponsor">
<div class="d-flex col-12 col-md-3 flex-column align-items-baseline">
<select class="form-control" v-model="spotlight.sponsor">
<option v-for="sponsor in sponsors" :value="sponsor.org_name">
<span>[[sponsor.org_name]]</span>
</option>
</select>
<button class="btn btn-link text-highlight-pink mt-2" @click="removeSpotlight(index)">- Remove Spotlight</button>
</div>
<textarea class="d-flex col-12 ml-md-3 col-md-8 form-control mb-4" v-model="spotlight.content" name="content" id="" cols="90" rows="8"></textarea>
</div>
</div>
Expand Down Expand Up @@ -744,7 +747,7 @@ <h4 class="font-bigger-1 font-weight-bold mb-3">[[hackathon.name]] Wall of Fame<
</div>

</b-tab>
<template v-slot:tabs-end>
<template v-slot:tabs-end v-if="!hackHasEnded">
<li role="presentation" class="nav-item navigation">
<a href="{% url 'hackathon_onboard' hackathon.slug %}" class="text-reset text-decoration-none nav-link">
<div class="mt-4">Guide</div>
Expand Down Expand Up @@ -828,6 +831,7 @@ <h4 class="font-bigger-1 font-weight-bold mb-3">[[hackathon.name]] Wall of Fame<
document.hackathonObj = JSON.parse(document.getElementById('hackathon-object').textContent);
document.activePanel = parseInt({{panel | safe}});
document.chatURL = "{{ chat_url | safe}}";
document.displayShowcase = {{hackathon.display_showcase|yesno:"true,false" }}
if(location.hostname === 'gitcoin.co') $('#network-filter').hide();
</script>
<script src='{% static "v2/js/pages/dashboard-hackathon.js" %}'></script>
Expand Down
9 changes: 8 additions & 1 deletion app/perftools/management/commands/create_page_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from django.utils.encoding import force_text
from django.utils.functional import Promise

from dashboard.models import Profile
from dashboard.models import HackathonEvent, Profile
from economy.models import EncodeAnything, SuperModel
from perftools.models import JSONStore
from retail.utils import build_stat_results, programming_languages
Expand Down Expand Up @@ -211,6 +211,12 @@ def create_quests_cache():
quest.save()


def create_hackathon_cache():
for hackathon in HackathonEvent.objects.filter(display_showcase=True):
hackathon.get_total_prizes(force=True)
hackathon.get_total_winners(force=True)


def create_results_cache():
print('results')
keywords = ['']
Expand Down Expand Up @@ -271,3 +277,4 @@ def handle(self, *args, **options):
create_quests_cache()
create_grants_cache()
create_contributor_landing_page_context()
create_hackathon_cache()

0 comments on commit 0745546

Please sign in to comment.