Commit 1c16ba98 authored by Serge S. Koval's avatar Serge S. Koval

Added jinja2 context to the list formatting callback.

Example here: https://gist.github.com/3714266
parent 7cd9efdf
from flask import request, url_for, redirect, flash
from jinja2 import contextfunction
from flask.ext.admin.babel import gettext
from flask.ext.admin.base import BaseView, expose
......@@ -665,17 +667,20 @@ class BaseModelView(BaseView, ActionsMixin):
"""
return name not in self.disallowed_actions
def get_list_value(self, model, name):
@contextfunction
def get_list_value(self, context, model, name):
"""
Returns value to be displayed in list view
:param context:
Jinja2 context
:param model:
Model instance
:param name:
Field name
"""
if name in self.list_formatters:
return self.list_formatters[name](model, name)
return self.list_formatters[name](context, model, name)
return rec_getattr(model, name)
......
def macro(name):
'''
Jinja2 macro list column formatter.
:param name:
Macro name in the current template
'''
def inner(context, model, column):
m = context.resolve(name)
if not m:
return m
return m(model=model, column=column)
return inner
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment