def validate_document(document, request, fields, type_field, valid_type_values, updating): """Checks that all required fields are given. """ document_type = document.get(type_field) if not document_type: # can't do the validation without the type (an error was already added # when validating the Colander schema) return if type_field == 'activities': # for routes the required fields depend on the assigned activities of # a route. but because currently all activities have the same required # fields, we can simply take the required fields of the first # activity. if this is going to change in the future the fields for # activities would have to be taken into account. document_type = document_type[0] if document_type not in valid_type_values: request.errors.add( 'body', type_field, 'invalid value: %s' % document_type) return fields_req = fields.get(document_type)['required'] check_required_fields(document, fields_req, request, updating) check_duplicate_locales(document, request)
def validate_document(document, request, fields, updating): """Checks that all required fields are given. """ check_required_fields(document, fields, request, updating) check_duplicate_locales(document, request)