import functools


def replace_filters(**kwarg_mapping):
    """Decorator to replace kwargs.

    Examples:
       kwargs: {'a': 'b'}, kwarg_mapping: {'a': 'c'}
       replaced kwargs to decorated func:
          {'c': 'b'}

    replace_filters is used to replace caller's input
    to make it understandable by models.py.
    """
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            replaced_kwargs = {}
            for key, value in kwargs.items():
                if key in kwarg_mapping:
                    replaced_kwargs[kwarg_mapping[key]] = value
                else:
                    replaced_kwargs[key] = value
            return func(*args, **replaced_kwargs)
        return wrapper
    return decorator