2015-05-15 08:30:58 -05:00
|
|
|
"""Manipulate Markov data via the Django site."""
|
2014-04-05 10:52:29 -05:00
|
|
|
|
|
|
|
import logging
|
2014-04-05 14:26:06 -05:00
|
|
|
import time
|
2014-04-05 10:52:29 -05:00
|
|
|
|
|
|
|
from django.http import HttpResponse
|
2014-04-05 14:26:06 -05:00
|
|
|
from django.shortcuts import get_object_or_404, render
|
2014-04-05 10:52:29 -05:00
|
|
|
|
2015-05-15 08:36:17 -05:00
|
|
|
import markov.lib as markovlib
|
|
|
|
from markov.models import MarkovContext
|
2014-04-05 10:52:29 -05:00
|
|
|
|
|
|
|
|
2015-05-15 08:30:58 -05:00
|
|
|
log = logging.getLogger('markov.views')
|
2014-04-05 10:52:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
"""Display nothing, for the moment."""
|
|
|
|
|
|
|
|
return HttpResponse()
|
|
|
|
|
|
|
|
|
2014-04-05 14:26:06 -05:00
|
|
|
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)
|
2016-01-16 17:58:11 -06:00
|
|
|
chain = " ".join(markovlib.generate_line(context))
|
2014-04-05 14:26:06 -05:00
|
|
|
end_t = time.time()
|
|
|
|
|
2016-03-30 16:00:49 -05:00
|
|
|
return render(request, 'markov/context.html', {'chain': chain, 'context': context, 'elapsed': end_t - start_t})
|