karma: display all karma keys in index page

this kind of sucks from a performance standpoint, i'd like to make it
better
This commit is contained in:
Brian S. Stephan 2016-05-13 21:55:54 -05:00
parent b82e5309e1
commit 4809247632
3 changed files with 57 additions and 3 deletions

View File

@ -0,0 +1,47 @@
{% extends 'base.html' %}
{% load static %}
{% block extra_media %}
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/jqc-1.12.0,dt-1.10.11/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/t/bs/jqc-1.12.0,dt-1.10.11/datatables.min.js"></script>
{% endblock %}
{% block title %}karma{% endblock %}
{% block content %}
<div style="width: 75%; margin-left: auto; margin-right: auto;">
<table id="karma" class="display table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Key</th>
<th>Score</th>
<th>Rank</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Key</th>
<th>Score</th>
<th>Rank</th>
</tr>
</tfoot>
<tbody>
{% for entry in entries %}
<tr>
<td><a href="{% url 'karma_key_detail' entry.key %}">{{ entry.key }}</a></td>
<td>{{ entry.score }}</td>
<td>{{ entry.rank }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#karma').DataTable( {
"order": [[ 2, "asc" ]],
"lengthMenu": [[50, 100, -1], [50, 100, "All"]]
} );
} );
</script>
{% endblock %}

View File

@ -1,11 +1,10 @@
"""URL patterns for the karma views."""
from django.conf.urls import patterns, url
from django.views.generic import TemplateView
from karma.views import key_detail
from karma.views import key_detail, index
urlpatterns = patterns('races.views',
url(r'^$', TemplateView.as_view(template_name='index.html'), name='karma_index'),
url(r'^$', index, name='karma_index'),
url(r'^key/(?P<karma_key>.+)/', key_detail, name='karma_key_detail'),
)

View File

@ -9,6 +9,14 @@ from karma.models import KarmaKey
log = logging.getLogger('karma.views')
def index(request):
"""Display all karma keys."""
entries = KarmaKey.objects.all().order_by('key')
return render(request, 'karma/index.html', {'entries': entries})
def key_detail(request, karma_key):
"""Display the requested karma key."""