# Path: puput/models.py
# class BlogPage(BlogRoutes, Page, Blog):
#     extra = BlogManager()
# 
#     content_panels = Page.content_panels + getattr(Blog, 'content_panels', [])
#     settings_panels = Page.settings_panels + getattr(Blog, 'settings_panels', [])
# 
#     subpage_types = ['puput.EntryPage']
# 
#     def get_entries(self):
#         return EntryPage.objects.descendant_of(self).live().order_by('-date').select_related('owner')
# 
#     def get_context(self, request, *args, **kwargs):
#         context = super(BlogPage, self).get_context(request, *args, **kwargs)
#         context['entries'] = self.entries
#         context['blog_page'] = self
#         context['search_type'] = getattr(self, 'search_type', "")
#         context['search_term'] = getattr(self, 'search_term', "")
#         return context
# 
#     @property
#     def last_url_part(self):
#         """
#         Get the BlogPage url without the domain
#         """
#         return self.get_url_parts()[-1]
# 
#     class Meta:
#         verbose_name = _('Blog')


from mimetypes import guess_type
from urllib.parse import urljoin
from django import http
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from django.template.defaultfilters import truncatewords_html
from wagtail.core.models import Site
from .models import BlogPage
        from .urls import get_entry_url




class BlogPageFeedGenerator(Rss201rev2Feed):
    def add_root_elements(self, handler):
        super(BlogPageFeedGenerator, self).add_root_elements(handler)
        if self.feed['image_link']:
            handler.addQuickElement(
                'image',
                '',
                {
                    'url': self.feed['image_link'],
                    'title': self.feed['title'],
                    'link': self.feed['link'],
                }
            )


class BlogPageFeed(Feed):
    feed_type = BlogPageFeedGenerator

    def __call__(self, request, *args, **kwargs):
        if request.resolver_match.url_name == 'blog_page_feed_slug':
            self.blog_page = BlogPage.extra.get_by_path(kwargs['blog_path'])
            if not self.blog_page:
                raise http.Http404
        else:

# Path: puput/models.py
# class BlogPage(BlogRoutes, Page, Blog):
#     extra = BlogManager()
# 
#     content_panels = Page.content_panels + getattr(Blog, 'content_panels', [])
#     settings_panels = Page.settings_panels + getattr(Blog, 'settings_panels', [])
# 
#     subpage_types = ['puput.EntryPage']
# 
#     def get_entries(self):
#         return EntryPage.objects.descendant_of(self).live().order_by('-date').select_related('owner')
# 
#     def get_context(self, request, *args, **kwargs):
#         context = super(BlogPage, self).get_context(request, *args, **kwargs)
#         context['entries'] = self.entries
#         context['blog_page'] = self
#         context['search_type'] = getattr(self, 'search_type', "")
#         context['search_term'] = getattr(self, 'search_term', "")
#         return context
# 
#     @property
#     def last_url_part(self):
#         """
#         Get the BlogPage url without the domain
#         """
#         return self.get_url_parts()[-1]
# 
#     class Meta:
#         verbose_name = _('Blog')


# Path: puput/feeds.py
from mimetypes import guess_type
from urllib.parse import urljoin
from django import http
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from django.template.defaultfilters import truncatewords_html
from wagtail.core.models import Site
from .models import BlogPage
        from .urls import get_entry_url





class BlogPageFeedGenerator(Rss201rev2Feed):
    def add_root_elements(self, handler):
        super(BlogPageFeedGenerator, self).add_root_elements(handler)
        if self.feed['image_link']:
            handler.addQuickElement(
                'image',
                '',
                {
                    'url': self.feed['image_link'],
                    'title': self.feed['title'],
                    'link': self.feed['link'],
                }
            )


class BlogPageFeed(Feed):
    feed_type = BlogPageFeedGenerator

    def __call__(self, request, *args, **kwargs):
        if request.resolver_match.url_name == 'blog_page_feed_slug':
            self.blog_page = BlogPage.extra.get_by_path(kwargs['blog_path'])
            if not self.blog_page:
                raise http.Http404
        else:

            self.blog_page = BlogPage.objects.first()