Ejemplo n.º 1
0
class HtmlPageTests(TestCase):
    fixtures = ['pagetypes.json', 'pages.json']

    def setUp(self):
        self.home = HtmlPage.objects.get(slug='home')
        self.level_one = HtmlPage(title='Level One',
            slug='l1',
            content='x',
            parent=self.home,
            page_type=PageType.objects.get(pk=PageType.NORMAL_PAGE)
        )
        self.level_one.save()
        self.client = Client()

    def test_page_creation(self):
        self.assertEqual(3, HtmlPage.objects.count())
        level_two = HtmlPage(title='Level Two',
            slug='l2',
            content='x',
            parent=self.level_one,
            page_type=PageType.objects.get(pk=PageType.NORMAL_PAGE)
        )
        level_two.save()
        self.assertEqual(4, HtmlPage.objects.count())

        for slug in ['home', 'l1', 'l2']:
            self.assertTrue(self._test_url(reverse('pages_display', args=[slug])))

    def _test_url(self, url, expected_status_code=200):
        response = self.client.get(url)
        return (expected_status_code == response.status_code)
Ejemplo n.º 2
0
    def test_page_creation(self):
        self.assertEqual(3, HtmlPage.objects.count())
        level_two = HtmlPage(title='Level Two',
            slug='l2',
            content='x',
            parent=self.level_one,
            page_type=PageType.objects.get(pk=PageType.NORMAL_PAGE)
        )
        level_two.save()
        self.assertEqual(4, HtmlPage.objects.count())

        for slug in ['home', 'l1', 'l2']:
            self.assertTrue(self._test_url(reverse('pages_display', args=[slug])))
Ejemplo n.º 3
0
def show_page(request, slug="home", template='bluetrain/page.html', extra_context={}):
    # look for cached copy of page
    if settings.USE_CACHE:
        cache_key = HtmlPage.get_cache_key_for_page(slug)
        page_view = cache.get(cache_key, None)
        if page_view:
            return page_view

    page = get_object_or_404(HtmlPage, slug=slug, active=True)

    home = False
    show_login_focus = False
    level_one = page.level_one
    is_level_one = (page == page.level_one)

    if slug == 'home':
        home = True
        template = 'bluetrain/home.html'
        level_one_class = 'Home'
    else:
        level_one_class = level_one.css_class()

    context = locals()
    context.update(extra_context)
    page_view = render_to_response(template, context, context_instance=RequestContext(request))
    if settings.USE_CACHE:
        cache.set(cache_key, page_view, settings.DEFAULT_CACHE_TIMEOUT)
    return page_view
Ejemplo n.º 4
0
 def setUp(self):
     self.home = HtmlPage.objects.get(slug='home')
     self.level_one = HtmlPage(title='Level One',
         slug='l1',
         content='x',
         parent=self.home,
         page_type=PageType.objects.get(pk=PageType.NORMAL_PAGE)
     )
     self.level_one.save()
     self.client = Client()