# -*- coding: utf-8 -*-

from django.views.generic.list import ListView
from django.views.generic import TemplateView

from posts.models import Post, PostTag
from posts.views import PostListView


# Home page
class IndexView(PostListView):
    template_name = "website/index.html"


# FAQ
class FAQView(TemplateView):
    template_name = "website/faq.html"


# For XML serving
class XmlView(ListView):
    queryset = Post.objects.all()

    def get_context_data(self, *args, **kwargs):
        request = self.request

        protocol = "https://" if request.is_secure() else "http://"

        context = super(ListView, self).get_context_data(*args, **kwargs)
        context['posts'] = Post.objects.order_by('-create_date')

        return context


# Sitemap (xml)
class SiteMapXML(XmlView):
    template_name = "sitemap.xml"
    content_type = "application/xml"

    def get_context_data(self, *args, **kwargs):
        context = super(SiteMapXML, self).get_context_data(*args, **kwargs)
        context['tags'] = PostTag.objects.all()

        return context


# Atom Feed (xml)
class AtomFeedXML(XmlView):
    template_name = "atom.xml"
    content_type = "application/atom+xml"


# RSS Feed (xml)
class RssFeedXML(XmlView):
    template_name = "rss.xml"
    content_type = "application/rss+xml"
