from django import template from middleware import threadlocals regist

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from django import template
from middleware import threadlocals
register = template.Library()
@register.inclusion_tag('common/block_emit.html')
def block_emit(category):
p = threadlocals.storage_get(threadlocals.StorageKeys.PAGE_INCLUDE)
r = None
if (p):
if (category in p):
r = p[category];
return {
'include': r,
}
def addcategory(category, value):
p = threadlocals.storage_get(threadlocals.StorageKeys.PAGE_INCLUDE)
if (not p):
p = {}
if (category in p):
category[p] += value
else:
category[p] = value
threadlocals.storage_set(threadlocals.StorageKeys.PAGE_INCLUDE, p)
@register.simple_tag
def head_jsurl(url):
# addcategory("header", "<script type='text/javascript' src='%s'></script>\n" % (url))
return None
@register.tag
def head_include(parser, token):
nodelist = parser.parse(('endhead_include',))
parser.delete_first_token()
return HeadBlock(nodelist)
class HeadBlock(template.Node):
def __init__(self, nodelist):
self.nodelist = nodelist
def render(self, context):
output = self.nodelist.render(context)
print output
addcategory("header", "%s\n" % (output))
print "ues"
return None