# Path: digihel/mixins.py
# class RelativeURLMixin(object):
#     def relative_url(self, current_site, request=None):
#         url_parts = self.get_url_parts()
# 
#         if url_parts is None:
#             # page is not routable
#             return
# 
#         site_id, root_url, page_path = url_parts
# 
#         return page_path
# 
#     # Override the method to support the case where we have
#     # one Site for testing and another for production.
#     def get_url_parts(self, request=None):
#         possible_sites = [
#             (pk, path, url)
#             for pk, path, url in self._get_site_root_paths(request)
#             if self.url_path.startswith(path)
#         ]
# 
#         if not possible_sites:
#             return None
# 
#         test_site_paths = set([x for x in possible_sites if 'test' in Site.objects.get(id=x[0]).site_name.lower()])
#         prod_site_paths = set(possible_sites) - test_site_paths
#         if False and self.content_type.app_label == 'kehmet':
#             possible_sites = list(test_site_paths)
#         else:
#             possible_sites = list(prod_site_paths)
# 
#         if len(possible_sites) == 0:
#             return None
# 
#         site_id, root_path, root_url = possible_sites[0]
# 
#         if hasattr(request, 'site'):
#             for site_id, root_path, root_url in possible_sites:
#                 if site_id == request.site.pk:
#                     break
#             else:
#                 site_id, root_path, root_url = possible_sites[0]
# 
#         page_path = reverse(
#             'wagtail_serve', args=(self.url_path[len(root_path):],))
# 
#         # Remove the trailing slash from the URL reverse generates if
#         # WAGTAIL_APPEND_SLASH is False and we're not trying to serve
#         # the root path
#         if not WAGTAIL_APPEND_SLASH and page_path != '/':
#             page_path = page_path.rstrip('/')
# 
#         return (site_id, root_url, page_path)


from django.db import models
from django.utils.translation import ugettext_lazy as _
from modelcluster.fields import ParentalKey
from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.admin.edit_handlers import (
    FieldPanel, InlinePanel, MultiFieldPanel, PageChooserPanel, StreamFieldPanel
)
from wagtail.core import blocks
from wagtail.core.fields import StreamField
from wagtail.core.models import Orderable, Page
from wagtail.documents.edit_handlers import DocumentChooserPanel
from wagtail.images.blocks import ImageChooserBlock
from wagtail.search import index
from wagtail_svgmap.blocks import ImageMapBlock
from digihel.mixins import RelativeURLMixin
    class Meta:
        abstract = True


class RelatedLink(LinkFields):
    title = models.CharField(max_length=255, help_text="Link title")

    panels = [
        FieldPanel('title'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

    def __str__(self):
        return self.title

    class Meta:
        abstract = True


class ContentPage(RelativeURLMixin, Page):
    body = StreamField(content_blocks)

    content_panels = Page.content_panels + [
        StreamFieldPanel('body')
    ]
    search_fields = Page.search_fields + [
        index.SearchField('body')
    ]



# Path: digihel/mixins.py
# class RelativeURLMixin(object):
#     def relative_url(self, current_site, request=None):
#         url_parts = self.get_url_parts()
# 
#         if url_parts is None:
#             # page is not routable
#             return
# 
#         site_id, root_url, page_path = url_parts
# 
#         return page_path
# 
#     # Override the method to support the case where we have
#     # one Site for testing and another for production.
#     def get_url_parts(self, request=None):
#         possible_sites = [
#             (pk, path, url)
#             for pk, path, url in self._get_site_root_paths(request)
#             if self.url_path.startswith(path)
#         ]
# 
#         if not possible_sites:
#             return None
# 
#         test_site_paths = set([x for x in possible_sites if 'test' in Site.objects.get(id=x[0]).site_name.lower()])
#         prod_site_paths = set(possible_sites) - test_site_paths
#         if False and self.content_type.app_label == 'kehmet':
#             possible_sites = list(test_site_paths)
#         else:
#             possible_sites = list(prod_site_paths)
# 
#         if len(possible_sites) == 0:
#             return None
# 
#         site_id, root_path, root_url = possible_sites[0]
# 
#         if hasattr(request, 'site'):
#             for site_id, root_path, root_url in possible_sites:
#                 if site_id == request.site.pk:
#                     break
#             else:
#                 site_id, root_path, root_url = possible_sites[0]
# 
#         page_path = reverse(
#             'wagtail_serve', args=(self.url_path[len(root_path):],))
# 
#         # Remove the trailing slash from the URL reverse generates if
#         # WAGTAIL_APPEND_SLASH is False and we're not trying to serve
#         # the root path
#         if not WAGTAIL_APPEND_SLASH and page_path != '/':
#             page_path = page_path.rstrip('/')
# 
#         return (site_id, root_url, page_path)


# Path: content/models.py
from django.db import models
from django.utils.translation import ugettext_lazy as _
from modelcluster.fields import ParentalKey
from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.admin.edit_handlers import (
    FieldPanel, InlinePanel, MultiFieldPanel, PageChooserPanel, StreamFieldPanel
)
from wagtail.core import blocks
from wagtail.core.fields import StreamField
from wagtail.core.models import Orderable, Page
from wagtail.documents.edit_handlers import DocumentChooserPanel
from wagtail.images.blocks import ImageChooserBlock
from wagtail.search import index
from wagtail_svgmap.blocks import ImageMapBlock
from digihel.mixins import RelativeURLMixin

    class Meta:
        abstract = True


class RelatedLink(LinkFields):
    title = models.CharField(max_length=255, help_text="Link title")

    panels = [
        FieldPanel('title'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

    def __str__(self):
        return self.title

    class Meta:
        abstract = True


class ContentPage(RelativeURLMixin, Page):
    body = StreamField(content_blocks)

    content_panels = Page.content_panels + [
        StreamFieldPanel('body')
    ]
    search_fields = Page.search_fields + [
        index.SearchField('body')
    ]



class LinkedContentPage(RelativeURLMixin, Page):