Moved Jinja2 stuff to its own module, and added |undertitle filter.
This commit is contained in:
parent
f03566a10f
commit
b2e8711ac4
@ -5,10 +5,10 @@ import logging
|
||||
import logging.config
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
import jinja2
|
||||
import os
|
||||
import os.path
|
||||
|
||||
import jinja2
|
||||
from eve import Eve
|
||||
import flask
|
||||
from flask import render_template, request
|
||||
@ -16,8 +16,7 @@ from flask.templating import TemplateNotFound
|
||||
|
||||
from pillar.api import custom_field_validation
|
||||
from pillar.api.utils import authentication
|
||||
from pillar.web.utils import pretty_date
|
||||
from pillar.web.nodes.routes import url_for_node
|
||||
import pillar.web.jinja
|
||||
|
||||
from . import api
|
||||
from . import web
|
||||
@ -249,15 +248,7 @@ class PillarServer(Eve):
|
||||
custom_jinja_loader = jinja2.ChoiceLoader(paths_list)
|
||||
self.jinja_loader = custom_jinja_loader
|
||||
|
||||
def format_pretty_date(d):
|
||||
return pretty_date(d)
|
||||
|
||||
def format_pretty_date_time(d):
|
||||
return pretty_date(d, detail=True)
|
||||
|
||||
self.jinja_env.filters['pretty_date'] = format_pretty_date
|
||||
self.jinja_env.filters['pretty_date_time'] = format_pretty_date_time
|
||||
self.jinja_env.globals['url_for_node'] = url_for_node
|
||||
pillar.web.jinja.setup_jinja_env(self.jinja_env)
|
||||
|
||||
def _config_static_dirs(self):
|
||||
pillar_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
32
pillar/web/jinja.py
Normal file
32
pillar/web/jinja.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""Our custom Jinja filters and other template stuff."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import jinja2.filters
|
||||
|
||||
from pillar.web.utils import pretty_date
|
||||
from pillar.web.nodes.routes import url_for_node
|
||||
|
||||
|
||||
def format_pretty_date(d):
|
||||
return pretty_date(d)
|
||||
|
||||
|
||||
def format_pretty_date_time(d):
|
||||
return pretty_date(d, detail=True)
|
||||
|
||||
|
||||
def format_undertitle(s):
|
||||
"""Underscore-replacing title filter.
|
||||
|
||||
Replaces underscores with spaces, and then applies Jinja2's own title filter.
|
||||
"""
|
||||
|
||||
return jinja2.filters.do_title(s.replace('_', ' '))
|
||||
|
||||
|
||||
def setup_jinja_env(jinja_env):
|
||||
jinja_env.filters['pretty_date'] = format_pretty_date
|
||||
jinja_env.filters['pretty_date_time'] = format_pretty_date_time
|
||||
jinja_env.filters['undertitle'] = format_undertitle
|
||||
jinja_env.globals['url_for_node'] = url_for_node
|
Loading…
x
Reference in New Issue
Block a user