Skip to content
This repository has been archived by the owner on Dec 9, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into site-support
Browse files Browse the repository at this point in the history
Conflicts:
	test_project/settings.py
  • Loading branch information
zerok committed Oct 8, 2011
2 parents 17f9119 + 4426a5a commit 2a9b115
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -136,6 +136,11 @@ the `django-better-chunks`_ fork (``django.contrib.site``- and i18n-support).
Releases
--------

0.5.1
* Removed rendering of the content attribute from the admin list by Michael Fladischer
* PyBabel compatibility by Michael Fladischer
* Fixed caching issue with memcache backend

0.5
* Hungarian translation by Török Gábor
* Method added to demo edit form (#5) by Bill Evans
Expand Down
28 changes: 23 additions & 5 deletions flatblocks/templatetags/flatblock_tags.py
Expand Up @@ -17,7 +17,9 @@
The number of seconds that text should get cached after it has been
fetched from the database.
This field is option and defaults to no caching.
This field is optional and defaults to no caching (0).
To use Django's default caching length use None.
Example::
Expand Down Expand Up @@ -46,8 +48,11 @@

from flatblocks import settings

import logging


register = template.Library()
logger = logging.getLogger(__name__)

FlatBlock = models.get_model('flatblocks', 'flatblock')

Expand Down Expand Up @@ -96,7 +101,8 @@ def prepare(self, parser, token):
self.tpl_is_variable = True
else:
self.tpl_name = self.tpl_name[1:-1]
self.cache_time = int(self.cache_time)
if self.cache_time is not None and self.cache_time != 'None':
self.cache_time = int(self.cache_time)

def __call__(self, parser, token):
self.prepare(parser, token)
Expand Down Expand Up @@ -142,8 +148,10 @@ def render(self, context):
new_ctx = template.Context({})
new_ctx.update(context)
try:
cache_key = settings.CACHE_PREFIX + real_slug
flatblock = cache.get(cache_key)
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
Expand All @@ -157,7 +165,17 @@ def render(self, context):
slug=real_slug,
defaults = {'content': real_slug}
)
cache.set(cache_key, flatblock, int(self.cache_time))
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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -7,7 +7,7 @@

setup(
name = 'django-flatblocks',
version = '0.5.0',
version = '0.5.1',
description = 'django-flatblocks acts like django.contrib.flatpages but '
'for parts of a page; like an editable help box you want '
'show alongside the main content.',
Expand Down
3 changes: 3 additions & 0 deletions test_project/settings.py
@@ -1,5 +1,8 @@
import os
import sys
import logging

logging.basicConfig(level=logging.DEBUG)

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
#sys.path.insert(0, os.path.dirname(PROJECT_ROOT))
Expand Down
12 changes: 12 additions & 0 deletions test_project/templates/index.html
@@ -0,0 +1,12 @@
{% load flatblock_tags %}<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Test page for flatblock rendering</title>
</head>
<body>
{% flatblock 'test1' 0 %} <!-- No caching -->
{% flatblock 'test2' 10 %} <!-- 10s caching -->
{% flatblock 'test3' None %} <!-- Default length caching -->
</body>
</html>
2 changes: 2 additions & 0 deletions test_project/urls.py
@@ -1,10 +1,12 @@
from django.conf.urls.defaults import *
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib import admin
from . import views

admin.autodiscover()

urlpatterns = patterns('',
url('^flatblocks/', include("flatblocks.urls")),
url('^admin/', include(admin.site.urls)),
url('^/?', views.index),
)
5 changes: 5 additions & 0 deletions test_project/views.py
@@ -0,0 +1,5 @@
from django.shortcuts import render_to_response


def index(request):
return render_to_response('index.html')

0 comments on commit 2a9b115

Please sign in to comment.