(source, top=None, bottom=None, maxrank=5000, klass=None)
return rank
top, bottom, and source are all objects with the .rank attribute.
    maxrank is the maximum rank to aim for when placing objects at the top.
top, bottom, and source are all objects with the .rank attribute.
    maxrank is the maximum rank to aim for when placing objects at the top.
top bottom and source are all objects with the . rank attribute . maxrank is the maximum rank to aim for when placing objects at the top .
def compute_rank(source, top=None, bottom=None, maxrank=5000, klass=None):
    """
    top, bottom, and source are all objects with the .rank attribute.
    maxrank is the maximum rank to aim for when placing objects at the top.
    """

    # No top, move to the top.
    if not top:
        # Add to the max rank and bump to the top
        rank = maxrank + (source.rank / 2)
        return rank

    # No bottom, move as bottom.
    if not bottom:
        # Reduce from top to place on bottom.
        rank = top.rank - (top.rank / 2)
        return rank

    # Get the ranks of the top and bottom objects
    brank = bottom.rank
    trank = top.rank

    # Deal with corner case: top and bottom ranks are the same.
    if brank == trank:
        # Reduce the bottom rank by a given bias
        brank = bottom.rank = brank - 1
        # Update the bottom rank to be below top.
        klass.objects.filter(pk=bottom.pk).update(rank=bottom.rank)

    # Place the current rank in between the top and bottom.
    rank = (trank + brank) / 2

    return rank
def compute_rank ( source , top = None , bottom = None , maxrank = 5000 , klass = None ) : # No top, move to the top. if not top : # Add to the max rank and bump to the top rank = maxrank + ( source . rank / 2 ) return rank # No bottom, move as bottom. if not bottom : # Reduce from top to place on bottom. rank = top . rank - ( top . rank / 2 ) return rank # Get the ranks of the top and bottom objects brank = bottom . rank trank = top . rank # Deal with corner case: top and bottom ranks are the same. if brank == trank : # Reduce the bottom rank by a given bias brank = bottom . rank = brank - 1 # Update the bottom rank to be below top. klass . objects . filter ( pk = bottom . pk ) . update ( rank = bottom . rank ) # Place the current rank in between the top and bottom. rank = ( trank + brank ) / 2 return rank