31 lines
763 B
Python
31 lines
763 B
Python
"""Manipulate Markov data via the Django site."""
|
|
|
|
import logging
|
|
import time
|
|
|
|
from django.http import HttpResponse
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
|
import markov.lib as markovlib
|
|
from markov.models import MarkovContext
|
|
|
|
|
|
log = logging.getLogger('markov.views')
|
|
|
|
|
|
def index(request):
|
|
"""Display nothing, for the moment."""
|
|
|
|
return HttpResponse()
|
|
|
|
|
|
def context_index(request, context_id):
|
|
"""Display the context index for the given context."""
|
|
|
|
start_t = time.time()
|
|
context = get_object_or_404(MarkovContext, pk=context_id)
|
|
chain = " ".join(markovlib.generate_line(context))
|
|
end_t = time.time()
|
|
|
|
return render(request, 'markov/context.html', {'chain': chain, 'context': context, 'elapsed': end_t - start_t})
|