from django.contrib.auth.decorators import login_required
from django.http.response import Http404
from django.shortcuts import render, get_object_or_404, redirect
from django.template import loader
from django.http import HttpResponse
from django import template
from .models import *

#@login_required(login_url="/login/")

def index(request):  
    context = {}
    context['segment'] = 'index'
    context['judul'] = 'Banner'
    context['kata'] = 'INI ARTIKELnya'

    html_template = loader.get_template( 'navigator/ekosistem/index.html' )
    return HttpResponse(html_template.render(context, request))

def link_detail(request, slug=None):
    context = {}
    context['segment'] = 'index'
    context['judul'] = 'Ekosistem'
    context['links'] = Link.objects.all()

    link_obj = None
    if slug is not None:
        try:
            link_obj = Link.objects.get(slug=slug)
        except Link.DoesNotExist:
            raise Http404
        except Link.MultipleObjectsReturned:
            article_obj = Link.objects.filter(slug=slug).first()
        except:
            raise Http404
    context = {
        "object": link_obj,
    }
    #return render(request, "artikel/detail.html", context=context)
    
    html_template = loader.get_template( 'navigator/ekosistem/detail.html' )
    return HttpResponse(html_template.render(context, request))