def render(self, context):
        if self.is_variable:
            real_slug = template.Variable(self.slug).resolve(context)
        else:
            real_slug = self.slug
        if isinstance(self.template_name, template.Variable):
            real_template = self.template_name.resolve(context)
        else:
            real_template = self.template_name
        # Eventually we want to pass the whole context to the template so that
        # users have the maximum of flexibility of what to do in there.
        if self.with_template:
            new_ctx = template.Context({})
            new_ctx.update(context)
        try:
            flatblock = None
            if self.cache_time != 0:
                cache_key = settings.CACHE_PREFIX + real_slug
                flatblock = cache.get(cache_key)
            if flatblock is None:

                # if flatblock's slug is hard-coded in template then it is
                # safe and convenient to auto-create block if it doesn't exist.
                # This behaviour can be configured using the
                # FLATBLOCKS_AUTOCREATE_STATIC_BLOCKS setting
                if self.is_variable or not settings.AUTOCREATE_STATIC_BLOCKS:
                    flatblock = FlatBlock.objects.get(slug=real_slug)
                else:
                    flatblock, _ = FlatBlock.objects.get_or_create(
                                      slug=real_slug,
                                      defaults = {'content': real_slug}
                                   )
                if self.cache_time != 0:
                    if self.cache_time is None or self.cache_time == 'None':
                        logger.debug("Caching %s for the cache's default timeout"
                                % (real_slug,))
                        cache.set(cache_key, flatblock)
                    else:
                        logger.debug("Caching %s for %s seconds" % (real_slug,
                            str(self.cache_time)))
                        cache.set(cache_key, flatblock, int(self.cache_time))
                else:
                    logger.debug("Don't cache %s" % (real_slug,))

            if self.with_template:
                tmpl = loader.get_template(real_template)
                if(flatblock.markdown):
                    newblock = {'content': downmark(flatblock.content), 'slug': flatblock.slug, 'header': flatblock.header}
                    new_ctx.update({'flatblock':newblock})
                else:
                    new_ctx.update({'flatblock':flatblock})
                return tmpl.render(new_ctx)
            else:
                return flatblock.content
        except FlatBlock.DoesNotExist:
            return ''
Exemple #2
0
 def richanswer(self):
     return downmark(self.answer)
Exemple #3
0
def pages(request, slug_name):
    dict = {}
    block = FlatBlock.objects.get(slug=slug_name)
    dict["header_data"] = block.header
    dict["content_data"] = downmark(block.content) if block.markdown else block.content
    return render_to_response('pages.html', dict, context_instance=RequestContext(request))
Exemple #4
0
 def richquestion(self):
     return downmark(self.question)