<s> """<STR_LIT>""" <EOL> from competencies . models import Organization <EOL> def cascade_visibility_down ( element , visibility_mode ) : <EOL> """<STR_LIT>""" <EOL> links = [ rel . get_accessor_name ( ) for rel in element . _meta . get_all_related_objects ( ) ] <EOL> for link in links : <EOL> objects = getattr ( element , link ) . all ( ) <EOL> for object in objects : <EOL> try : <EOL> if visibility_mode == '<STR_LIT>' : <EOL> if object . public : <EOL> object . public = False <EOL> object . save ( ) <EOL> elif visibility_mode == '<STR_LIT>' : <EOL> if not object . public : <EOL> object . public = True <EOL> object . save ( ) <EOL> except Exception as e : <EOL> pass <EOL> if object . _meta . get_all_related_objects ( ) : <EOL> cascade_visibility_down ( object , visibility_mode ) <EOL> def cascade_public_up ( element ) : <EOL> """<STR_LIT>""" <EOL> element = element . get_parent ( ) <EOL> while element . __class__ != Organization : <EOL> if not element . public : <EOL> element . public = True <EOL> element . save ( ) <EOL> element = element . get_parent ( ) <EOL> def fork_organization ( forking_org , original_org ) : <EOL> """<STR_LIT>""" <EOL> if not original_org . public : <EOL> return None <EOL> if forking_org . subjectarea_set . all ( ) : <EOL> return None <EOL> if original_org == forking_org : <EOL> return None <EOL> from copy import deepcopy <EOL> for sa in original_org . subjectarea_set . filter ( public = True ) : <EOL> original_sa = deepcopy ( sa ) <EOL> sa . pk = None <EOL> sa . organization = forking_org <EOL> sa . public = forking_org . public <EOL> sa . save ( ) <EOL> for sda in original_sa . subdisciplinearea_set . filter ( public = True ) : <EOL> original_sda = deepcopy ( sda ) <EOL> sda . pk = None <EOL> sda . subject_area = sa <EOL> sda . public = forking_org . public <EOL> sda . save ( ) <EOL> for ca in original_sda . competencyarea_set . filter ( public = True ) : <EOL> original_ca = deepcopy ( ca ) <EOL> ca . pk = None <EOL> ca . subject_area = sa <EOL> ca . subdiscipline_area = sda <EOL> ca . public = forking_org . public <EOL> ca . save ( ) <EOL> for eu in original_ca . essentialunderstanding_set . filter ( public = True ) : <EOL> eu . pk = None <EOL> eu . competency_area = ca <EOL> eu . public = forking_org . public <EOL> eu . save ( ) <EOL> for ca in original_sa . competencyarea_set . filter ( public = True , subdiscipline_area = None ) : <EOL> original_ca = deepcopy ( ca ) <EOL> ca . pk = None <EOL> ca . subject_area = sa <EOL> ca . public = forking_org . public <EOL> ca . save ( ) <EOL> for eu in original_ca . essentialunderstanding_set . filter ( public = True ) : <EOL> eu . pk = None <EOL> eu . competency_area = ca <EOL> eu . public = forking_org . public <EOL> eu . save ( ) </s>
