def shorten_name(name):
    """
    Shorten a name so that it fits within our standard 25-char limit.

    If it contains dots, then it'll be collapsed around them as necessary
    before possibly being truncated.

    >>> shorten_name("ThisIsAVeryVeryVeryVeryVeryLongName")
    'ThisIsAVeryVeryVeryVeryV~'
    >>> shorten_name("this.is.also.a.pretty.long.name")
    't.i.a.a.p.l.name'
    """

    if len(name) > 25:
        if "." in name:
            parts = name.split(".")
            last = parts.pop()

            done = ""

            for x in parts:
                done += x[0]
                done += "."

            done += last

            if len(done) > 25:
                done = done[:24] + "~"

            name = done
        else:
            name = name[:24] + "~"

    return name