def form_valid(self, form): org = self.request.user.get_org() if not org: # pragma: no cover raise Exception(_("No org for this user, cannot claim")) self.object = Channel.objects.filter( claim_code=self.form.cleaned_data["claim_code"]).first() country = self.object.country phone_country = ContactURN.derive_country_from_tel( self.form.cleaned_data["phone_number"], str(self.object.country)) # always prefer the country of the phone number they are entering if we have one if phone_country and phone_country != country: # pragma: needs cover self.object.country = phone_country analytics.track(self.request.user.username, "temba.channel_create") self.object.claim(org, self.request.user, self.form.cleaned_data["phone_number"]) self.object.save() # trigger a sync self.object.trigger_sync() return super().form_valid(form)
def form_valid(self, form): org = self.request.user.get_org() self.object = Channel.objects.filter( claim_code=self.form.cleaned_data["claim_code"]).first() country = self.object.country phone_country = ContactURN.derive_country_from_tel( self.form.cleaned_data["phone_number"], str(self.object.country)) # always prefer the country of the phone number they are entering if we have one if phone_country and phone_country != country: # pragma: needs cover self.object.country = phone_country self.object.claim(org, self.request.user, self.form.cleaned_data["phone_number"]) self.object.save() # trigger a sync self.object.trigger_sync() return super().form_valid(form)