Skip to content

Commit

Permalink
add last updated at for leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
dojutsu-user committed Nov 9, 2019
1 parent ee7001d commit 9833238
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 5 deletions.
1 change: 0 additions & 1 deletion leaderboard/leaderboard/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from celery.schedules import crontab

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down
6 changes: 5 additions & 1 deletion leaderboard/submission/management/commands/sync_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def get_all_merged_prs(self, repo):
page_no=page_no+1,
)

log.info('Getting data for %s', link)

response = requests.get(link)
if response.status_code == 200:
data = response.json()
Expand All @@ -81,8 +83,10 @@ def get_all_merged_prs(self, repo):
break

for pr in data:
if pr['merged_at'] != 'null':
if pr['merged_at'] != None:
final_data.append(pr)
else:
log.info('%s response for %s:' % (response.status_code, link))

except Exception:
log.exception('Error while getting all merged PRs for repo %s', repo)
Expand Down
21 changes: 21 additions & 0 deletions leaderboard/submission/migrations/0007_submission_created_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.2.6 on 2019-11-08 16:16

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('submission', '0006_auto_20191103_0148'),
]

operations = [
migrations.AddField(
model_name='submission',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2019, 11, 8, 16, 16, 12, 887676, tzinfo=utc)),
preserve_default=False,
),
]
1 change: 1 addition & 0 deletions leaderboard/submission/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Submission(models.Model):
(50, 50),
))
link = models.URLField('GitHub link')
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f'Submission by {self.user}'
8 changes: 8 additions & 0 deletions leaderboard/submission/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ def get_queryset(self):
data = sorted(data, key=operator.itemgetter('total_points'), reverse=True)

return data

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
obj = Submission.objects.all().order_by('-created_at').first()
if obj:
context['last_updated']: last_updated.created_at

return context
3 changes: 2 additions & 1 deletion leaderboard/templates/submission/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load static %}

{% block content %}

<div class="jumbotron jumbotron-fluid is-center bg-whitesmoke text-center">
<div class="container">
<h2 class="home-heading">Get Set FOSS - Leaderboard</h2>
Expand All @@ -16,6 +16,7 @@ <h2 class="home-heading">Get Set FOSS - Leaderboard</h2>
<a href="{% provider_login_url 'github' %}" class="btn-lg btn-dark github-btn">
<i class="fab fa-github"></i> Login with GitHub
</a>
<p class="my-3"><a href="{% url 'leaderboard' %}" target="_blank">View Leaderboard</a></p>
{% else %}
<h3>Hello <strong>{{ request.user }}</strong></h3>
{% endif %}
Expand Down
5 changes: 4 additions & 1 deletion leaderboard/templates/submission/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ <h1>Get Set FOSS 2019<br/>Leaderboard</h1>
</div>

<div class="container">
<table class="table table-striped">
{% if last_updated %}
<span class="badge badge-info">Last Updated At: {{ last_updated }}</span>
{% endif %}
<table class="table table-striped my-3">
<thead>
<tr>
<th scope="col">#</th>
Expand Down
3 changes: 3 additions & 0 deletions leaderboard/templates/submission/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'dashboard' %}">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'leaderboard' %}" target="_blank">Leaderboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'account_logout' %}">Logout</a>
Expand Down
5 changes: 4 additions & 1 deletion static_dir/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

.main-page-logo {
width:70%;
width: 50%;
}

.github-btn:hover {
Expand All @@ -37,6 +37,9 @@
.jumbotron.jumbotron-fluid {
width: 100%;
}
.main-page-logo {
width: 70%;
}
}

.mx-r-3 {
Expand Down

0 comments on commit 9833238

Please sign in to comment.