def set_theme_requires(sector_ids):
 ttable = s3db.project_theme
 tstable = s3db.project_theme_sector
 rows = db().select(ttable.id, tstable.sector_id, left=tstable.on((ttable.id == tstable.theme_id)))
 sector_ids = (sector_ids or [])
 theme_ids = [row.project_theme.id for row in rows if ((not row.project_theme_sector.sector_id) or (row.project_theme_sector.sector_id in sector_ids))]
 table = s3db.project_theme_project
 field = table.theme_id
 field.requires = IS_EMPTY_OR(IS_ONE_OF(db, 'project_theme.id', field.represent, filterby='id', filter_opts=theme_ids, sort=True))

def set_theme_requires ( sector_ids ) : ttable = s3db . project_theme tstable = s3db . project_theme_sector rows = db ( ) . select ( ttable . id , tstable . sector_id , left = tstable . on ( ( ttable . id == tstable . theme_id ) ) ) sector_ids = ( sector_ids or [ ] ) theme_ids = [ row . project_theme . id for row in rows if ( ( not row . project_theme_sector . sector_id ) or ( row . project_theme_sector . sector_id in sector_ids ) ) ] table = s3db . project_theme_project field = table . theme_id field . requires = IS_EMPTY_OR ( IS_ONE_OF ( db , 'project_theme.id' , field . represent , filterby = 'id' , filter_opts = theme_ids , sort = True ) )
filters the theme_id based on the sector_id .