def truncate_str(str, n=35, end=True, mark='…'):
    """
    Convenience function to truncate a string to n characters, and end or begin
    with an ellipsis (if it exceeds n characters)

    :param str: The string to truncate
    :param n: The length to truncate to
    :param end: True to truncate the end, False to truncate the start
    :param mark: The mark to use; defaults to an ellipsis

    :returns: The truncated string
    """
    assert len(mark) < n

    if len(str) <= n:
        return str

    n -= len(mark)

    return str[:n] + mark if end else mark + str[-n:]