示例#1
0
 def test_cache_key(self):
     eq_('flatcontent_None_test-content_en-us',
         FlatContent.key_from_slug(self.flat_content.slug))
     eq_('flatcontent_1_test-content_en-us',
         FlatContent.key_from_slug(self.flat_site_content.slug,
                                   site_id=self.flat_site_content.site.id))
     translation.activate('tr')
     eq_('flatcontent_None_test-content_tr',
         FlatContent.key_from_slug(self.flat_content.slug))
示例#2
0
 def test_get(self):
     eq_('test content', FlatContent.get('test-content'))
     eq_('test content with site',
         FlatContent.get('test-content', site_id=self.site.id))
     site = SiteFactory.create()
     site.save()
     eq_('test content', FlatContent.get('test-content', site_id=site.id))
     # Check that the items are now in the cache
     with patch.object(FlatContent.objects, 'get') as mock_objects_get:
         eq_('test content', FlatContent.get('test-content'))
         eq_(mock_objects_get.call_count, 0)
    def test_get_with_context(self):
        """
        Check that get works with or without context, and no cache is used
        with context
        """
        flatcontent = FlatContentFactory.create(
            slug='test-tpl', site=None, content='Hi {{ name }}')

        assert FlatContent.get('test-tpl') == 'Hi '
        assert FlatContent.get('test-tpl', context={
            'name': 'Brad',
        }) == 'Hi Brad'
    def render(self, context):
        site_id = self.site_id
        if self.site_id != None:
            site_id = template.Variable(site_id).resolve(context)

        flat_content = FlatContent.get(slug=self.slug, site_id=site_id)
        if not self.context_var:
            return flat_content
        else:
            context[self.context_var] = flat_content
        return ''
    def render(self, context):
        site_id = self.for_site
        if self.for_site != None:
            site_id = template.Variable(site_id).resolve(context)

        flat_content = FlatContent.get(
            slug=self.slug,
            site_id=site_id,
            context={
                key: val.resolve(context)
                for key, val in self.with_.items()
            },
        )
        if not self.as_:
            return flat_content
        else:
            context[self.as_] = flat_content
        return ''
 def render(self, context):
     if not self.context_var:
         return FlatContent.get(slug=self.slug)
     else:
         context[self.context_var] = FlatContent.get(slug=self.slug)
     return ''
示例#7
0
 def test_get_not_found(self):
     # Test the flatcontent doesn't exist
     eq_('', FlatContent.get('not-found'))
示例#8
0
 def test_get_fallback(self):
     # Test the non site-specific fallback
     FlatContentFactory.create(
         slug='test-content2', site=None, content='test content2').save()
     eq_('test content2',
         FlatContent.get('test-content2', site_id=self.site.id))