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)
|
2015-05-15 08:36:17 -05:00
|
|
|
chain = u" ".join(markovlib.generate_line(context))
|
2014-04-05 14:26:06 -05:00
|
|
|
end_t = time.time()
|
|
|
|
|
2015-05-15 08:30:58 -05:00
|
|
|
return render(request, 'context.html', {'chain': chain,
|
|
|
|
'context': context,
|
|
|
|
'elapsed': end_t - start_t})
|