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

Added medals in leaderboard #301

Merged
merged 1 commit into from
Jul 8, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions website/migrations/0028_auto_20170705_2359.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2017-07-05 23:59
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('website', '0027_issue_label'),
]

operations = [
migrations.AlterField(
model_name='issue',
name='label',
field=models.PositiveSmallIntegerField(choices=[(0, b'General'), (1, b'Number Error'), (2, b'Functional'), (3, b'Performance'), (4, b'Security'), (5, b'Typo'), (6, b'Design')], default=0),
),
]
20 changes: 20 additions & 0 deletions website/migrations/0029_userprofile_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2017-07-06 06:31
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('website', '0028_auto_20170705_2359'),
]

operations = [
migrations.AddField(
model_name='userprofile',
name='title',
field=models.IntegerField(choices=[(0, b'Unrated'), (1, b'Bronze'), (2, b'Silver'), (3, b'Gold'), (4, b'Platinum')], default=0),
),
]
10 changes: 10 additions & 0 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,19 @@ def user_images_path(instance, filename):


class UserProfile(models.Model):
title = (
(0, 'Unrated'),
(1, 'Bronze'),
(2, 'Silver'),
(3, 'Gold'),
(4, 'Platinum'),
)


user = models.OneToOneField(User, related_name="userprofile")
user_avatar = models.ImageField(upload_to=user_images_path, blank=True, null=True)
title = models.IntegerField(choices=title,default=0)


def avatar(self, size=36):
if self.user_avatar:
Expand Down
6 changes: 3 additions & 3 deletions website/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</label>
{% endif %}
</div>
<select name="label" class="form-control">
<select data-intro="Categorize the bug." data-step="3" name="label" class="form-control">
<option value="0" selected="selected">Bug Type</option>
<option value="1">Number error</option>
<option value="2">Functional</option>
Expand All @@ -144,7 +144,7 @@
{% else %}
<span>
<input type="file" class="required" id='${multipartFilePath}' name="screenshot" onchange="$(this).parent().find('span').html($(this).val().replace('C:\\fakepath\\', ''))"/>
<button class="btn btn-primary" data-intro="Upload a screenshot of the concerned page." data-step="3" name="test_files" type="button" onclick="$(this).parent().find('input[type=file]').click();">
<button class="btn btn-primary" data-intro="Upload a screenshot of the concerned page." data-step="4" name="test_files" type="button" onclick="$(this).parent().find('input[type=file]').click();">
<i class="fa fa-upload" aria-hidden="true"></i> Upload Screenshot
</button>
&nbsp;
Expand All @@ -157,7 +157,7 @@
</label>
{% endif %}
</div>
<button type="submit" name="reportbug_button" id="btn" class="btn btn-default" data-intro="Click here to report the bug to BugHeist." data-step="4">Report Bug</button>
<button type="submit" name="reportbug_button" id="btn" class="btn btn-default" data-intro="Click here to report the bug to BugHeist." data-step="5">Report Bug</button>
<i class="fa fa-trophy" aria-hidden="true">+3</i>
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions website/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ <h3><strong>Design</strong></h3>
<h1 class="page-sub-header">Featured Websites</h1>
</div>
</div>
<div class="row" data-intro="These are the lists of featured websites on BugHeist." data-step="5">
<div class="row" data-intro="These are the lists of featured websites on BugHeist." data-step="6">
{% for domain in domains %}
<div class="col-lg-6 col-md-6">
<div class="panel" id="hunt_{{domain.id}}" style="background-color:{{domain.get_color}}">
Expand Down Expand Up @@ -192,7 +192,7 @@ <h1 class="page-sub-header">Featured Websites</h1>
</div>
</div>

<div class="row" data-intro="View latest activities here." data-step="6">
<div class="row" data-intro="View latest activities here." data-step="7">
<div class="col-lg-12">
<h1 class="page-sub-header">Latest activity</h1>
</div>
Expand Down
17 changes: 16 additions & 1 deletion website/templates/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
text-decoration: none;
margin-left: 10px;
}
.silver {
background-color: lightblue;
color: #333;
}
.gold {
background-color: #D4AF37;
color: #333;
}
.bronze {
background-color: #C9AE5D;
color: #333;
}

{% endblock %}

{% block content %}
Expand All @@ -33,9 +46,11 @@ <h1 class="page-header">Global Leaderboard</h1>
{% endif %}
<a href="/profile/{{leader.username}}">{{leader.username}}</a>
<span class="pull-right badge">{{leader.total_score}} Points</span>
<span ><kbd class="{{ leader.userprofile.get_title_display }}" >{{ leader.userprofile.get_title_display }}</kbd></span>
</div>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% endblock %}

30 changes: 30 additions & 0 deletions website/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
.list-group .label-default {
margin-top:3px;
}
.block-icon {
font-size: 90px;
line-height: 70px;
margin-top: -40px;
}
.silver {
background-color: lightblue;
color: #333;
}
.gold {
background-color: #D4AF37;
color: #333;
}
.bronze {
background-color: #C9AE5D;
color: #333;
}

{% endblock %}

{% block content %}
Expand All @@ -25,11 +43,23 @@ <h1 class="page-header text-capitalize">{{ user.username }}</h1>
<div class="col-md-3">
{% if user.userprofile.avatar %}
<img src="{{ user.userprofile.avatar }}" class="img-responsive img-thumbnail">

{% else %}
<img src="{% gravatar_url user.email 200 %}" class="img-responsive img-thumbnail">
{% endif %}
<h4> <kbd class="{{ user.userprofile.get_title_display }}" >{{ user.userprofile.get_title_display }}</kbd> Total bugs:<strong>{{ activities | length }} </strong> </h4>
<div class="block-icon">

<kbd class="fa fa-exclamation-triangle" style="font-size:20px;color:#ff4444;">{{ bug_type_1 | length }}</kbd>
<kbd class="fa fa-trophy" style="font-size:20px;color:#FF8800;">{{ bug_type_2 | length }}</kbd>
<kbd class="fa fa-flash" style="font-size:20px;color:#00C851;">{{ bug_type_3 | length }}</kbd>
<kbd class="fa fa-lock" style="font-size:20px;color:#0099CC;">{{ bug_type_4 | length}}</kbd>
<kbd class="fa fa-eraser" style="font-size:20px;color:white;">{{ bug_type_5 | length}}</kbd>
<kbd class="fa fa-code" style="font-size:20px;color:#ef6c00;">{{ bug_type_6 | length}}</kbd>
</div>
</div>
<div class="col-md-3">

{% if request.user == user %}
<form method="post" action="." enctype="multipart/form-data">
{% csrf_token %}
Expand Down
17 changes: 16 additions & 1 deletion website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.contrib.auth.models import User
from actstream import registry
from django.http import JsonResponse
from website.models import Issue, Points, Hunt, Domain, InviteFriend
from website.models import Issue, Points, Hunt, Domain, InviteFriend, UserProfile
from django.core.files import File
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import Sum, Count
Expand Down Expand Up @@ -188,6 +188,19 @@ def form_valid(self, form):
obj.screenshot.save(self.request.POST.get('screenshot-hash') +'.png', django_file, save=True)
obj.user_agent = self.request.META.get('HTTP_USER_AGENT')
obj.save()

total_issues = Issue.objects.filter(user=self.request.user).count()
user_prof = UserProfile.objects.get(user=self.request.user)
if total_issues <=10:
user_prof.title = 1
elif total_issues <=50:
user_prof.title = 2
elif total_issues <= 200:
user_prof.title = 3
else:
user_prof.title = 4

user_prof.save()

if domain.github and os.environ.get("GITHUB_PASSWORD"):
from giturlparse import parse
Expand Down Expand Up @@ -288,6 +301,8 @@ def get_context_data(self, **kwargs):
context['websites'] = Domain.objects.filter(issue__user=self.object).annotate(total=Count('issue')).order_by('-total')
context['activities'] = user_stream(self.object, with_user_activity=True)
context['profile_form'] = UserProfileForm()
for i in range(1,7):
context['bug_type_'+str(i)] = Issue.objects.filter(user=self.object,label=str(i))
return context

@method_decorator(login_required)
Expand Down