mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-03-16 21:30:24 +00:00
add an explicit cache timeout value in the CacheRosettaStorage, to mitigate #59
This commit is contained in:
parent
01ef9ab227
commit
f243ab7eaa
4 changed files with 33 additions and 25 deletions
|
|
@ -86,7 +86,7 @@ class CacheRosettaStorage(BaseRosettaStorage):
|
|||
|
||||
def set(self, key, val):
|
||||
#print ('set', self._key_prefix + key)
|
||||
cache.set(self._key_prefix + key, val)
|
||||
cache.set(self._key_prefix + key, val, 86400)
|
||||
|
||||
def has(self, key):
|
||||
#print ('has', self._key_prefix + key)
|
||||
|
|
|
|||
|
|
@ -3,44 +3,48 @@ from django.utils.safestring import mark_safe
|
|||
from django.utils.html import escape
|
||||
import re
|
||||
from django.template import Node
|
||||
from django.utils.encoding import smart_str, smart_unicode
|
||||
from django.template.defaultfilters import stringfilter
|
||||
from django.utils.encoding import smart_unicode
|
||||
|
||||
|
||||
register = template.Library()
|
||||
rx = re.compile(r'(%(\([^\s\)]*\))?[sd])')
|
||||
|
||||
|
||||
def format_message(message):
|
||||
return mark_safe(rx.sub('<code>\\1</code>', escape(message).replace(r'\n','<br />\n')))
|
||||
format_message=register.filter(format_message)
|
||||
return mark_safe(rx.sub('<code>\\1</code>', escape(message).replace(r'\n', '<br />\n')))
|
||||
format_message = register.filter(format_message)
|
||||
|
||||
|
||||
def lines_count(message):
|
||||
return 1 + sum([len(line)/50 for line in message.split('\n')])
|
||||
lines_count=register.filter(lines_count)
|
||||
return 1 + sum([len(line) / 50 for line in message.split('\n')])
|
||||
lines_count = register.filter(lines_count)
|
||||
|
||||
def mult(a,b):
|
||||
return int(a)*int(b)
|
||||
mult=register.filter(mult)
|
||||
|
||||
def minus(a,b):
|
||||
def mult(a, b):
|
||||
return int(a) * int(b)
|
||||
mult = register.filter(mult)
|
||||
|
||||
|
||||
def minus(a, b):
|
||||
try:
|
||||
return int(a) - int(b)
|
||||
except:
|
||||
return 0
|
||||
minus=register.filter(minus)
|
||||
minus = register.filter(minus)
|
||||
|
||||
def gt(a,b):
|
||||
|
||||
def gt(a, b):
|
||||
try:
|
||||
return int(a) > int(b)
|
||||
except:
|
||||
return False
|
||||
gt=register.filter(gt)
|
||||
gt = register.filter(gt)
|
||||
|
||||
|
||||
def do_incr(parser, token):
|
||||
args = token.split_contents()
|
||||
if len(args) < 2:
|
||||
raise TemplateSyntaxError("'incr' tag requires at least one argument")
|
||||
raise SyntaxError("'incr' tag requires at least one argument")
|
||||
name = args[1]
|
||||
if not hasattr(parser, '_namedIncrNodes'):
|
||||
parser._namedIncrNodes = {}
|
||||
|
|
@ -51,26 +55,28 @@ do_incr = register.tag('increment', do_incr)
|
|||
|
||||
|
||||
class IncrNode(template.Node):
|
||||
def __init__(self, init_val=0):
|
||||
self.val = init_val
|
||||
def __init__(self, init_val=0):
|
||||
self.val = init_val
|
||||
|
||||
def render(self, context):
|
||||
self.val += 1
|
||||
return smart_unicode(self.val)
|
||||
|
||||
|
||||
def render(self, context):
|
||||
self.val += 1
|
||||
return smart_unicode(self.val)
|
||||
|
||||
|
||||
def is_fuzzy(message):
|
||||
return message and hasattr(message, 'flags') and 'fuzzy' in message.flags
|
||||
is_fuzzy = register.filter(is_fuzzy)
|
||||
|
||||
|
||||
class RosettaCsrfTokenPlaceholder(Node):
|
||||
def render(self, context):
|
||||
return mark_safe(u"<!-- csrf token placeholder -->")
|
||||
|
||||
|
||||
def rosetta_csrf_token(parser, token):
|
||||
try:
|
||||
from django.template.defaulttags import csrf_token
|
||||
return csrf_token(parser,token)
|
||||
return csrf_token(parser, token)
|
||||
except ImportError:
|
||||
return RosettaCsrfTokenPlaceholder()
|
||||
rosetta_csrf_token=register.tag(rosetta_csrf_token)
|
||||
rosetta_csrf_token = register.tag(rosetta_csrf_token)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ from rosetta.signals import entry_changed, post_save
|
|||
from rosetta.storage import get_storage
|
||||
import re
|
||||
import rosetta
|
||||
import datetime
|
||||
import unicodedata
|
||||
import hashlib
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django.conf.urls.defaults import patterns, include, url
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
|
|
@ -16,3 +17,5 @@ urlpatterns = patterns('',
|
|||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^rosetta/', include('rosetta.urls'))
|
||||
)
|
||||
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
|
|
|
|||
Loading…
Reference in a new issue