# Path: website/jdpages/models.py
# class HomePage(Page, RichText):
#     """
#     Page model for the site homepage.
#     Only works properly when url points to the homepage '/' as url.
#     """
#     header_title = models.CharField(max_length=300, blank=True, default="")
#     header_subtitle = models.CharField(max_length=500, blank=True, default="")
#     news_category = models.ForeignKey(BlogCategory, null=True, blank=True)
#     vision_pages = models.ManyToManyField(VisionPage, blank=True, verbose_name="Standpunt pagina's")
# 
#     @property
#     def blog_posts(self):
#         return get_public_blogposts(self.news_category)[:4]
# 
#     class Meta:
#         verbose_name = 'Home pagina'
#         verbose_name_plural = "Home pagina's"
# 
# Path: website/jdpages/models.py
# class SidebarSocial(PageItem):
# 
#     @property
#     def urls(self):
#         smulrs = SocialMediaUrls.objects.all()
#         if smulrs.exists():
#             return smulrs[0]
#         return None
# 
#     class Meta:
#         verbose_name = "Sidebar Social Media Item"
# 
# Path: website/jdpages/models.py
# class PageHeaderImage(SiteRelated):
#     """ Page header image. """
#     name = models.CharField(max_length=1000, blank=True, null=False, default="")
#     page = models.ForeignKey(Page, blank=False, null=True)
#     image = FileField(max_length=200, format="Image", validators=[validate_header_image])


import logging
from mezzanine.pages.models import RichTextPage
from fullcalendar.views import OccurrenceView
from website.jdpages.models import HomePage
from website.jdpages.models import SidebarSocial
from website.jdpages.models import PageHeaderImage

    # No image found! If we received an integer, then do not search further
    if isinstance(page, int):
        return None

    # Try from parent
    if page.parent:
        return get_page_header(page.parent)

    # Try from first homepage
    homepage = get_homepage_id()
    if homepage is not None:
        # Since we give get_page_header an integer, there is no infinite recursion here...
        return get_page_header(homepage)

    return None


def get_homepage_header():
    """ Returns the page header image of the homepage """
    homepage_id = get_homepage_id()
    if homepage_id is None:
        return None
    return get_page_header(homepage_id)


class OccuranceJDView(OccurrenceView):

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

# Path: website/jdpages/models.py
# class HomePage(Page, RichText):
#     """
#     Page model for the site homepage.
#     Only works properly when url points to the homepage '/' as url.
#     """
#     header_title = models.CharField(max_length=300, blank=True, default="")
#     header_subtitle = models.CharField(max_length=500, blank=True, default="")
#     news_category = models.ForeignKey(BlogCategory, null=True, blank=True)
#     vision_pages = models.ManyToManyField(VisionPage, blank=True, verbose_name="Standpunt pagina's")
# 
#     @property
#     def blog_posts(self):
#         return get_public_blogposts(self.news_category)[:4]
# 
#     class Meta:
#         verbose_name = 'Home pagina'
#         verbose_name_plural = "Home pagina's"
# 
# Path: website/jdpages/models.py
# class SidebarSocial(PageItem):
# 
#     @property
#     def urls(self):
#         smulrs = SocialMediaUrls.objects.all()
#         if smulrs.exists():
#             return smulrs[0]
#         return None
# 
#     class Meta:
#         verbose_name = "Sidebar Social Media Item"
# 
# Path: website/jdpages/models.py
# class PageHeaderImage(SiteRelated):
#     """ Page header image. """
#     name = models.CharField(max_length=1000, blank=True, null=False, default="")
#     page = models.ForeignKey(Page, blank=False, null=True)
#     image = FileField(max_length=200, format="Image", validators=[validate_header_image])


# Path: website/jdpages/views.py
import logging
from mezzanine.pages.models import RichTextPage
from fullcalendar.views import OccurrenceView
from website.jdpages.models import HomePage
from website.jdpages.models import SidebarSocial
from website.jdpages.models import PageHeaderImage


    # No image found! If we received an integer, then do not search further
    if isinstance(page, int):
        return None

    # Try from parent
    if page.parent:
        return get_page_header(page.parent)

    # Try from first homepage
    homepage = get_homepage_id()
    if homepage is not None:
        # Since we give get_page_header an integer, there is no infinite recursion here...
        return get_page_header(homepage)

    return None


def get_homepage_header():
    """ Returns the page header image of the homepage """
    homepage_id = get_homepage_id()
    if homepage_id is None:
        return None
    return get_page_header(homepage_id)


class OccuranceJDView(OccurrenceView):

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        context['page_for_sidebars'] = HomePage.objects.all().first()