# Create your views here.
from conteudo.models import Academico, Profissional, Complementar, Competencia, Informacao,\
    Timeline
from django.http import Http404
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.views.generic.list import ListView
from layout.models import Tema
from datetime import datetime


def academico(request):
    try:
        atuacoes = Academico.objects.all()
    except Academico.DoesNotExist:
        raise Http404
    return render_to_response('conteudo/academico_archive.html', {'atuacoes': atuacoes}, context_instance=RequestContext(request))

    
class academicoView(ListView):
    context_object_name = 'atuacoes'
    queryset = Academico.objects.all()
    template_name = "conteudo/academico_archive.html"
    
    def __init__(self, **kwargs):
        ListView.__init__(self, **kwargs)
        tema = Tema.objects.all()[0]
        tema.set_main_color(tema.cor_academico)


class profissionalView(ListView):
    context_object_name = 'atuacoes'
    queryset = Profissional.objects.all()
    template_name = "conteudo/profissional_archive.html"
    
    def __init__(self, **kwargs):
        ListView.__init__(self, **kwargs)
        tema = Tema.objects.all()[0]
        tema.set_main_color(tema.cor_profissional)


class complementarView(ListView):
    context_object_name = 'formacoes'
    queryset = Complementar.objects.all()
    template_name = "conteudo/complementar_archive.html"
    
    def __init__(self, **kwargs):
        ListView.__init__(self, **kwargs)
        tema = Tema.objects.all()[0]
        tema.set_main_color(tema.cor_complementar)
    

class competenciasView(ListView):
    context_object_name = 'competencias'
    queryset = Competencia.objects.all()
    template_name = "conteudo/competencias_archive.html"
    
    def __init__(self, **kwargs):
        ListView.__init__(self, **kwargs)
        tema = Tema.objects.all()[0]
        tema.set_main_color(tema.cor_competencias)
    

class informacoesView(ListView):
    context_object_name = 'informacoes'
    queryset = Informacao.objects.all()
    template_name = "conteudo/informacoes_archive.html"
    
    def __init__(self, **kwargs):
        ListView.__init__(self, **kwargs)
        tema = Tema.objects.all()[0]
        tema.set_main_color(tema.cor_informacoes)
    
class timelineView(ListView):
    context_object_name = 'timeline'
    queryset = Timeline.objects.filter(date__range=["1987-10-22", datetime.now()])
    template_name = "conteudo/timeline_archive.html"
    
    def __init__(self, **kwargs):
        ListView.__init__(self, **kwargs)
        if Tema.objects.all():
            tema = Tema.objects.all()[0]
            tema.set_main_color(tema.cor_home)
        else:
            tema = Tema(cor_principal='#0088cc',\
                    cor_home='#0088cc',\
                    cor_academico='#0088cc',\
                    cor_profissional='#0088cc',\
                    cor_complementar='#0088cc',\
                    cor_competencias='#0088cc',\
                    cor_informacoes='#0088cc',\
                    cor_fonte_padrao='#30353A',\
                    fonte_padrao='"Helvetica Neue", sans-serif',\
                    sideleft_width='250')
            tema.save()
            tema = Tema.objects.all()[0]
            tema.set_main_color(tema.cor_home)
