36 lines
894 B
Python
36 lines
894 B
Python
"""Present karma data."""
|
|
|
|
import logging
|
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
from rest_framework import viewsets
|
|
|
|
from karma.models import KarmaKey
|
|
from karma.serializers import KarmaKeySerializer
|
|
|
|
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."""
|
|
|
|
entry = get_object_or_404(KarmaKey, key=karma_key.lower())
|
|
|
|
return render(request, 'karma/karma_key.html', {'entry': entry, 'entry_history': entry.history(mode='date')})
|
|
|
|
|
|
class KarmaKeyViewSet(viewsets.ReadOnlyModelViewSet):
|
|
|
|
"""Provide list and detail actions for karma keys."""
|
|
|
|
queryset = KarmaKey.objects.all()
|
|
serializer_class = KarmaKeySerializer
|