From 804b24dcdba35db5b492b4f38615fdf56f5e6733 Mon Sep 17 00:00:00 2001 From: Rehan Dalal Date: Tue, 2 Oct 2012 02:49:35 -0400 Subject: [PATCH] Small fix to bootstrapping --- standup/app.py | 8 ++--- standup/helpers/__init__.py | 1 - standup/helpers/jinja2/__init__.py | 1 - standup/helpers/jinja2/ifchanged.py | 45 ----------------------------- 4 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 standup/helpers/__init__.py delete mode 100644 standup/helpers/jinja2/__init__.py delete mode 100644 standup/helpers/jinja2/ifchanged.py diff --git a/standup/app.py b/standup/app.py index c74e5a1..b9f39cc 100644 --- a/standup/app.py +++ b/standup/app.py @@ -486,10 +486,8 @@ def _day(day): return datetime.strptime(day, '%Y-%m-%d') +@app.before_request def bootstrap(): - #Add Jinja extensions - app.jinja_env.add_extension('helpers.jinja2.ifchanged.IfChangedExtension') - # Jinja global variables projects = Project.query.order_by(Project.name).filter(Project.statuses.any()) teams = Team.query.order_by(Team.name).all() @@ -506,9 +504,7 @@ def bootstrap(): if __name__ == '__main__': db.create_all() - - app.before_request(bootstrap) - + # Bind to PORT if defined, otherwise default to 5000. port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port, debug=settings.DEBUG) diff --git a/standup/helpers/__init__.py b/standup/helpers/__init__.py deleted file mode 100644 index 20c2d21..0000000 --- a/standup/helpers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'rdalal' diff --git a/standup/helpers/jinja2/__init__.py b/standup/helpers/jinja2/__init__.py deleted file mode 100644 index 20c2d21..0000000 --- a/standup/helpers/jinja2/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'rdalal' diff --git a/standup/helpers/jinja2/ifchanged.py b/standup/helpers/jinja2/ifchanged.py deleted file mode 100644 index 43ab465..0000000 --- a/standup/helpers/jinja2/ifchanged.py +++ /dev/null @@ -1,45 +0,0 @@ -from weakref import WeakKeyDictionary -from jinja2 import contextfunction -from jinja2.ext import Extension, nodes - - -class IfChangedExtension(Extension): - """An extension that implements ifchanged (like in django) for Jinja2""" - tags = set(['ifchanged']) - - _buffered_data = WeakKeyDictionary() - - def parse(self, parser): - # get the line number of our tag and skip the "ifchanged" name - lineno = parser.stream.next().lineno - # create the arguments for our "_if_changed" method on our extension. - # it only gets one constant argument that is a (not that unique, but - # good enough for this example) key it uses to buffer the ifchanged body - args = [nodes.Const(parser.free_identifier().name, - lineno=lineno)] - # parse everything up to endifchanged and drop the "endifchange" name - # (the needle) - body = parser.parse_statements(['name:endifchanged'], - drop_needle=True) - # create a callblock node that calls "_if_changed" with the arguments - # from above. The callblock passes a function to the function as - # "caller" keyword argument that renders the body. - return nodes.CallBlock(self.call_method('_if_changed', args), - [], [], body).set_lineno(lineno) - - @contextfunction - def _if_changed(self, context, key, caller): - """The if-changed callback. Because it's a contextfunction it also - gets the context as first argument. - """ - try: - buffers = self._buffered_data[context] - except KeyError: - self._buffered_data[context] = buffers = {} - body = caller() - if key not in buffers or buffers[key] != body: - rv = body - else: - rv = u'' - buffers[key] = body - return rv \ No newline at end of file