2016-03-30 17:08:01 -05:00
|
|
|
"""Present karma data."""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from django.shortcuts import get_object_or_404, render
|
2016-05-13 22:19:38 -05:00
|
|
|
from rest_framework import viewsets
|
2016-03-30 17:08:01 -05:00
|
|
|
|
|
|
|
from karma.models import KarmaKey
|
2016-05-13 22:19:38 -05:00
|
|
|
from karma.serializers import KarmaKeySerializer
|
2016-03-30 17:08:01 -05:00
|
|
|
|
|
|
|
log = logging.getLogger('karma.views')
|
|
|
|
|
|
|
|
|
2016-05-13 21:55:54 -05:00
|
|
|
def index(request):
|
|
|
|
"""Display all karma keys."""
|
|
|
|
|
|
|
|
entries = KarmaKey.objects.all().order_by('key')
|
|
|
|
|
|
|
|
return render(request, 'karma/index.html', {'entries': entries})
|
|
|
|
|
|
|
|
|
2016-03-30 17:08:01 -05:00
|
|
|
def key_detail(request, karma_key):
|
|
|
|
"""Display the requested karma key."""
|
|
|
|
|
2016-03-31 16:47:17 -05:00
|
|
|
entry = get_object_or_404(KarmaKey, key=karma_key.lower())
|
2016-03-30 17:08:01 -05:00
|
|
|
|
2016-03-31 16:36:10 -05:00
|
|
|
return render(request, 'karma/karma_key.html', {'entry': entry, 'entry_history': entry.history(mode='date')})
|
2016-05-13 22:19:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
class KarmaKeyViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
|
|
|
|
"""Provide list and detail actions for karma keys."""
|
|
|
|
|
|
|
|
queryset = KarmaKey.objects.all()
|
|
|
|
serializer_class = KarmaKeySerializer
|