'Helper method to sort messages according to sender priority.'

@staticmethod
def sort_by_sender(row):

    s3db = current.s3db
    db = current.db
    ptable = s3db.msg_parsing_status
    mtable = s3db.msg_message
    stable = s3db.msg_sender
    try:
        pmessage = db((ptable.id == row.id)).select(ptable.message_id)
        m_id = pmessage.message_id
        message = db((mtable.id == m_id)).select(mtable.from_address, limitby=(0, 1)).first()
        sender = message.from_address
        srecord = db((stable.sender == sender)).select(stable.priority, limitby=(0, 1)).first()
        return srecord.priority
    except:
        import sys
        return sys.maxint
