예제 #1
0
파일: views.py 프로젝트: Iv/django-page-cms
 def resolve_page(self, request, context, is_staff):
     """Return the appropriate page according to the path."""
     path = context['path']
     lang = context['lang']
     page = Page.objects.from_path(path, lang,
         exclude_drafts=(not is_staff))
     if page:
         return page
     # if the complete path didn't worked out properly 
     # and if didn't used PAGE_USE_STRICT_URL setting we gonna
     # try to see if it might be a delegation page.
     # To do that we remove the right part of the url and try again
     # to find a page that match
     if not settings.PAGE_USE_STRICT_URL:
         path = remove_slug(path)
         while path is not None:
             page = Page.objects.from_path(path, lang,
                 exclude_drafts=(not is_staff))
             # find a match. Is the page delegating?
             if page:
                 if page.delegate_to:
                     return page
             path = remove_slug(path)
             
     return None
예제 #2
0
    def resolve_page(self, request, context, is_staff):
        """Return the appropriate page according to the path."""
        path = context['path']
        lang = context['lang']
        page = Page.objects.from_path(path,
                                      lang,
                                      exclude_drafts=(not is_staff))
        if page:
            return page
        # if the complete path didn't worked out properly
        # and if didn't used PAGE_USE_STRICT_URL setting we gonna
        # try to see if it might be a delegation page.
        # To do that we remove the right part of the url and try again
        # to find a page that match
        if not settings.PAGE_USE_STRICT_URL:
            path = remove_slug(path)
            while path is not None:
                page = Page.objects.from_path(path,
                                              lang,
                                              exclude_drafts=(not is_staff))
                # find a match. Is the page delegating?
                if page:
                    if page.delegate_to:
                        return page
                path = remove_slug(path)

        return None
예제 #3
0
 def resolve_page(self, request, context, is_staff):
     """Return the appropriate page according to the path."""
     path = context['path']
     lang = context['lang']
     page = Page.objects.from_path(path, lang,
         exclude_drafts=(not is_staff))
     if page:
         return page
     # if the complete path didn't worked out properly 
     # and if didn't used PAGE_USE_STRICT_URL setting we gonna
     # try to see if it might be a delegation page.
     # To do that we remove the right part of the url and try again
     # to find a page that match
     if not settings.PAGE_USE_STRICT_URL:
         path = remove_slug(path)
         while path is not None:
             page = Page.objects.from_path(path, lang,
                 exclude_drafts=(not is_staff))
             # find a match. Is the page delegating?
             if page:
                 if page.delegate_to:
                     return page
                 # find children and take first one (auto-delegate)
                 children = page.get_children().filter(
                     status__in=(Page.PUBLISHED, Page.HIDDEN), sites=settings.SITE_ID)
                 first_child = None
                 while children:
                     first_child = children[0]
                     if first_child.expose_content():
                         children = None
                     else:
                         children = first_child.get_children().filter(
                             status__in=(Page.PUBLISHED, Page.HIDDEN), sites=settings.SITE_ID)
                 if first_child:
                     first_child.redirect_to_url = first_child.get_url_path(lang)
                     return first_child
             path = remove_slug(path)
             
     return None
예제 #4
0
 def test_remove_slug(self):
     """Test the remove slug function."""
     self.assertEqual(remove_slug('hello/world/toto'), 'hello/world')
     self.assertEqual(remove_slug('hello/world'), 'hello')
     self.assertEqual(remove_slug('/hello/world/'), 'hello')
     self.assertEqual(remove_slug('hello'), None)