(self, location, commit=True)
Set the primary location, and all important user data, for
        the user.

        :param location: may be a sql or couch location
Set the primary location, and all important user data, for
        the user.
Set the primary location and all important user data for the user .
def set_location(self, location, commit=True):
        """
        Set the primary location, and all important user data, for
        the user.

        :param location: may be a sql or couch location
        """
        from corehq.apps.fixtures.models import UserFixtureType

        if not location.location_id:
            raise AssertionError("You can't set an unsaved location")

        self.update_metadata({'commcare_location_id': location.location_id})

        if not location.location_type_object.administrative:
            # just need to trigger a get or create to make sure
            # this exists, otherwise things blow up
            sp = SupplyInterface(self.domain).get_or_create_by_location(location)

            self.update_metadata({
                'commtrack-supply-point': sp.case_id
            })

        self.create_location_delegates([location])

        self.update_metadata({
            'commcare_primary_case_sharing_id':
            location.location_id
        })

        self.update_fixture_status(UserFixtureType.LOCATION)
        self.location_id = location.location_id
        self.get_domain_membership(self.domain).location_id = location.location_id
        if self.location_id not in self.assigned_location_ids:
            self.assigned_location_ids.append(self.location_id)
            self.get_domain_membership(self.domain).assigned_location_ids.append(self.location_id)
            self.update_metadata({'commcare_location_ids': user_location_data(self.assigned_location_ids)})
        self.get_sql_location.reset_cache(self)
        if commit:
            self.save()
def set_location ( self , location , commit = True ) : from corehq . apps . fixtures . models import UserFixtureType if not location . location_id : raise AssertionError ( "You can't set an unsaved location" ) self . update_metadata ( { 'commcare_location_id' : location . location_id } ) if not location . location_type_object . administrative : # just need to trigger a get or create to make sure # this exists, otherwise things blow up sp = SupplyInterface ( self . domain ) . get_or_create_by_location ( location ) self . update_metadata ( { 'commtrack-supply-point' : sp . case_id } ) self . create_location_delegates ( [ location ] ) self . update_metadata ( { 'commcare_primary_case_sharing_id' : location . location_id } ) self . update_fixture_status ( UserFixtureType . LOCATION ) self . location_id = location . location_id self . get_domain_membership ( self . domain ) . location_id = location . location_id if self . location_id not in self . assigned_location_ids : self . assigned_location_ids . append ( self . location_id ) self . get_domain_membership ( self . domain ) . assigned_location_ids . append ( self . location_id ) self . update_metadata ( { 'commcare_location_ids' : user_location_data ( self . assigned_location_ids ) } ) self . get_sql_location . reset_cache ( self ) if commit : self . save ( )