'Calculates and sets user disk usage.'

def calculate_and_set_disk_usage(self):

    new = None
    db_session = object_session(self)
    current = self.get_disk_usage()
    if (db_session.get_bind().dialect.name not in ('postgres', 'postgresql')):
        done = False
        while (not done):
            new = self.calculate_disk_usage()
            db_session.refresh(self)
            if (self.get_disk_usage() == current):
                done = True
            else:
                current = self.get_disk_usage()
    else:
        new = pgcalc(db_session, self.id)
    if (new not in (current, None)):
        self.set_disk_usage(new)
        db_session.add(self)
        db_session.flush()
