Browse Source

moving jinja custom filters and import it to create_app

Axolotle 1 year ago
parent
commit
cb92fa58df

+ 5
- 0
app/__init__.py View File

@@ -18,6 +18,7 @@ base_path = op.dirname(__file__)
18 18
 
19 19
 def create_app(config_name):
20 20
     app = Flask(__name__, static_url_path='/staticsite')
21
+    app.debug = True
21 22
     # add haml-like template syntax to jinja_env
22 23
     app.jinja_env.add_extension('hamlish_jinja.HamlishExtension')
23 24
     app.config.from_object(config[config_name])
@@ -32,4 +33,8 @@ def create_app(config_name):
32 33
     from app.main import main as main_blueprint
33 34
     app.register_blueprint(main_blueprint)
34 35
 
36
+    # import custom filters for jinja templates
37
+    from app.main.jinja_custom_filters import custom_filters
38
+    app.jinja_env.filters = dict(app.jinja_env.filters, **custom_filters)
39
+
35 40
     return app

+ 3
- 5
app/main/jinja_custom_filters.py View File

@@ -1,9 +1,7 @@
1
-from jinja2 import filters
2
-
3
-# FIXME try to make decorator @app.template_filter() work
4
-# figuring out where is jinja_env or create it
5 1
 def format_date(value, format='%d/%m/%Y'):
6 2
     """ Return date to given format"""
7 3
     return value.strftime(format)
8 4
 
9
-filters.FILTERS['format_date'] = format_date
5
+custom_filters = {
6
+    'format_date' : format_date,
7
+}

app/templates/_macros.html → app/templates/_macros.haml View File


app/templates/index.html → app/templates/index.haml View File


app/templates/menu.html → app/templates/menu.haml View File


app/templates/player.html → app/templates/player.haml View File


Loading…
Cancel
Save