from django.shortcuts import render
from django.http import HttpResponse
from apps.inverted import main, main2

# Create your views here.
# def index(request):
#     return HttpResponse("Hello, world. You're at the polls index.")

def home(request):
    return render(request, 'apps/home.html')

def index(request):
    return render(request, 'apps/index.html')
def index2(request):
    return render(request, 'apps/index2.html')

def detail(request,id):

    text, judul, cast, year = main.detail(id)
    content={
        'no': id,
        'judul':judul,
        'text':text,
        'cast':cast,
        'year':year
    }
    return render(request, 'apps/detail.html', content)

def detail2(request, id):

    text,judul,cast,year = main2.detail(id)
    content={
        'no': id,
        'judul':judul,
        'text':text,
        'cast':cast,
        'year':year
    }
    return render(request, 'apps/detail2.html', content)



def result2(request):
    #%%
    # proximity_index = collections.OrderedDict(sorted(proximity_index.items()))
    # for key, value in proximity_index.items():
    #     # print (key, value)
    if request.method == 'POST':
        query = request.POST['querysearch']
        hasil = main2.main(query)

        content={
            'hasil':hasil,
            'query':query
        }
        return render(request, 'apps/result2.html',content)


def result(request):
    #%%
    # proximity_index = collections.OrderedDict(sorted(proximity_index.items()))
    # for key, value in proximity_index.items():
    #     # print (key, value)
    if request.method == 'POST':
        query = request.POST['querysearch']
        hasil= main.main(query)

        content={
            'hasil':hasil,
            'query':query
        }
        return render(request, 'apps/result.html',content)
