Example #1
0
    def validate(self):
        if len(self.value) != self.length:
            raise exceptions.ValidationError('length mismatch in {}'.format(
                self.__class__.__name__))

        if self.valid_values:
            if self.value not in self.valid_values:
                raise exceptions.ValidationError('invalid value in {}'.format(
                    self.__class__.__name__))
Example #2
0
    def render_to_string(self):
        output = ''
        for field in self.fields:
            output += str(field.render_to_string())

        # Check length
        if len(output) != self.length:
            raise exceptions.ValidationError('length mismatch in {}'.format(
                self.__class__.__name__))

        return output