def validate(self, data):
        """Check that the answers are appropiate for the version."""
        if data['status'] != PUBLISHED:
            raise serializers.ValidationError(
                "Can not submit a response for an unpublished version.")

        form = PulpoForm(data['schema'])
        result = form.check_answers(data['response'])
        if result['result'] != 'OK':
            raise serializers.ValidationError(result['errors'])

        return data
    def validate(self, data):
        user = self.context['request'].user
        published_version = WorkOrderSchema.objects.filter(
            form__airport__id=user.aerosimple_user.airport_id,
            status=PUBLISHED).first()

        form = PulpoForm(published_version.schema)
        result = form.check_answers(data['response'])

        if result['result'] != 'OK':
            raise ValidationError(result.errors)

        return data
Example #3
0
    def validate(self, data):
        user = self.context['request'].user
        published_version = AssetVersion.objects.get(
            form__airport__id=user.aerosimple_user.airport_id,
            form__category=data['asset_type'].category,
            status=PUBLISHED)

        form = PulpoForm(published_version.schema)
        answers = data['response']
        result = form.check_answers(answers)

        if result['result'] != 'OK':
            raise ValidationError(result.errors)

        return data
    def validate(self, data):
        user = self.context['request'].user
        if self.instance:
            form = PulpoForm(self.instance.form.schema)
        else:
            published_version = LogVersion.objects.filter(
                form__airport__id=user.aerosimple_user.airport_id,
                status=PUBLISHED).first()
            form = PulpoForm(published_version.schema)
        result = form.check_answers(data['response'])

        if result['result'] != 'OK':
            raise serializers.ValidationError(result['errors'])

        return data