<s> import logging <EOL> from django . db . models import CASCADE <EOL> from django . utils import translation <EOL> from freenasUI . system . models import Settings <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> def get_related_objects ( obj ) : <EOL> """<STR_LIT>""" <EOL> reldict = { } <EOL> relnum = <NUM_LIT:0> <EOL> for related in obj . _meta . get_all_related_objects ( ) : <EOL> if related . field . rel . on_delete is not CASCADE : <EOL> continue <EOL> relset = getattr ( obj , related . get_accessor_name ( ) ) <EOL> qs = relset . all ( ) <EOL> count = qs . count ( ) <EOL> if count == <NUM_LIT:0> : <EOL> continue <EOL> relnum += count <EOL> for o in qs : <EOL> _reld , _reln = get_related_objects ( o ) <EOL> for key , val in _reld . items ( ) : <EOL> if key in reldict : <EOL> reldict [ key ] += list ( val ) <EOL> else : <EOL> reldict [ key ] = list ( val ) <EOL> relnum += _reln <EOL> if related . model . _meta . verbose_name in reldict : <EOL> reldict [ related . model . _meta . verbose_name ] += list ( qs ) <EOL> else : <EOL> reldict [ related . model . _meta . verbose_name ] = list ( qs ) <EOL> return reldict , relnum <EOL> def set_language ( ) : <EOL> language = Settings . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . stg_language <EOL> translation . activate ( language ) </s>
