def format(format_string, cast=lambda x: x):
    """
    A pre-called helper to supply a modern string format (the kind with {} instead of %s), so that
    it can apply to each value in the column as it is rendered.  This can be useful for string
    padding like leading zeroes, or rounding floating point numbers to a certain number of decimal
    places, etc.

    If given, the ``cast`` argument should be a mapping function that coerces the input to whatever
    type is required for the string formatting to work.  Trying to push string data into a float
    format will raise an exception, for example, so the ``float`` type itself could be given as
    the ``cast`` function.

    Examples::

        # Perform some 0 padding
        item_number = columns.FloatColumn("Item No.", sources=['number'],
                                          processor=format("{:03d}))

        # Force a string column value to coerce to float and round to 2 decimal places
        rating = columns.TextColumn("Rating", sources=['avg_rating'],
                                    processor=format("{:.2f}", cast=float))

    """

    def helper(instance, *args, **kwargs):
        value = kwargs.get('default_value')
        if value is None:
            value = instance
        value = cast(value)
        return format_string.format(value, obj=instance)
    return helper