# Path: simple_cms/models.py
# class Navigation(TextMixin, CommonAbstractModel):
#     """
#     Navigation and Page combined model
#     Customizations on One-To-One in implementing app
#     """
#     title = models.CharField(max_length=255, help_text='Navigation and default page title')
#     slug = AutoSlugField(editable=True, populate_from='title')
#     group = models.ForeignKey(NavigationGroup, blank=True, null=True)
#     parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
#     order = PositionField(collection=('parent', 'site'))
#     site = models.ForeignKey(Site, related_name='pages')
#     homepage = models.BooleanField(default=False)
#     url = models.CharField(max_length=255, blank=True, default='', help_text='eg. link somewhere else http://awesome.com/ or /awesome/page/')
#     target = models.CharField(max_length=255, blank=True, default='', help_text='eg. open link in "_blank" window', choices=TARGET_CHOICES)
#     page_title = models.CharField(max_length=255, blank=True, default='', help_text='Optional html title')
#     text = models.TextField(blank=True, default='')
#     format = models.CharField(max_length=255, blank=True, default='', choices=FORMAT_CHOICES)
#     render_as_template = models.BooleanField(default=False)
#     template = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common/awesome.html')
#     view = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common.views.awesome')
#     redirect_url = models.CharField(max_length=255, blank=True, default='')
#     redirect_permanent = models.BooleanField(default=False)
#     inherit_blocks = models.BooleanField(default=True, verbose_name="Inherit Blocks")
#     inherit_template = models.BooleanField(default=False, verbose_name="Inherit Template")
#     seo = GenericRelation(Seo)
#     blocks = GenericRelation(RelatedBlock)
# 
#     class Meta:
#         unique_together = (('site', 'slug', 'parent'),)
#         ordering = ['title']
#         verbose_name_plural = 'Navigation'
# 
#     def __unicode__(self):
#         return u'%s' % self._chain()
# 
#     def clean(self):
#         from django.core.exceptions import ValidationError
#         if self.parent == self:
#             raise ValidationError('Can\'t set parent to self.')
# 
#     def num_blocks(self):
#         l = len(self.blocks.all())
#         if l:
#             return l
#         return ''
# 
#     def custom_template(self):
#         if self.template:
#             return '<img src="%sadmin/img/icon-yes.gif" alt="yes" title="%s">' % (settings.STATIC_URL, self.template)
#         return ''
#     custom_template.allow_tags = True
#     custom_template.admin_order_field = 'template'
# 
#     def custom_view(self):
#         if self.view:
#             return '<img src="%sadmin/img/icon-yes.gif" alt="yes" title="%s">' % (settings.STATIC_URL, self.view)
#         return ''
#     custom_view.allow_tags = True
#     custom_view.admin_order_field = 'view'
# 
#     def root(self):
#         item = self
#         while item.parent:
#             item = item.parent
#         return item
# 
#     def get_title(self):
#         if self.page_title:
#             return self.page_title
#         return self.title
# 
#     def _chain(self, prop='title'):
#         """ Create slug chain for an object and its parent(s). """
#         item = self
#         tA = [getattr(item, prop)]
#         while item.parent:
#             item = item.parent
#             tA.append(getattr(item, prop))
#         else:
#             pass
#         tA.reverse()
#         return '/'.join(['%s' % name for name in tA])
# 
#     def get_absolute_url(self):
#         if self.url:
#             return self.url
#         return mark_safe('/%s/' % self._chain('slug'))
# 
#     def get_children(self):
#         return self.children.all().filter(active=True).order_by('order')
# 
#     @property
#     def href(self):
#         r = ''
#         if self.target:
#             r = r+'target="%s"' % self.target
#         if self.url:
#             r = r+'href="%s"' % self.url
#             return mark_safe(r)
#         r = r+'href="/%s/"' % self._chain('slug')
#         return mark_safe(r)
# 
#     @property
#     def link_attributes(self):
#         return self.href
# 
#     @property
#     def depth(self):
#         depth = 0
#         item = self
#         while item.parent:
#             item = item.parent
#             depth += 1
#         else:
#             pass
#         return depth
# 
#     @property
#     def search_description(self):
#         return self.text


from django.contrib.sites.models import Site, RequestSite
from django.conf import settings
from simple_cms.models import Navigation
                    if self.check_domain and self.site:
                        kwargs['site'] = self.site
                    self.page = Navigation.objects.get(**kwargs)
                    self.pageA.append(self.page)
                    self.exact_match = True
                    return True
                except Navigation.DoesNotExist:
                    return False
        except:
            return False
        return False
    
    def find_page(self):
        admin_preview = False
        try:
            admin_preview = self.request.GET.get('admin_preview')
            if admin_preview:
                if not self.request.user.is_authenticated or not self.request.user.is_staff:
                    return
        except KeyError:
            pass
        for slug in self.urlA:
            try:
                kwargs = {'active': True, 'parent':self.page, 'slug':slug}
                if admin_preview:
                    del kwargs['active']
                if self.check_domain and self.site:
                    kwargs['site'] = self.site
                self.page = Navigation.objects.get(**kwargs)
                self.pageA.append(self.page)

# Path: simple_cms/models.py
# class Navigation(TextMixin, CommonAbstractModel):
#     """
#     Navigation and Page combined model
#     Customizations on One-To-One in implementing app
#     """
#     title = models.CharField(max_length=255, help_text='Navigation and default page title')
#     slug = AutoSlugField(editable=True, populate_from='title')
#     group = models.ForeignKey(NavigationGroup, blank=True, null=True)
#     parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
#     order = PositionField(collection=('parent', 'site'))
#     site = models.ForeignKey(Site, related_name='pages')
#     homepage = models.BooleanField(default=False)
#     url = models.CharField(max_length=255, blank=True, default='', help_text='eg. link somewhere else http://awesome.com/ or /awesome/page/')
#     target = models.CharField(max_length=255, blank=True, default='', help_text='eg. open link in "_blank" window', choices=TARGET_CHOICES)
#     page_title = models.CharField(max_length=255, blank=True, default='', help_text='Optional html title')
#     text = models.TextField(blank=True, default='')
#     format = models.CharField(max_length=255, blank=True, default='', choices=FORMAT_CHOICES)
#     render_as_template = models.BooleanField(default=False)
#     template = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common/awesome.html')
#     view = models.CharField(max_length=255, blank=True, default='', help_text='Eg. common.views.awesome')
#     redirect_url = models.CharField(max_length=255, blank=True, default='')
#     redirect_permanent = models.BooleanField(default=False)
#     inherit_blocks = models.BooleanField(default=True, verbose_name="Inherit Blocks")
#     inherit_template = models.BooleanField(default=False, verbose_name="Inherit Template")
#     seo = GenericRelation(Seo)
#     blocks = GenericRelation(RelatedBlock)
# 
#     class Meta:
#         unique_together = (('site', 'slug', 'parent'),)
#         ordering = ['title']
#         verbose_name_plural = 'Navigation'
# 
#     def __unicode__(self):
#         return u'%s' % self._chain()
# 
#     def clean(self):
#         from django.core.exceptions import ValidationError
#         if self.parent == self:
#             raise ValidationError('Can\'t set parent to self.')
# 
#     def num_blocks(self):
#         l = len(self.blocks.all())
#         if l:
#             return l
#         return ''
# 
#     def custom_template(self):
#         if self.template:
#             return '<img src="%sadmin/img/icon-yes.gif" alt="yes" title="%s">' % (settings.STATIC_URL, self.template)
#         return ''
#     custom_template.allow_tags = True
#     custom_template.admin_order_field = 'template'
# 
#     def custom_view(self):
#         if self.view:
#             return '<img src="%sadmin/img/icon-yes.gif" alt="yes" title="%s">' % (settings.STATIC_URL, self.view)
#         return ''
#     custom_view.allow_tags = True
#     custom_view.admin_order_field = 'view'
# 
#     def root(self):
#         item = self
#         while item.parent:
#             item = item.parent
#         return item
# 
#     def get_title(self):
#         if self.page_title:
#             return self.page_title
#         return self.title
# 
#     def _chain(self, prop='title'):
#         """ Create slug chain for an object and its parent(s). """
#         item = self
#         tA = [getattr(item, prop)]
#         while item.parent:
#             item = item.parent
#             tA.append(getattr(item, prop))
#         else:
#             pass
#         tA.reverse()
#         return '/'.join(['%s' % name for name in tA])
# 
#     def get_absolute_url(self):
#         if self.url:
#             return self.url
#         return mark_safe('/%s/' % self._chain('slug'))
# 
#     def get_children(self):
#         return self.children.all().filter(active=True).order_by('order')
# 
#     @property
#     def href(self):
#         r = ''
#         if self.target:
#             r = r+'target="%s"' % self.target
#         if self.url:
#             r = r+'href="%s"' % self.url
#             return mark_safe(r)
#         r = r+'href="/%s/"' % self._chain('slug')
#         return mark_safe(r)
# 
#     @property
#     def link_attributes(self):
#         return self.href
# 
#     @property
#     def depth(self):
#         depth = 0
#         item = self
#         while item.parent:
#             item = item.parent
#             depth += 1
#         else:
#             pass
#         return depth
# 
#     @property
#     def search_description(self):
#         return self.text


# Path: simple_cms/context_processors.py
from django.contrib.sites.models import Site, RequestSite
from django.conf import settings
from simple_cms.models import Navigation

                    if self.check_domain and self.site:
                        kwargs['site'] = self.site
                    self.page = Navigation.objects.get(**kwargs)
                    self.pageA.append(self.page)
                    self.exact_match = True
                    return True
                except Navigation.DoesNotExist:
                    return False
        except:
            return False
        return False
    
    def find_page(self):
        admin_preview = False
        try:
            admin_preview = self.request.GET.get('admin_preview')
            if admin_preview:
                if not self.request.user.is_authenticated or not self.request.user.is_staff:
                    return
        except KeyError:
            pass
        for slug in self.urlA:
            try:
                kwargs = {'active': True, 'parent':self.page, 'slug':slug}
                if admin_preview:
                    del kwargs['active']
                if self.check_domain and self.site:
                    kwargs['site'] = self.site
                self.page = Navigation.objects.get(**kwargs)
                self.pageA.append(self.page)

            except Navigation.DoesNotExist: