Created
September 20, 2013 00:28
-
-
Save mitsuhiko/6631789 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set has_changed = make_has_changed() %} | |
{% for item in foo %} | |
{% if has_changed(item.date.year, item.date.month) %} | |
<h1>{{ item.date.year }} {{ item.date.month }}</h1> | |
{% endif %} | |
... | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HasChangedHelper(object): | |
def __init__(self): | |
self.state = None | |
def __call__(self, *new_state): | |
if self.state != new_state: | |
self.state = new_state | |
return True | |
return False | |
jinja_env.globals['make_has_changed'] = HasChangedHelper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment