Allows to call any method of any object with parameters.

    Because come on! It's bloody stupid that Django's templating engine doesn't
    allow that.

    Usage::

        {% call myobj 'mymethod' myvar foobar=myvar2 as result %}
        {% call myobj 'mydict' 'mykey' as result %}
        {% call myobj 'myattribute' as result %}

    :param obj: The object which has the method that you would like to call
    :param method: A string representing the attribute on the object that
      should be called.

def call(obj, method, *args, **kwargs):
    """
    Allows to call any method of any object with parameters.

    Because come on! It's bloody stupid that Django's templating engine doesn't
    allow that.

    Usage::

        {% call myobj 'mymethod' myvar foobar=myvar2 as result %}
        {% call myobj 'mydict' 'mykey' as result %}
        {% call myobj 'myattribute' as result %}

    :param obj: The object which has the method that you would like to call
    :param method: A string representing the attribute on the object that
      should be called.

    """
    function_or_dict_or_member = getattr(obj, method)
    if callable(function_or_dict_or_member):
        # If it is a function, let's call it
        return function_or_dict_or_member(*args, **kwargs)
    if not len(args):
        # If it is a member, lets return it
        return function_or_dict_or_member
    # If it is a dict, let's access one of it's keys
    return function_or_dict_or_member[args[0]]