'Mark this hierarchy as dirty. To be called when the target
table gets updated (can be called repeatedly).
@param tablename: the tablename'

@classmethod
def dirty(cls, tablename):

    s3db = current.s3db
    if (not tablename):
        return
    config = s3db.get_config(tablename, 'hierarchy')
    if (not config):
        return
    hierarchies = current.model.hierarchies
    if (tablename in hierarchies):
        hierarchy = hierarchies[tablename]
        flags = hierarchy['flags']
    else:
        flags = {}
        hierarchies[tablename] = {'nodes': dict(), 'flags': flags}
    flags['dirty'] = True
    dbstatus = flags.get('dbstatus', True)
    if dbstatus:
        htable = current.s3db.s3_hierarchy
        query = (htable.tablename == tablename)
        row = current.db(query).select(htable.id, htable.dirty, limitby=(0, 1)).first()
        if (not row):
            htable.insert(tablename=tablename, dirty=True)
        elif (not row.dirty):
            row.update_record(dirty=True)
        flags['dbstatus'] = False
    return
