<s> from corehq . apps . locations . models import Location <EOL> from corehq . apps . users . models import CommCareUser <EOL> from dimagi . utils . couch . database import iter_docs <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> class Command ( BaseCommand ) : <EOL> args = "<STR_LIT>" <EOL> help = "<STR_LIT>" <EOL> def process_user ( self , user ) : <EOL> if user . location_id : <EOL> user . set_location ( Location . get ( user . location_id ) ) <EOL> else : <EOL> user . unset_location ( ) <EOL> def handle ( self , * args , ** options ) : <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> raise CommandError ( "<STR_LIT>" % self . args ) <EOL> domain = args [ <NUM_LIT:0> ] <EOL> ids = ( <EOL> CommCareUser . ids_by_domain ( domain , is_active = True ) + <EOL> CommCareUser . ids_by_domain ( domain , is_active = False ) <EOL> ) <EOL> for doc in iter_docs ( CommCareUser . get_db ( ) , ids ) : <EOL> user = CommCareUser . wrap ( doc ) <EOL> try : <EOL> self . process_user ( user ) <EOL> except Exception as e : <EOL> print "<STR_LIT>" % ( user . _id , e ) </s>
