from django.views.generic import ListView,DetailView
from at_django_boilerplate.backend_admin.models import SEOConfiguration
# Create your views here.

from at_django_boilerplate.blogs.models import Blog
class BlogsListView(ListView):
    model = Blog
    template_name = 'blogs_list.html'
    context_object_name = 'blogs'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        seo = SEOConfiguration.objects.first()
        context["meta_title"] = seo.blog_meta_title if seo else "Blog - RegisterYourStartup"
        context["meta_description"] = seo.blog_meta_description if seo else "Read articles and updates from Zestato."
        return context


class BlogDetailView(DetailView):
    model = Blog
    template_name = 'blog_detail.html'
    context_object_name = 'blog'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        blog = self.get_object()
        context["meta_title"] = blog.title
        context["meta_description"] = blog.meta_description if hasattr(blog, 'meta_description') else blog.short_description[:160]
        return context