from pageapp.models import page
from django.shortcuts import render, get_object_or_404
from polysite.globals import CustomRenderer
import mistune


def getpage(request, page_id):
    pagedetail = get_object_or_404(page, pk=page_id)
    renderer = CustomRenderer()
    md = mistune.Markdown(renderer=renderer, hard_wrap=True)
    pagedetail.body = md(pagedetail.body)
    return render(request, 'pageapp/page.html', {'page': pagedetail})


def aboutpage(request):
    # about = get_object_or_404(page, pk=1)
    # return render(request, 'pageapp/page.html', {'page': about})
    return getpage(request, 1)


def contactpage(request):
    # contact = get_object_or_404(page, pk=2)
    # return render(request, 'pageapp/page.html', {'page': contact})
    return getpage(request, 2)
