Exemple #1
0
    def validate_urns(self, attrs, source):
        # if we have tel URNs, we may need a country to normalize by
        tel_sender = self.org.get_send_channel(TEL_SCHEME)
        country = tel_sender.country if tel_sender else None

        urns = []
        for urn in attrs.get(source, []):
            try:
                parsed = ContactURN.parse_urn(urn)
            except ValueError, e:
                raise ValidationError(e.message)

            norm_scheme, norm_path = ContactURN.normalize_urn(parsed.scheme, parsed.path, country)
            if not ContactURN.validate_urn(norm_scheme, norm_path):
                raise ValidationError("Invalid URN: '%s'" % urn)
            urns.append((norm_scheme, norm_path))
Exemple #2
0
    def validate_urn(self, attrs, source):
        urns = []

        if 'channel' in attrs and attrs['channel']:
            country = attrs['channel'].country

            for urn in attrs.get(source, []):
                parsed = ContactURN.parse_urn(urn)
                norm_scheme, norm_path = ContactURN.normalize_urn(parsed.scheme, parsed.path, country)
                if not ContactURN.validate_urn(norm_scheme, norm_path):
                    raise ValidationError("Invalid URN: '%s'" % urn)
                urns.append((norm_scheme, norm_path))
        else:
            raise ValidationError("You must specify a valid channel")

        attrs['urn'] = urns
        return attrs
    def validate_urn(self, attrs, source):
        urns = []

        if 'channel' in attrs and attrs['channel']:
            country = attrs['channel'].country

            for urn in attrs.get(source, []):
                parsed = ContactURN.parse_urn(urn)
                norm_scheme, norm_path = ContactURN.normalize_urn(parsed.scheme, parsed.path, country)
                if not ContactURN.validate_urn(norm_scheme, norm_path):
                    raise ValidationError("Invalid URN: '%s'" % urn)
                urns.append((norm_scheme, norm_path))
        else:
            raise ValidationError("You must specify a valid channel")

        attrs['urn'] = urns
        return attrs
Exemple #4
0
    def clean(self):
        country = self.org.get_country_code()

        # validate URN fields
        for field_key, value in self.cleaned_data.iteritems():
            if field_key.startswith('__urn__') and value:
                scheme = field_key[7:field_key.rfind('__')]

                norm_scheme, norm_path = ContactURN.normalize_urn(scheme, value, country)
                existing = Contact.from_urn(self.org, norm_scheme, norm_path)

                if existing and existing != self.instance:
                    self._errors[field_key] = _("Used by another contact")
                elif not ContactURN.validate_urn(norm_scheme, norm_path):
                    self._errors[field_key] = _("Invalid format")

        return self.cleaned_data
Exemple #5
0
    def clean(self):
        channel = self.org.get_receive_channel(TEL_SCHEME)
        country = channel.country if channel else None

        # validate URN fields
        for field_key, value in self.cleaned_data.iteritems():
            if field_key.startswith('__urn__') and value:
                scheme = field_key[7:]

                norm_scheme, norm_path = ContactURN.normalize_urn(scheme, value, country)
                existing = Contact.from_urn(self.org, norm_scheme, norm_path)

                if existing and existing != self.instance:
                    self._errors[field_key] = _("Used by another contact")
                elif not ContactURN.validate_urn(norm_scheme, norm_path):
                    self._errors[field_key] = _("Invalid format")

        return self.cleaned_data
    def validate_urns(self, attrs, source):
        urns = []

        # get a channel
        channel = self.org.get_send_channel(TEL_SCHEME)

        if channel:
            for urn in attrs.get(source, []):
                parsed = ContactURN.parse_urn(urn)
                norm_scheme, norm_path = ContactURN.normalize_urn(parsed.scheme, parsed.path, channel.country)
                if not ContactURN.validate_urn(norm_scheme, norm_path):
                    raise ValidationError("Invalid URN: '%s'" % urn)
                urns.append((norm_scheme, norm_path))
        else:
            raise ValidationError("You cannot start flows without at least one phone number configured")

        attrs['urns'] = urns
        return attrs
Exemple #7
0
    def clean(self):
        channel = self.org.get_receive_channel(TEL_SCHEME)
        country = channel.country if channel else None

        # validate URN fields
        for field_key, value in self.cleaned_data.iteritems():
            if field_key.startswith('__urn__') and value:
                scheme = field_key[7:]

                norm_scheme, norm_path = ContactURN.normalize_urn(scheme, value, country)
                existing = Contact.from_urn(self.org, norm_scheme, norm_path)

                if existing and existing != self.instance:
                    self._errors[field_key] = _("Used by another contact")
                elif not ContactURN.validate_urn(norm_scheme, norm_path):
                    self._errors[field_key] = _("Invalid format")

        return self.cleaned_data
Exemple #8
0
    def validate_urns(self, attrs, source):
        urns = None
        request_urns = attrs.get(source, None)

        if request_urns is not None:
            urns = []
            for urn in request_urns:
                try:
                    parsed = ContactURN.parse_urn(urn)
                except ValueError:
                    raise ValidationError("Unable to parse URN: '%s'" % urn)

                norm_scheme, norm_path = ContactURN.normalize_urn(parsed.scheme, parsed.path)

                if not ContactURN.validate_urn(norm_scheme, norm_path):
                    raise ValidationError("Invalid URN: '%s'" % urn)

                urns.append((norm_scheme, norm_path))

        attrs['urns'] = urns
        return attrs
    def validate_urns(self, attrs, source):
        urns = None
        request_urns = attrs.get(source, None)

        if request_urns is not None:
            urns = []
            for urn in request_urns:
                try:
                    parsed = ContactURN.parse_urn(urn)
                except ValueError:
                    raise ValidationError("Unable to parse URN: '%s'" % urn)

                norm_scheme, norm_path = ContactURN.normalize_urn(parsed.scheme, parsed.path)

                if not ContactURN.validate_urn(norm_scheme, norm_path):
                    raise ValidationError("Invalid URN: '%s'" % urn)

                urns.append((norm_scheme, norm_path))

        attrs['urns'] = urns
        return attrs