Example #1
0
    def test_get_page_for_apphook(self):
        en_title, de_title = self.create_base_structure(APP_NAME, ['en', 'de'])
        with force_language("en"):
            path = reverse('sample-settings')
        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'

        attached_to_page = applications_page_check(
            request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page.pk)

        response = self.client.get(path)
        self.assertEqual(response.status_code, 200)

        self.assertTemplateUsed(response, 'sampleapp/home.html')
        self.assertContains(response, en_title.title)
        with force_language("de"):
            path = reverse('sample-settings')
        request = self.get_request(path)
        request.LANGUAGE_CODE = 'de'
        attached_to_page = applications_page_check(
            request, path=path[1:])  # strip leading slash and language prefix
        self.assertEqual(attached_to_page.pk, de_title.page.pk)

        response = self.client.get(path)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'sampleapp/home.html')
        self.assertContains(response, de_title.title)
        self.apphook_clear()
Example #2
0
    def test_get_page_for_apphook_on_preview_or_edit(self):
        if get_user_model().USERNAME_FIELD == 'email':
            superuser = get_user_model().objects.create_superuser('admin', '*****@*****.**', '*****@*****.**')
        else:
            superuser = get_user_model().objects.create_superuser('admin', '*****@*****.**', 'admin')

        page = create_page("home", "nav_playground.html", "en",
                           created_by=superuser, published=True, apphook=APP_NAME)
        create_title('de', page.get_title(), page)
        page.publish('en')
        page.publish('de')
        page.save()

        # Needed because publish button only shows if the page is dirty
        page.set_publisher_state('en', state=PUBLISHER_STATE_DIRTY)

        public_page = page.get_public_object()

        with self.login_user_context(superuser):
            with force_language("en"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
                request.LANGUAGE_CODE = 'en'
                attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
                response = self.client.get(path+"?edit")
                self.assertContains(response, '?redirect=')
            with force_language("de"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
                request.LANGUAGE_CODE = 'de'
                attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
                self.assertEqual(attached_to_page.pk, public_page.pk)
Example #3
0
    def test_get_page_for_apphook(self):

        with SettingsOverride(ROOT_URLCONF="cms.test_utils.project.second_urls_for_apphook_tests"):
            en_title, de_title = self.create_base_structure(APP_NAME, ["en", "de"])
            with force_language("en"):
                path = reverse("sample-settings")
            request = self.get_request(path)
            request.LANGUAGE_CODE = "en"

            attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
            self.assertEqual(attached_to_page.pk, en_title.page.pk)

            response = self.client.get(path)
            self.assertEqual(response.status_code, 200)

            self.assertTemplateUsed(response, "sampleapp/home.html")
            self.assertContains(response, en_title.title)
            with force_language("de"):
                path = reverse("sample-settings")
            request = self.get_request(path)
            request.LANGUAGE_CODE = "de"
            attached_to_page = applications_page_check(
                request, path=path[1:]
            )  # strip leading slash and language prefix
            self.assertEqual(attached_to_page.pk, de_title.page.pk)

            response = self.client.get(path)
            self.assertEqual(response.status_code, 200)
            self.assertTemplateUsed(response, "sampleapp/home.html")
            self.assertContains(response, de_title.title)

            apphook_pool.clear()
Example #4
0
    def test_get_page_for_apphook_on_preview_or_edit(self):

        if get_user_model().USERNAME_FIELD == "email":
            superuser = get_user_model().objects.create_superuser("admin", "*****@*****.**", "*****@*****.**")
        else:
            superuser = get_user_model().objects.create_superuser("admin", "*****@*****.**", "admin")

        page = create_page("home", "nav_playground.html", "en", created_by=superuser, published=True, apphook=APP_NAME)
        create_title("de", page.get_title(), page)
        page.publish("en")
        page.publish("de")
        public_page = page.get_public_object()

        with self.login_user_context(superuser):
            with force_language("en"):
                path = reverse("sample-settings")
                request = self.get_request(path + "?edit")
                request.LANGUAGE_CODE = "en"
                attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
                self.assertEqual(attached_to_page.pk, public_page.pk)
            with force_language("de"):
                path = reverse("sample-settings")
                request = self.get_request(path + "?edit")
                request.LANGUAGE_CODE = "de"
                attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
                self.assertEqual(attached_to_page.pk, public_page.pk)
Example #5
0
    def test_get_page_for_apphook_on_preview_or_edit(self):
        if get_user_model().USERNAME_FIELD == 'email':
            superuser = get_user_model().objects.create_superuser('admin', '*****@*****.**', '*****@*****.**')
        else:
            superuser = get_user_model().objects.create_superuser('admin', '*****@*****.**', 'admin')

        page = create_page("home", "nav_playground.html", "en",
                           created_by=superuser, published=True, apphook=APP_NAME)
        create_title('de', page.get_title(), page)
        page.publish('en')
        page.publish('de')
        page.save()
        public_page = page.get_public_object()

        with self.login_user_context(superuser):
            with force_language("en"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
                request.LANGUAGE_CODE = 'en'
                attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
                response = self.client.get(path+"?edit")
                self.assertContains(response, '?redirect=')
            with force_language("de"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
                request.LANGUAGE_CODE = 'de'
                attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
                self.assertEqual(attached_to_page.pk, public_page.pk)
Example #6
0
    def test_get_page_for_apphook(self):
        en_title, de_title = self.create_base_structure(APP_NAME, ['en', 'de'])
        with force_language("en"):
            path = reverse('sample-settings')
        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'

        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page.pk)

        response = self.client.get(path)
        self.assertEqual(response.status_code, 200)

        self.assertTemplateUsed(response, 'sampleapp/home.html')
        self.assertContains(response, en_title.title)
        with force_language("de"):
            path = reverse('sample-settings')
        request = self.get_request(path)
        request.LANGUAGE_CODE = 'de'
        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash and language prefix
        self.assertEqual(attached_to_page.pk, de_title.page.pk)

        response = self.client.get(path)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'sampleapp/home.html')
        self.assertContains(response, de_title.title)
        self.apphook_clear()
Example #7
0
def details(request, page_id=None, slug=None, template_name=settings.CMS_TEMPLATES[0][0], no404=False):
    lang = get_language_from_request(request)
    site = Site.objects.get_current()
    pages = Page.objects.published().filter(parent__isnull=True).order_by("tree_id")
    current_page, response = None, None
    if pages:
        if page_id:
            current_page = get_object_or_404(Page.objects.published(site), pk=page_id)
        elif slug != None:
            if slug == "":
                current_page = pages[0]
            else:
                path = request.path.replace(reverse('pages-root'), '', 1)
                current_page = _get_current_page(path, lang)
                if settings.CMS_APPLICATIONS_URLS:
                    # check if it should'nt point to some application, if yes,
                    # change current page if required
                    current_page = applications_page_check(request, current_page, path)
                
                if not current_page:
                    raise Http404('CMS Page not found')
        else:
            current_page = applications_page_check(request)
            #current_page = None
        template_name = get_template_from_request(request, current_page)
    elif not no404:
        raise Http404("no page found for site %s" % unicode(site.name))
    if current_page:  
        has_page_permissions = current_page.has_page_permission(request)
        request._current_page_cache = current_page
    else:
        has_page_permissions = False
        
    return template_name, locals()
Example #8
0
    def test_get_page_for_apphook_on_preview_or_edit(self):
        superuser = User.objects.create_superuser('admin', '*****@*****.**',
                                                  'admin')
        page = create_page("home",
                           "nav_playground.html",
                           "en",
                           created_by=superuser,
                           published=True,
                           apphook=APP_NAME)
        create_title('de', page.get_title(), page, apphook=APP_NAME)
        page.publish()
        public_page = page.get_public_object()

        with self.login_user_context(superuser):
            with force_language("en"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?edit')
                request.LANGUAGE_CODE = 'en'
                attached_to_page = applications_page_check(
                    request, path=path[1:])  # strip leading slash
                self.assertEquals(attached_to_page.pk, public_page.pk)
            with force_language("de"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?edit')
                request.LANGUAGE_CODE = 'de'
                attached_to_page = applications_page_check(
                    request, path=path[1:])  # strip leading slash
                self.assertEquals(attached_to_page.pk, public_page.pk)
Example #9
0
    def test_get_page_for_apphook(self):

        with SettingsOverride(ROOT_URLCONF="project.second_urls_for_apphook_tests"):

            apphook_pool.clear()
            superuser = User.objects.create_superuser("admin", "*****@*****.**", "admin")
            page = create_page("home", "nav_playground.html", "en", created_by=superuser, published=True)
            create_title("de", page.get_title(), page)
            child_page = create_page(
                "child_page", "nav_playground.html", "en", created_by=superuser, published=True, parent=page
            )
            create_title("de", child_page.get_title(), child_page)
            child_child_page = create_page(
                "child_child_page",
                "nav_playground.html",
                "en",
                created_by=superuser,
                published=True,
                parent=child_page,
                apphook="SampleApp",
            )
            create_title("de", child_child_page.get_title(), child_child_page, apphook="SampleApp")

            child_child_page.publish()
            # publisher_public is set to draft on publish, issue with onetoone reverse
            child_child_page = self.reload(child_child_page)

            en_title = child_child_page.publisher_public.get_title_obj("en")

            path = reverse("en:sample-settings")

            request = self.get_request(path)
            request.LANGUAGE_CODE = "en"

            attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
            self.assertEquals(attached_to_page.pk, en_title.page.pk)

            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)

            self.assertTemplateUsed(response, "sampleapp/home.html")
            self.assertContains(response, en_title.title)

            de_title = child_child_page.publisher_public.get_title_obj("de")
            path = reverse("de:sample-settings")

            request = self.get_request(path)
            request.LANGUAGE_CODE = "de"

            attached_to_page = applications_page_check(
                request, path=path[4:]
            )  # strip leading slash and language prefix
            self.assertEquals(attached_to_page.pk, de_title.page.pk)

            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateUsed(response, "sampleapp/home.html")
            self.assertContains(response, de_title.title)

            apphook_pool.clear()
Example #10
0
def details(request, page_id=None, slug=None, template_name=settings.CMS_TEMPLATES[0][0], no404=False):
    # get the right model
    PageModel = get_page_model(request)
    
    lang = get_language_from_request(request)
    site = Site.objects.get_current()
    if 'preview' in request.GET.keys():
        pages = PageModel.objects.all()
    else:
        pages = PageModel.objects.published()
    
    root_pages = pages.filter(parent__isnull=True).order_by("tree_id")
    
    current_page, response = None, None
    if root_pages:
        if page_id:
            current_page = get_object_or_404(pages, pk=page_id)
        elif slug != None:
            if slug == "":
                current_page = root_pages[0]
            else:
                if slug.startswith(reverse('pages-root')):
                    path = slug.replace(reverse('pages-root'), '', 1)
                else:
                    path = slug
                if root_pages:
                    home_tree_id = root_pages[0].tree_id
                    home_slug = root_pages[0].get_slug(language=lang)
                else:
                    home_slug = ""
                    home_tree_id = None
                current_page, alternative = get_current_page(path, lang, pages, home_slug, home_tree_id)
                if settings.CMS_APPLICATIONS_URLS:
                    # check if it should'nt point to some application, if yes,
                    # change current page if required
                    current_page = applications_page_check(request, current_page, path)
                if not current_page:
                    if alternative and settings.CMS_LANGUAGE_FALLBACK:
                        return HttpResponseRedirect(alternative)
                    if no404:# used for placeholder finder
                        current_page = None
                    else:
                        raise Http404('CMS: Page not found for "%s"' % slug)
        else:
            current_page = applications_page_check(request)
            #current_page = None
        template_name = get_template_from_request(request, current_page)
    elif not no404:
        raise Http404("CMS: No page found for site %s" % unicode(site.name))
    
    if current_page:  
        has_change_permissions = current_page.has_change_permission(request)
        request._current_page_cache = current_page
        if current_page.get_redirect(language=lang):
            return HttpResponseRedirect(current_page.get_redirect(language=lang))
    else:
        has_change_permissions = False
    return template_name, locals()
Example #11
0
    def test_04_get_page_for_apphook(self):
        
        if APP_MODULE in sys.modules:
            del sys.modules[APP_MODULE]
            
        with SettingsOverride(ROOT_URLCONF='testapp.second_urls_for_apphook_tests'):
    
            apphook_pool.clear()    
            superuser = User.objects.create_superuser('admin', '*****@*****.**', 'admin')
            page = self.create_page(user=superuser, published=True)
            self.create_title(page.get_title(), page.get_slug(), 'de', page)
            child_page = self.create_page(page, user=superuser, published=True)
            self.create_title(child_page.get_title(), child_page.get_slug(), 'de', child_page)
            child_child_page = self.create_page(child_page, user=superuser, published=True)
            self.create_title(child_child_page.get_title(), child_child_page.get_slug(), 'de', child_child_page)
            child_child_page.title_set.all().update(application_urls='SampleApp')
            
            child_child_page.publish()
            # publisher_public is set to draft on publish, issue with onetoone reverse
            child_child_page = self.reload(child_child_page) 
            
            en_title = child_child_page.publisher_public.get_title_obj('en')

            path = reverse('en:sample-settings')
            
            request = self.get_request(path)
            request.LANGUAGE_CODE = 'en'
            
            attached_to_page = applications_page_check(request, path=path[1:]) # strip leading slash
            self.assertEquals(attached_to_page.pk, en_title.page.pk)            
            
            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)

            self.assertTemplateUsed(response, 'sampleapp/home.html')
            self.assertContains(response, en_title.title)
            
            de_title = child_child_page.publisher_public.get_title_obj('de')
            path = reverse('de:sample-settings')
        
            request = self.get_request(path)
            request.LANGUAGE_CODE = 'de'
            
            attached_to_page = applications_page_check(request, path=path[4:]) # strip leading slash and language prefix
            self.assertEquals(attached_to_page.pk, de_title.page.pk)            
            
            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateUsed(response, 'sampleapp/home.html')
            self.assertContains(response, de_title.title)
            
            apphook_pool.clear()
Example #12
0
    def test_get_page_for_apphook(self):
            
        with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
    
            apphook_pool.clear()    
            superuser = User.objects.create_superuser('admin', '*****@*****.**', 'admin')
            page = create_page("home", "nav_playground.html", "en",
                               created_by=superuser, published=True)
            create_title('de', page.get_title(), page)
            child_page = create_page("child_page", "nav_playground.html", "en",
                         created_by=superuser, published=True, parent=page)
            create_title('de', child_page.get_title(), child_page)
            child_child_page = create_page("child_child_page", "nav_playground.html",
                "en", created_by=superuser, published=True, parent=child_page, apphook='SampleApp')
            create_title("de", child_child_page.get_title(), child_child_page, apphook='SampleApp')
            
            child_child_page.publish()
            # publisher_public is set to draft on publish, issue with onetoone reverse
            child_child_page = self.reload(child_child_page) 
            
            en_title = child_child_page.publisher_public.get_title_obj('en')

            path = reverse('en:sample-settings')
            
            request = self.get_request(path)
            request.LANGUAGE_CODE = 'en'
            
            attached_to_page = applications_page_check(request, path=path[1:]) # strip leading slash
            self.assertEquals(attached_to_page.pk, en_title.page.pk)            
            
            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)

            self.assertTemplateUsed(response, 'sampleapp/home.html')
            self.assertContains(response, en_title.title)
            
            de_title = child_child_page.publisher_public.get_title_obj('de')
            path = reverse('de:sample-settings')
        
            request = self.get_request(path)
            request.LANGUAGE_CODE = 'de'
            
            attached_to_page = applications_page_check(request, path=path[4:]) # strip leading slash and language prefix
            self.assertEquals(attached_to_page.pk, de_title.page.pk)            
            
            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateUsed(response, 'sampleapp/home.html')
            self.assertContains(response, de_title.title)
            
            apphook_pool.clear()
Example #13
0
 def __get__(self, request, obj_type=None):
     from cms.utils.page_resolver import get_page_from_request
     if not hasattr(request, '_current_page_cache'):
         request._current_page_cache = get_page_from_request(request)
         if not request._current_page_cache:
             # if this is in a apphook
             # find the page the apphook is attached to
             request._current_page_cache = applications_page_check(request)
     return request._current_page_cache
Example #14
0
 def __get__(self, request, obj_type=None):
     from cms.utils.page_resolver import get_page_from_request
     if not hasattr(request, '_current_page_cache'):
         request._current_page_cache = get_page_from_request(request)
         if not request._current_page_cache:
             # if this is in a apphook
             # find the page the apphook is attached to
             request._current_page_cache = applications_page_check(request)
     return request._current_page_cache
Example #15
0
def get_page(request):
    from cms.appresolver import applications_page_check
    from cms.utils.page import get_page_from_request

    if not hasattr(request, '_current_page_cache'):
        request._current_page_cache = get_page_from_request(request)
        if not request._current_page_cache:
            # if this is in a apphook
            # find the page the apphook is attached to
            request._current_page_cache = applications_page_check(request)
    return request._current_page_cache
Example #16
0
    def test_get_page_for_apphook_on_preview_or_edit(self):
        superuser = User.objects.create_superuser('admin', '*****@*****.**', 'admin')
        page = create_page("home", "nav_playground.html", "en",
                            created_by=superuser, published=True, apphook=APP_NAME)
        create_title('de', page.get_title(), page, apphook=APP_NAME)
        page.publish()
        public_page = page.get_public_object()

        with self.login_user_context(superuser):
            with force_language("en"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?edit')
                request.LANGUAGE_CODE = 'en'
                attached_to_page = applications_page_check(request, path=path[1:]) # strip leading slash
                self.assertEquals(attached_to_page.pk, public_page.pk)
            with force_language("de"):
                path = reverse('sample-settings')
                request = self.get_request(path + '?edit')
                request.LANGUAGE_CODE = 'de'
                attached_to_page = applications_page_check(request, path=path[1:]) # strip leading slash
                self.assertEquals(attached_to_page.pk, public_page.pk)
Example #17
0
    def test_get_child_page_for_apphook_with_instance_namespace(self):
        en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
        with force_language("en"):
            path = reverse('namespaced_app_ns:sample-settings')
            path_instance1 = reverse('instance_ns:sample-settings')
            path_instance2 = reverse('namespaced_app_ns:sample-settings', current_app='instance_ns')
        self.assertEqual(path, path_instance1)
        self.assertEqual(path, path_instance2)

        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'
        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page_id)
        self.apphook_clear()
Example #18
0
    def test_get_child_page_for_apphook_with_instance_namespace(self):
        en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
        with force_language("en"):
            path = reverse('namespaced_app_ns:sample-settings')
            path_instance1 = reverse('instance_ns:sample-settings')
            path_instance2 = reverse('namespaced_app_ns:sample-settings', current_app='instance_ns')
        self.assertEqual(path, path_instance1)
        self.assertEqual(path, path_instance2)

        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'
        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page_id)
        self.apphook_clear()
Example #19
0
    def test_get_child_page_for_apphook_with_instance_namespace(self):
        with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
            en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
            with force_language("en"):
                path = reverse('namespaced_app_ns:sample-settings')
                path_instance1 = reverse('instance_ns:sample-settings')
                path_instance2 = reverse('namespaced_app_ns:sample-settings', current_app='instance_ns')
            self.assertEquals(path, path_instance1)
            self.assertEquals(path, path_instance2)

            request = self.get_request(path)
            request.LANGUAGE_CODE = 'en'
            attached_to_page = applications_page_check(request, path=path[1:]) # strip leading slash
            self.assertEquals(attached_to_page.pk, en_title.page_id)
            apphook_pool.clear()
Example #20
0
    def test_get_child_page_for_apphook_with_instance_namespace(self):
        with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
            en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
            with force_language("en"):
                path = reverse('namespaced_app_ns:sample-settings')
                path_instance1 = reverse('instance_ns:sample-settings')
                path_instance2 = reverse('namespaced_app_ns:sample-settings', current_app='instance_ns')
            self.assertEquals(path, path_instance1)
            self.assertEquals(path, path_instance2)

            request = self.get_request(path)
            request.LANGUAGE_CODE = 'en'
            attached_to_page = applications_page_check(request, path=path[1:]) # strip leading slash
            self.assertEquals(attached_to_page.pk, en_title.page_id)
            apphook_pool.clear()
Example #21
0
    def test_get_sub_page_for_apphook_with_implicit_current_app(self):
        en_title = self.create_base_structure(NS_APP_NAME, 'en', 'namespaced_app_ns')
        with force_language("en"):
            path = reverse('namespaced_app_ns:current-app')
        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'

        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page.pk)

        response = self.client.get(path)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'sampleapp/app.html')
        self.assertContains(response, 'namespaced_app_ns')
        self.assertContains(response, path)
        self.apphook_clear()
Example #22
0
    def test_get_sub_page_for_apphook_with_implicit_current_app(self):
        en_title = self.create_base_structure(NS_APP_NAME, 'en', 'namespaced_app_ns')
        with force_language("en"):
            path = reverse('namespaced_app_ns:current-app')
        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'

        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page.pk)

        response = self.client.get(path)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'sampleapp/app.html')
        self.assertContains(response, 'namespaced_app_ns')
        self.assertContains(response, path)
        self.apphook_clear()
Example #23
0
    def test_get_root_page_for_apphook_with_instance_namespace(self):
        en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')

        self.reload_urls()
        with force_language("en"):
            reverse("example_app:example")
            reverse("example1:example")
            reverse("example2:example")
            path = reverse('namespaced_app_ns:sample-root')
            path_instance = reverse('instance_ns:sample-root')
        self.assertEqual(path, path_instance)

        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'

        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page.pk)
        self.apphook_clear()
Example #24
0
    def test_get_root_page_for_apphook_with_instance_namespace(self):
        en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')

        self.reload_urls()
        with force_language("en"):
            reverse("example_app:example")
            reverse("example1:example")
            reverse("example2:example")
            path = reverse('namespaced_app_ns:sample-root')
            path_instance = reverse('instance_ns:sample-root')
        self.assertEqual(path, path_instance)

        request = self.get_request(path)
        request.LANGUAGE_CODE = 'en'

        attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
        self.assertEqual(attached_to_page.pk, en_title.page.pk)
        self.apphook_clear()
Example #25
0
    def test_get_sub_page_for_apphook_with_implicit_current_app(self):
        with SettingsOverride(ROOT_URLCONF="cms.test_utils.project.second_urls_for_apphook_tests"):
            en_title = self.create_base_structure(NS_APP_NAME, "en", "namespaced_app_ns")
            with force_language("en"):
                path = reverse("namespaced_app_ns:current-app")
            request = self.get_request(path)
            request.LANGUAGE_CODE = "en"

            attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
            self.assertEqual(attached_to_page.pk, en_title.page.pk)

            response = self.client.get(path)
            self.assertEqual(response.status_code, 200)
            self.assertTemplateUsed(response, "sampleapp/app.html")
            self.assertContains(response, "namespaced_app_ns")
            self.assertContains(response, path)

            apphook_pool.clear()
Example #26
0
    def test_get_sub_page_for_apphook_with_explicit_current_app(self):
        with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
            en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
            with force_language("en"):
                path = reverse('namespaced_app_ns:current-app')

            request = self.get_request(path)
            request.LANGUAGE_CODE = 'en'

            attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
            self.assertEqual(attached_to_page.pk, en_title.page.pk)

            response = self.client.get(path)
            self.assertEqual(response.status_code, 200)
            self.assertTemplateUsed(response, 'sampleapp/app.html')
            self.assertContains(response, 'instance_ns')
            self.assertContains(response, path)

            apphook_pool.clear()
Example #27
0
    def test_get_root_page_for_apphook_with_instance_namespace(self):
        with SettingsOverride(ROOT_URLCONF="cms.test_utils.project.second_urls_for_apphook_tests"):
            en_title = self.create_base_structure(NS_APP_NAME, "en", "instance_ns")

            self.reload_urls()
            with force_language("en"):
                reverse("example_app:example")
                reverse("example1:example")
                reverse("example2:example")
                path = reverse("namespaced_app_ns:sample-root")
                path_instance = reverse("instance_ns:sample-root")
            self.assertEqual(path, path_instance)

            request = self.get_request(path)
            request.LANGUAGE_CODE = "en"

            attached_to_page = applications_page_check(request, path=path[1:])  # strip leading slash
            self.assertEqual(attached_to_page.pk, en_title.page.pk)

            apphook_pool.clear()
Example #28
0
def details(request, page_id=None, slug=None, template_name=settings.CMS_TEMPLATES[0][0], no404=False):
    # get the right model
    page_queryset = get_page_queryset(request)
    
    lang = get_language_from_request(request)
    site = Site.objects.get_current()
    if 'preview' in request.GET.keys() and request.user.has_perm(Page._meta.app_label + ' ' + Page._meta.get_change_permission()):
        pages = page_queryset.filter(site=site)
    else:
        pages = page_queryset.published().filter(site=site)
    
    current_page, response = None, None
    if pages.all_root():
        if page_id:
            current_page = get_object_or_404(pages, pk=page_id)
        elif slug != None:
            if slug == "":
                current_page = pages.get_home()
            else:
                pages_root = reverse('pages-root')
                path = slug.startswith(pages_root) and slug[len(pages_root):] or slug

                try:
                    home = pages.get_home()
                    current_page, alternative = get_current_page(path, lang, pages, home.get_slug(language=lang), home.tree_id)
                except NoHomeFound:
                    current_page, alternative = get_current_page(path, lang, pages)
                     
                if apphook_pool.get_apphooks():
                    # check if it shouldn't point to some application, if yes,
                    # change current page if required
                    current_page = applications_page_check(request, current_page, path)
                if not current_page:
                    if alternative and settings.CMS_LANGUAGE_FALLBACK:
                        return HttpResponseRedirect(alternative)
                    if no404:# used for placeholder finder
                        current_page = None
                    else:
                        if not slug and settings.DEBUG:
                            CMS_MEDIA_URL = settings.CMS_MEDIA_URL
                            return "cms/new.html", locals()
                        raise Http404('CMS: Page not found for "%s"' % slug)
        else:
            current_page = applications_page_check(request)
            #current_page = None
        template_name = get_template_from_request(request, current_page, no_current_page=True)
    elif not no404:
        if not slug and settings.DEBUG:
            CMS_MEDIA_URL = settings.CMS_MEDIA_URL
            return "cms/new.html", locals()
        raise Http404("CMS: No page found for site %s" % unicode(site.name))
    
    if current_page:
        has_change_permissions = current_page.has_change_permission(request)
        request._current_page_cache = current_page
        
        redirect_url = current_page.get_redirect(language=lang)
        if redirect_url:
            if settings.i18n_installed and redirect_url[0] == "/":
                redirect_url = "/%s/%s" % (lang, redirect_url.lstrip("/"))
            # add language prefix to url
            return HttpResponseRedirect(redirect_url)
        
        if current_page.login_required and not request.user.is_authenticated():
            if settings.i18n_installed:
                path = urlquote("/%s%s" % (request.LANGUAGE_CODE, request.get_full_path()))
            else:
                path = urlquote(request.get_full_path())
            tup = django_settings.LOGIN_URL , "next", path
            return HttpResponseRedirect('%s?%s=%s' % tup)
    else:
        has_change_permissions = False
    return template_name, locals()
Example #29
0
def details(request, page_id=None, slug=None, template_name=settings.CMS_TEMPLATES[0][0], no404=False):
    # get the right model
    page_queryset = get_page_queryset(request)
    
    lang = get_language_from_request(request)
    site = Site.objects.get_current()
    if 'preview' in request.GET.keys():
        pages = page_queryset.all()
    else:
        pages = page_queryset.published()
    
    root_pages = pages.all_root().order_by("tree_id")
    current_page, response = None, None
    if root_pages:
        if page_id:
            current_page = get_object_or_404(pages, pk=page_id)
        elif slug != None:
            if slug == "":
                current_page = root_pages[0]
            else:
                if slug.startswith(reverse('pages-root')):
                    path = slug.replace(reverse('pages-root'), '', 1)
                else:
                    path = slug
                if root_pages:
                    home_tree_id = root_pages[0].tree_id
                    home_slug = root_pages[0].get_slug(language=lang)
                else:
                    home_slug = ""
                    home_tree_id = None
                current_page, alternative = get_current_page(path, lang, pages, home_slug, home_tree_id)
                if settings.CMS_APPLICATIONS_URLS:
                    # check if it should'nt point to some application, if yes,
                    # change current page if required
                    current_page = applications_page_check(request, current_page, path)
                if not current_page:
                    if alternative and settings.CMS_LANGUAGE_FALLBACK:
                        return HttpResponseRedirect(alternative)
                    if no404:# used for placeholder finder
                        current_page = None
                    else:
                        raise Http404('CMS: Page not found for "%s"' % slug)
        else:
            current_page = applications_page_check(request)
            #current_page = None
        template_name = get_template_from_request(request, current_page)
    elif not no404:
        raise Http404("CMS: No page found for site %s" % unicode(site.name))
    
    if current_page:  
        has_change_permissions = current_page.has_change_permission(request)
        request._current_page_cache = current_page
        if current_page.get_redirect(language=lang):
            return HttpResponseRedirect(current_page.get_redirect(language=lang))
        if current_page.login_required and not request.user.is_authenticated():
            if 'cms.middleware.multilingual.MultilingualURLMiddleware' in django_settings.MIDDLEWARE_CLASSES:
                path = urlquote("/%s%s" % (request.LANGUAGE_CODE, request.get_full_path()))
            else:
                path = urlquote(request.get_full_path())
            tup = django_settings.LOGIN_URL , "next", path
            return HttpResponseRedirect('%s?%s=%s' % tup)
    else:
        has_change_permissions = False
    return template_name, locals()
Example #30
0
def details(request, page_id=None, slug=None, template_name=settings.CMS_TEMPLATES[0][0], no404=False):
    '''
    This is the bitch of the CMS.
    Basically, she does it all. For instance, this is called by a util function 
    to retrieve Models (!), hence the no404 argument.
    
    BADLY NEEDS REFACTORING, BITCH 
    '''
    # get the right model
    page_queryset = get_page_queryset(request)
    
    lang = get_language_from_request(request)
    site = Site.objects.get_current()
    if 'preview' in request.GET.keys():
        pages = page_queryset.filter(site=site)
    else:
        pages = page_queryset.published(site=site)
    
    current_page, response = None, None
    if pages.all_root(): # QUERY!
        # If there is at least one root page (no parent)
        if page_id:
            current_page = get_object_or_404(pages, pk=page_id)# QUERY!
        elif slug != None:
            if slug == "":
                # Gets the first root page (no parent) in the page's tree, 
                # ordered by tree ID
                current_page = pages.get_home()# QUERY!
            else:
                # We have a slug, we get the root using reverse (see ./urls.py) 
                pages_root = reverse('pages-root')
                # If the CMS urls are not the actual root of the url path
                # (http://bullshit.com/blablabla/some/page/slug)
                # Remove the prefix
                # (some/page/slug) 
                if slug.startswith(pages_root):
                    path = slug[len(pages_root):]
                else:  
                    path = slug
                try:
                    home = pages.get_home() # QUERY!
                    current_page, alternative = get_current_page(path, lang, pages, home.get_slug(language=lang), home.tree_id)
                except NoHomeFound:
                    current_page, alternative = get_current_page(path, lang, pages)# QUERY!
                    
                if apphook_pool.get_apphooks():
                    # check if it shouldn't point to some application, if yes,
                    # change current page if required
                    current_page = applications_page_check(request, current_page, path)
                if not current_page:
                    # We still don't have a current page... probably because it 
                    # doesn't exist in the current language, let's lookup for 
                    # the current language's fallback
                    if alternative and settings.CMS_LANGUAGE_FALLBACK:
                        return HttpResponseRedirect(alternative)
                    if no404:# used for placeholder finder
                        current_page = None 
                    else:
                        # "Normal case" - we're being a view
                        if not slug and settings.DEBUG:
                            CMS_MEDIA_URL = settings.CMS_MEDIA_URL
                            # Classic case of "I didn't read the Zen of Python".
                            # This is line 2: "Explicit is better than implicit"
                            return "cms/new.html", locals() # Come on, use a dict!. 
                        raise Http404('CMS: Page not found for "%s"' % slug)
        else:
            # We have an apphook on the root page
            current_page = applications_page_check(request)
            #current_page = None
        template_name = get_template_from_request(request, current_page, no_current_page=True)
    elif not no404: # Double negation: no404 = True
        # If we're not being a view
        if not slug and settings.DEBUG:
            CMS_MEDIA_URL = settings.CMS_MEDIA_URL
            return "cms/new.html", locals() # damn, it should be a dict!
        raise Http404("CMS: No page found for site %s" % unicode(site.name))
    
    if current_page:
        has_change_permissions = current_page.has_change_permission(request)
        request._current_page_cache = current_page
        
        redirect_url = current_page.get_redirect(language=lang)
        if redirect_url:
            if settings.i18n_installed and redirect_url[0] == "/":
                redirect_url = "/%s/%s" % (lang, redirect_url.lstrip("/"))
            # add language prefix to url
            return HttpResponseRedirect(redirect_url)
        
        if current_page.login_required and not request.user.is_authenticated():
            if settings.i18n_installed:
                path = urlquote("/%s%s" % (request.LANGUAGE_CODE, request.get_full_path()))
            else:
                path = urlquote(request.get_full_path())
            tup = django_settings.LOGIN_URL , "next", path
            return HttpResponseRedirect('%s?%s=%s' % tup)
    else:
        has_change_permissions = False
    return template_name, locals() # Ah well, passing the whole context again
Example #31
0
def details(request,
            page_id=None,
            slug=None,
            template_name=settings.CMS_TEMPLATES[0][0],
            no404=False):
    # get the right model
    page_queryset = get_page_queryset(request)

    lang = get_language_from_request(request)
    site = Site.objects.get_current()
    if 'preview' in request.GET.keys():
        pages = page_queryset.filter(site=site)
    else:
        pages = page_queryset.published().filter(site=site)

    current_page, response = None, None
    if pages.all_root():
        if page_id:
            current_page = get_object_or_404(pages, pk=page_id)
        elif slug != None:
            if slug == "":
                current_page = pages.get_home()
            else:
                pages_root = reverse('pages-root')
                path = slug.startswith(
                    pages_root) and slug[len(pages_root):] or slug

                try:
                    home = pages.get_home()
                    current_page, alternative = get_current_page(
                        path, lang, pages, home.get_slug(language=lang),
                        home.tree_id)
                except NoHomeFound:
                    current_page, alternative = get_current_page(
                        path, lang, pages)

                if apphook_pool.get_apphooks():
                    # check if it shouldn't point to some application, if yes,
                    # change current page if required
                    current_page = applications_page_check(
                        request, current_page, path)
                if not current_page:
                    if alternative and settings.CMS_LANGUAGE_FALLBACK:
                        return HttpResponseRedirect(alternative)
                    if no404:  # used for placeholder finder
                        current_page = None
                    else:
                        if not slug and settings.DEBUG:
                            CMS_MEDIA_URL = settings.CMS_MEDIA_URL
                            return "cms/new.html", locals()
                        raise Http404('CMS: Page not found for "%s"' % slug)
        else:
            current_page = applications_page_check(request)
            #current_page = None
        template_name = get_template_from_request(request,
                                                  current_page,
                                                  no_current_page=True)
    elif not no404:
        if not slug and settings.DEBUG:
            CMS_MEDIA_URL = settings.CMS_MEDIA_URL
            return "cms/new.html", locals()
        raise Http404("CMS: No page found for site %s" % unicode(site.name))

    if current_page:
        has_change_permissions = current_page.has_change_permission(request)
        request._current_page_cache = current_page

        redirect_url = current_page.get_redirect(language=lang)
        if redirect_url:
            if settings.i18n_installed and redirect_url[0] == "/":
                redirect_url = "/%s/%s" % (lang, redirect_url.lstrip("/"))
            # add language prefix to url
            return HttpResponseRedirect(redirect_url)

        if current_page.login_required and not request.user.is_authenticated():
            if settings.i18n_installed:
                path = urlquote(
                    "/%s%s" % (request.LANGUAGE_CODE, request.get_full_path()))
            else:
                path = urlquote(request.get_full_path())
            tup = django_settings.LOGIN_URL, "next", path
            return HttpResponseRedirect('%s?%s=%s' % tup)
    else:
        has_change_permissions = False
    return template_name, locals()
Example #32
0
    def test_04_get_page_for_apphook(self):

        if APP_MODULE in sys.modules:
            del sys.modules[APP_MODULE]

        with SettingsOverride(
                ROOT_URLCONF='testapp.second_urls_for_apphook_tests'):

            apphook_pool.clear()
            superuser = User.objects.create_superuser('admin',
                                                      '*****@*****.**',
                                                      'admin')
            page = self.create_page(user=superuser, published=True)
            self.create_title(page.get_title(), page.get_slug(), 'de', page)
            child_page = self.create_page(page, user=superuser, published=True)
            self.create_title(child_page.get_title(), child_page.get_slug(),
                              'de', child_page)
            child_child_page = self.create_page(child_page,
                                                user=superuser,
                                                published=True)
            self.create_title(child_child_page.get_title(),
                              child_child_page.get_slug(), 'de',
                              child_child_page)
            child_child_page.title_set.all().update(
                application_urls='SampleApp')

            child_child_page.publish()
            # publisher_public is set to draft on publish, issue with onetoone reverse
            child_child_page = self.reload(child_child_page)

            en_title = child_child_page.publisher_public.get_title_obj('en')

            path = reverse('en:sample-settings')

            request = self.get_request(path)
            request.LANGUAGE_CODE = 'en'

            attached_to_page = applications_page_check(
                request, path=path[1:])  # strip leading slash
            self.assertEquals(attached_to_page.pk, en_title.page.pk)

            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)

            self.assertTemplateUsed(response, 'sampleapp/home.html')
            self.assertContains(response, en_title.title)

            de_title = child_child_page.publisher_public.get_title_obj('de')
            path = reverse('de:sample-settings')

            request = self.get_request(path)
            request.LANGUAGE_CODE = 'de'

            attached_to_page = applications_page_check(
                request,
                path=path[4:])  # strip leading slash and language prefix
            self.assertEquals(attached_to_page.pk, de_title.page.pk)

            response = self.client.get(path)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateUsed(response, 'sampleapp/home.html')
            self.assertContains(response, de_title.title)

            apphook_pool.clear()