Beispiel #1
0
    def test_default_view_with_language_prefix(self):
        """
        Test that everything is working with the language prefix option
        activated.
        """
        self.set_setting("PAGE_USE_LANGUAGE_PREFIX", True)

        from pages.views import details
        req = get_request_mock()
        self.assertRaises(Http404, details, req, '/pages/')

        page1 = self.new_page(content={'slug': 'page1'})
        page2 = self.new_page(content={'slug': 'page2'})

        self.assertEqual(page1.get_url_path(),
            reverse('pages-details-by-path', args=[],
            kwargs={'lang': 'en-us', 'path': 'page1'})
        )

        self.assertEqual(details(req, page1.get_url_path(),
            only_context=True)['current_page'],
            page1)

        self.assertEqual(details(req, path=page2.get_complete_slug(),
            only_context=True)['current_page'], page2)

        self.assertEqual(details(req, page2.get_url_path(),
            only_context=True)['current_page'],
            page2)

        self.set_setting("PAGE_USE_LANGUAGE_PREFIX", False)

        self.assertEqual(details(req, page2.get_url_path(),
            only_context=True)['current_page'],
            page2)
Beispiel #2
0
 def test_context_processor(self):
     """Test that the page's context processor is properly activated."""
     from pages.views import details
     req = get_request_mock()
     page1 = self.new_page(content={'slug': 'page1', 'title': 'hello'})
     page1.save()
     self.set_setting("PAGES_MEDIA_URL", "test_request_context")
     self.assertContains(details(req, path='/'), "test_request_context")
Beispiel #3
0
 def pages_view_decorator(request, *args, **kwargs):
     path = kwargs.pop('path', None)
     lang = kwargs.pop('lang', None)
     if path or lang:
         from pages.views import details
         response = details(request, path=path, lang=lang,
             only_context=True, delegation=False)
         context = response
         kwargs.update(context)
     return view(request, *args, **kwargs)
Beispiel #4
0
def get_placeholders(request, template_name):
    """
    Return a list of PlaceholderNode found in the given template
    """
    try:
        temp = loader.get_template(template_name)
    except TemplateDoesNotExist:
        return []
    context = details(request, only_context=True)
    temp.render(RequestContext(request, context))
    list = []
    placeholders_recursif(temp.nodelist, list)
    return list
Beispiel #5
0
    def pages_view_decorator(request, *args, **kwargs):
        # if the current page is already there
        if(kwargs.get('current_page', False) or
            kwargs.get('pages_navigation', False)):
            return view(request, *args, **kwargs)

        path = kwargs.pop('path', None)
        lang = kwargs.pop('lang', None)
        if path:
            from pages.views import details
            response = details(request, path=path, lang=lang,
                only_context=True, delegation=False)
            context = response
            kwargs.update(context)
        return view(request, *args, **kwargs)
    def test_view_context(self):
        """
        Test that the default view can only return the context
        """
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['slug'] = 'page1'
        # create a page for the example otherwise you will get a Http404 error
        response = c.post(add_url, page_data)
        page1 = Content.objects.get_content_slug_by_slug('page1').page

        from pages.views import details
        request = get_request_mock()
        context = details(request, path='/page1/', only_context=True)
        self.assertEqual(context['current_page'], page1)
    def test_view_context(self):
        """
        Test that the default view can only return the context
        """
        c = self.get_admin_client()
        page_data = self.get_new_page_data()
        page_data['slug'] = 'page1'
        # create a page for the example otherwise you will get a Http404 error
        response = c.post(add_url, page_data)
        page1 = Content.objects.get_content_slug_by_slug('page1').page

        from pages.views import details
        request = get_request_mock()
        context = details(request, path='/page1/', only_context=True)
        self.assertEqual(context['current_page'], page1)
    def test_view_context(self):
        """
        Test that the default view can only return the context
        """
        c = self.get_admin_client()
        c.login(username='******', password='******')
        page_data = self.get_new_page_data()
        page_data['slug'] = 'page1'
        # create a page for the example otherwise you will get a Http404 error
        response = c.post('/admin/pages/page/add/', page_data)
        page1 = Content.objects.get_content_slug_by_slug('page1').page

        from pages.views import details
        from pages.utils import get_request_mock
        request = get_request_mock()
        context = details(request, only_context=True)
        self.assertEqual(context['current_page'], page1)
Beispiel #9
0
    def pages_view_decorator(request, *args, **kwargs):
        # if the current page is already there
        if (kwargs.get('current_page', False)
                or kwargs.get('pages_navigation', False)):
            return view(request, *args, **kwargs)

        path = kwargs.pop('path', None)
        lang = kwargs.pop('lang', None)
        if path:
            from pages.views import details
            response = details(request,
                               path=path,
                               lang=lang,
                               only_context=True,
                               delegation=False)
            context = response
            kwargs.update(context)
        return view(request, *args, **kwargs)
    def test_view_context(self):
        """
        Test that the default view can only return the context
        """
        c = self.get_admin_client()
        c.login(username="******", password="******")
        page_data = self.get_new_page_data()
        page_data["slug"] = "page1"
        # create a page for the example otherwise you will get a Http404 error
        response = c.post("/admin/pages/page/add/", page_data)
        page1 = Content.objects.get_content_slug_by_slug("page1").page

        from pages.views import details
        from pages.utils import get_request_mock

        request = get_request_mock()
        context = details(request, path="/page1/", only_context=True)
        self.assertEqual(context["current_page"], page1)
Beispiel #11
0
def get_placeholders(template_name):
    """Return a list of PlaceholderNode found in the given template"""
    try:
        temp = loader.get_template(template_name)
    except TemplateDoesNotExist:
        return []
        
    request = get_request_mock()

    try:
        # to avoid circular import
        from pages.views import details
        context = details(request, only_context=True)
    except Http404:
        context = {}
    temp.render(RequestContext(request, context))
    plist, blist = [], []
    placeholders_recursif(temp.nodelist, plist, blist)
    return plist
Beispiel #12
0
    def pages_view_decorator(request, *args, **kwargs):
        # if the current page is already there
        if(kwargs.get('current_page', False) or
            kwargs.get('pages_navigation', False)):
            return view(request, *args, **kwargs)

        path = kwargs.pop('path', None)
        lang = kwargs.pop('lang', None)
        if path:
            from pages.views import details
            response = details(request, path=path, lang=lang,
                only_context=True, delegation=False)
            context = response
            if not type({}) == type(context):
                # context is a HttpResponseRedirect obj, return it
                # TODO: check this!!!
                return context

            extra_context_var = kwargs.pop('extra_context_var', None)
            if extra_context_var:
                kwargs.update({extra_context_var: context})
            else:
                kwargs.update(context)
        return view(request, *args, **kwargs)
Beispiel #13
0
 def _get_context_page(path):
     return details(req, path, 'en-us')
Beispiel #14
0
 def _get_context_page(path):
     return details(req, path, 'en-us')