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
def validate_schema(self, value): form = PulpoForm(value) if not form.is_valid(): raise ValidationError(form.errors) if len(value['pages']) != 2: raise ValidationError( "An Inspection schema must have exactly two pages") for p in value['pages']: if len(p['sections']) != 1: raise ValidationError( "An Inspection page must have exactly one section") if len(value['sections'][1]['fields']) == 0: raise ValidationError( "The inspection checklist must contain at least one item") for f in value['sections'][1]['fields']: val = filter( lambda x: (x['id'] == f and x['type'] == 'inspection'), value['fields']) if len(list(val)) == 0: raise ValidationError( "All fields in second page must be of type inspection") return value
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
def validate_schema(self, value): form = PulpoForm(value) if not form.is_valid(): raise ValidationError(form.errors) if len(value['pages']) > 1: raise ValidationError( "A Operations Schema can't have more than one page") for p in value['pages']: if len(p['sections']) != 1: raise ValidationError( "A Operations Schema page must have exactly one section") return value
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_schema(self, value): form = PulpoForm(value) if not form.is_valid(): raise serializers.ValidationError(form.errors) return value