template: gidx methods improvment:
gidx methods now use the filtered name to return global indexes. For instance, if "widget" is filtered name, first index will be "widget", then "widget_1", "widget_2" and so one. If an other name is used, it restart (e.g. for "label": "label", "label_1", "label_2", etc.).
This commit is contained in:
parent
07d5a18b79
commit
789a3056d9
1 changed files with 13 additions and 8 deletions
|
|
@ -126,14 +126,17 @@ class Indexer(object):
|
|||
"""Index global to a page"""
|
||||
|
||||
def __init__(self):
|
||||
self._idx = 0
|
||||
self._indexes = {}
|
||||
|
||||
def next(self):
|
||||
self._idx+=1
|
||||
return self._idx
|
||||
def next(self, value):
|
||||
if value not in self._indexes:
|
||||
self._indexes[value] = 0
|
||||
return 0
|
||||
self._indexes[value] += 1
|
||||
return self._indexes[value]
|
||||
|
||||
def current(self):
|
||||
return self._idx
|
||||
def current(self, value):
|
||||
return self._indexes.get(value)
|
||||
|
||||
|
||||
class ScriptsHandler(object):
|
||||
|
|
@ -319,12 +322,14 @@ class Renderer(object):
|
|||
@jinja2.contextfilter
|
||||
def _next_gidx(self, ctx, value):
|
||||
"""Use next current global index as suffix"""
|
||||
return u"{}_{}".format(value, ctx['gidx'].next())
|
||||
next_ = ctx['gidx'].next(value)
|
||||
return value if next_ == 0 else u"{}_{}".format(value, next_)
|
||||
|
||||
@jinja2.contextfilter
|
||||
def _cur_gidx(self, ctx, value):
|
||||
"""Use current current global index as suffix"""
|
||||
return u"{}_{}".format(value, ctx['gidx'].current())
|
||||
current = ctx['gidx'].current(value)
|
||||
return value if not current else u"{}_{}".format(value, current)
|
||||
|
||||
def _date_days(self, timestamp):
|
||||
return int(time.time() - int(timestamp))/(3600*24)
|
||||
|
|
|
|||
Loading…
Reference in a new issue