Initial commit of server-side datatables. Filtering needs more work.
This commit is contained in:
parent
690e0235d2
commit
66268dc733
|
@ -2,8 +2,8 @@
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
{% block extra_media %}
|
{% 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"/>
|
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs-3.3.7/jq-2.2.4/dt-1.10.15/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>
|
<script type="text/javascript" src="https://cdn.datatables.net/v/bs-3.3.7/jq-2.2.4/dt-1.10.15/datatables.min.js"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block title %}karma{% endblock %}
|
{% block title %}karma{% endblock %}
|
||||||
|
@ -23,19 +23,14 @@
|
||||||
<th>Score</th>
|
<th>Score</th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
<tbody>
|
|
||||||
{% for entry in entries %}
|
|
||||||
<tr>
|
|
||||||
<td><a href="{% url 'karma_key_detail' entry.key %}">{{ entry.key }}</a></td>
|
|
||||||
<td>{{ entry.score }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#karma').DataTable( {
|
$('#karma').DataTable( {
|
||||||
|
"processing": true,
|
||||||
|
"serverSide": true,
|
||||||
|
"ajax": "{% url 'karma_key_data_tables' %}",
|
||||||
"order": [[ 1, "desc" ]],
|
"order": [[ 1, "desc" ]],
|
||||||
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
|
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -3,14 +3,17 @@
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from karma.views import key_detail, index, KarmaKeyViewSet
|
from karma.views import key_detail, IndexView, KarmaKeyViewSet, KarmaKeyListJson
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register(r'keys', KarmaKeyViewSet)
|
router.register(r'keys', KarmaKeyViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', index, name='karma_index'),
|
url(r'^$', IndexView.as_view(), name='karma_index'),
|
||||||
url(r'^key/(?P<karma_key>.+)/', key_detail, name='karma_key_detail'),
|
url(r'^key/(?P<karma_key>.+)/', key_detail, name='karma_key_detail'),
|
||||||
|
|
||||||
url(r'^api/', include(router.urls)),
|
url(r'^api/', include(router.urls)),
|
||||||
|
|
||||||
|
# json pages for DataTables
|
||||||
|
url(r'^datatables/key/$', KarmaKeyListJson.as_view(), name='karma_key_data_tables'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render, reverse
|
||||||
|
from django.views.generic import TemplateView
|
||||||
|
from django_datatables_view.base_datatable_view import BaseDatatableView
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
from karma.models import KarmaKey
|
from karma.models import KarmaKey
|
||||||
|
@ -11,11 +13,9 @@ from karma.serializers import KarmaKeySerializer
|
||||||
log = logging.getLogger('karma.views')
|
log = logging.getLogger('karma.views')
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class IndexView(TemplateView):
|
||||||
"""Display all karma keys."""
|
""" Routes to the index template using the generic view """
|
||||||
entries = KarmaKey.objects.all().order_by('key')
|
template_name = 'karma/index.html'
|
||||||
|
|
||||||
return render(request, 'karma/index.html', {'entries': entries})
|
|
||||||
|
|
||||||
|
|
||||||
def key_detail(request, karma_key):
|
def key_detail(request, karma_key):
|
||||||
|
@ -30,3 +30,32 @@ class KarmaKeyViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
|
||||||
queryset = KarmaKey.objects.all()
|
queryset = KarmaKey.objects.all()
|
||||||
serializer_class = KarmaKeySerializer
|
serializer_class = KarmaKeySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class KarmaKeyListJson(BaseDatatableView):
|
||||||
|
""" Provide list of KarmaKeys in snazzy JSON format that DataTables enjoys """
|
||||||
|
|
||||||
|
model = KarmaKey
|
||||||
|
max_display_length = 500
|
||||||
|
columns = ['key', 'current_score']
|
||||||
|
|
||||||
|
# maintain order from columns
|
||||||
|
order_columns = ['key', 'current_score']
|
||||||
|
|
||||||
|
def get_initial_queryset(self):
|
||||||
|
""" Add another column that operates like score() """
|
||||||
|
return KarmaKey.objects.extra(select={
|
||||||
|
'current_score':
|
||||||
|
'SELECT SUM(kle.delta) FROM karma_karmalogentry kle WHERE kle.key_id = karma_karmakey.id'
|
||||||
|
})
|
||||||
|
|
||||||
|
def prepare_results(self, qs):
|
||||||
|
# prepare list with output column data
|
||||||
|
# queryset is already paginated here
|
||||||
|
json_data = []
|
||||||
|
for kk in qs:
|
||||||
|
json_data.append([
|
||||||
|
'<a href="{}">{}</a>'.format(reverse('karma_key_detail', args=[kk.key]), kk.key),
|
||||||
|
kk.current_score,
|
||||||
|
])
|
||||||
|
return json_data
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
#
|
#
|
||||||
# pip-compile --output-file requirements-dev.txt requirements-dev.in
|
# pip-compile --output-file requirements-dev.txt requirements-dev.in
|
||||||
#
|
#
|
||||||
appdirs==1.4.0 # via setuptools
|
|
||||||
astroid==1.4.9 # via pylint, pylint-celery, pylint-flask, pylint-plugin-utils, requirements-detector
|
astroid==1.4.9 # via pylint, pylint-celery, pylint-flask, pylint-plugin-utils, requirements-detector
|
||||||
|
backports.functools-lru-cache==1.4 # via jaraco.functools, pylint
|
||||||
click==6.7 # via pip-tools
|
click==6.7 # via pip-tools
|
||||||
|
configparser==3.5.0 # via pylint
|
||||||
django-adminplus==0.5
|
django-adminplus==0.5
|
||||||
django-bootstrap3==8.1.0
|
django-bootstrap3==8.1.0
|
||||||
|
django-datatables-view==1.14.0
|
||||||
django-extensions==1.7.6
|
django-extensions==1.7.6
|
||||||
django-registration-redux==1.4
|
django-registration-redux==1.4
|
||||||
django==1.10.5
|
django==1.10.5
|
||||||
|
@ -31,7 +33,6 @@ logilab-common==1.3.0
|
||||||
mccabe==0.6.1 # via prospector, pylint
|
mccabe==0.6.1 # via prospector, pylint
|
||||||
more-itertools==2.5.0 # via irc, jaraco.functools, jaraco.itertools
|
more-itertools==2.5.0 # via irc, jaraco.functools, jaraco.itertools
|
||||||
oauthlib==2.0.1 # via requests-oauthlib
|
oauthlib==2.0.1 # via requests-oauthlib
|
||||||
packaging==16.8 # via setuptools
|
|
||||||
parsedatetime==2.2
|
parsedatetime==2.2
|
||||||
pep8-naming==0.4.1 # via prospector
|
pep8-naming==0.4.1 # via prospector
|
||||||
pip-tools==1.8.0
|
pip-tools==1.8.0
|
||||||
|
@ -46,7 +47,6 @@ pylint-django==0.7.2 # via prospector
|
||||||
pylint-flask==0.5 # via prospector
|
pylint-flask==0.5 # via prospector
|
||||||
pylint-plugin-utils==0.2.4 # via prospector, pylint-celery, pylint-django, pylint-flask
|
pylint-plugin-utils==0.2.4 # via prospector, pylint-celery, pylint-django, pylint-flask
|
||||||
pylint==1.6.5 # via prospector, pylint-celery, pylint-common, pylint-django, pylint-flask, pylint-plugin-utils
|
pylint==1.6.5 # via prospector, pylint-celery, pylint-common, pylint-django, pylint-flask, pylint-plugin-utils
|
||||||
pyparsing==2.1.10 # via packaging
|
|
||||||
python-dateutil==2.6.0
|
python-dateutil==2.6.0
|
||||||
python-gitlab==0.18
|
python-gitlab==0.18
|
||||||
python-mpd2==0.5.5
|
python-mpd2==0.5.5
|
||||||
|
@ -56,10 +56,10 @@ requests-oauthlib==0.7.0 # via twython
|
||||||
requests==2.13.0 # via python-gitlab, requests-oauthlib, twython
|
requests==2.13.0 # via python-gitlab, requests-oauthlib, twython
|
||||||
requirements-detector==0.5.2 # via prospector
|
requirements-detector==0.5.2 # via prospector
|
||||||
setoptconf==0.2.0 # via prospector
|
setoptconf==0.2.0 # via prospector
|
||||||
six==1.10.0 # via astroid, django-extensions, irc, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, logilab-common, more-itertools, packaging, pip-tools, pylint, python-dateutil, python-gitlab, setuptools, tempora
|
six==1.10.0 # via astroid, django-extensions, irc, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, logilab-common, more-itertools, pip-tools, pylint, python-dateutil, python-gitlab, tempora
|
||||||
tempora==1.6.1 # via irc, jaraco.logging
|
tempora==1.6.1 # via irc, jaraco.logging
|
||||||
twython==3.4.0
|
twython==3.4.0
|
||||||
wrapt==1.10.8 # via astroid
|
wrapt==1.10.8 # via astroid
|
||||||
|
|
||||||
# The following packages are considered to be unsafe in a requirements file:
|
# The following packages are considered to be unsafe in a requirements file:
|
||||||
# setuptools # via logilab-common
|
# setuptools # via django-datatables-view, logilab-common
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
Django # core
|
Django # core
|
||||||
django-adminplus # admin.site.register_view
|
django-adminplus # admin.site.register_view
|
||||||
django-bootstrap3 # bootstrap layout
|
django-bootstrap3 # bootstrap layout
|
||||||
|
django-datatables-view # easy server-side datatables
|
||||||
django-extensions # more commands
|
django-extensions # more commands
|
||||||
django-registration-redux # registration views/forms
|
django-registration-redux # registration views/forms
|
||||||
djangorestframework # dispatch WS API
|
djangorestframework # dispatch WS API
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
#
|
#
|
||||||
# pip-compile --output-file requirements.txt requirements.in
|
# pip-compile --output-file requirements.txt requirements.in
|
||||||
#
|
#
|
||||||
|
backports.functools-lru-cache==1.4 # via jaraco.functools
|
||||||
django-adminplus==0.5
|
django-adminplus==0.5
|
||||||
django-bootstrap3==8.1.0
|
django-bootstrap3==8.1.0
|
||||||
|
django-datatables-view==1.14.0
|
||||||
django-extensions==1.7.6
|
django-extensions==1.7.6
|
||||||
django-registration-redux==1.4
|
django-registration-redux==1.4
|
||||||
django==1.10.5
|
django==1.10.5
|
||||||
|
@ -33,3 +35,6 @@ requests==2.13.0 # via python-gitlab, requests-oauthlib, twython
|
||||||
six==1.10.0 # via django-extensions, irc, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, more-itertools, python-dateutil, python-gitlab, tempora
|
six==1.10.0 # via django-extensions, irc, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, more-itertools, python-dateutil, python-gitlab, tempora
|
||||||
tempora==1.6.1 # via irc, jaraco.logging
|
tempora==1.6.1 # via irc, jaraco.logging
|
||||||
twython==3.4.0
|
twython==3.4.0
|
||||||
|
|
||||||
|
# The following packages are considered to be unsafe in a requirements file:
|
||||||
|
# setuptools # via django-datatables-view
|
||||||
|
|
Loading…
Reference in New Issue