from django.shortcuts import render
from django.urls import path


# Create your views here.

def template(filename, ec={}):
    def closure(request):
        return render(request, filename+'.html', ec)

    return closure


def reverse_template(filename, model, ec={}):
    def closure(request, id):
        return render(request, filename+'-reverse.html', {**ec, 'focus': model.objects.get(id=id)})

    return closure


def tpath(p: str, filename: str, ec={}):
    return path(p, template(filename, ec), name=filename.replace('/', '_'))


def rtpath(p: str, filename: str, model, ec={}):
    return path(p, reverse_template(filename, model, ec), name=filename.replace('/', '_')+'-reverse')
