def construct_create_update_request(resource): schema = {} for name, field in resource.filter_schema(exclusive=False, readonly=False).iteritems(): if field.required: field = field.clone(required=False) schema[name] = field schema = Sequence(Structure(schema)) response_schema = Sequence(Structure({ resource.id_field.name: resource.id_field.clone(required=True), })) return Request( name = 'create_update', endpoint = (PUT, resource.name), specific = False, auto_constructed = True, resource = resource, title = 'Creating and updating multiple %s' % pluralize(resource.title.lower()), schema = schema, responses = { OK: Response(response_schema), INVALID: Response(Errors), } )
def construct_create_update_request(resource): schema = {} for name, field in resource.filter_schema(exclusive=False, readonly=False).iteritems(): if field.required: field = field.clone(required=False) schema[name] = field schema = Sequence(Structure(schema)) response_schema = Sequence( Structure({ resource.id_field.name: resource.id_field.clone(required=True), })) return Request(name='create_update', endpoint=(PUT, resource.name), specific=False, auto_constructed=True, resource=resource, title='Creating and updating multiple %s' % pluralize(resource.title.lower()), schema=schema, responses={ OK: Response(response_schema), INVALID: Response(Errors), })
def construct_load_request(resource, declaration=None): fields = filter_schema_for_response(resource) response_schema = Sequence(Structure(fields), nonnull=True) schema = { 'fields': construct_fields_field(fields), 'identifiers': Sequence(resource.id_field.clone(), nonempty=True), } include_field = construct_include_field(fields) if include_field: schema['include'] = include_field return Request( name = 'load', endpoint = (LOAD, resource.name), auto_constructed = True, resource = resource, title = 'Loading %s' % pluralize(resource.title.lower()), schema = Structure(schema), responses = { OK: Response(response_schema), INVALID: Response(Errors), } )
def __call__(self, resource): fields = filter_schema_for_response(resource) schema = { 'offset': Integer(minimum=0, default=0, description='The offset into the result set of this query.'), 'limit': Integer(minimum=0, description='The maximum number of resources to return for this query.'), 'total': Boolean(default=False, nonnull=True, description='If true, only return the total for this query.'), } include_field = self._construct_include_field(fields) if include_field: schema['include'] = include_field exclude_field = self._construct_exclude_field(resource.id_field, fields) if exclude_field: schema['exclude'] = exclude_field sort_field = self._construct_sort_field(fields) if sort_field: schema['sort'] = sort_field operators = {} for name, field in fields.iteritems(): if field.operators: self._construct_operator_fields(operators, field) if operators: schema['query'] = Structure(operators, description='The query to filter resources by.') response_schema = Structure({ 'total': Integer(nonnull=True, minimum=0, description='The total number of resources in the result set for this query.'), 'resources': Sequence(Structure(fields), nonnull=True), }) return Request( name = 'query', endpoint = (GET, resource.name), auto_constructed = True, resource = resource, title = 'Querying %s' % pluralize(resource.title.lower()), schema = Structure(schema), responses = { OK: Response(response_schema), INVALID: Response(Errors), } )
def construct_load_request(resource, declaration=None): fields = filter_schema_for_response(resource) response_schema = Sequence(Structure(fields), nonnull=True) schema = { 'fields': construct_fields_field(fields), 'identifiers': Sequence(resource.id_field.clone(), nonempty=True), } include_field = construct_include_field(fields) if include_field: schema['include'] = include_field return Request(name='load', endpoint=(LOAD, resource.name), auto_constructed=True, resource=resource, title='Loading %s' % pluralize(resource.title.lower()), schema=Structure(schema), responses={ OK: Response(response_schema), INVALID: Response(Errors), })
def __call__(self, resource): fields = filter_schema_for_response(resource) schema = { 'offset': Integer( minimum=0, default=0, description='The offset into the result set of this query.'), 'limit': Integer( minimum=0, description= 'The maximum number of resources to return for this query.'), 'total': Boolean( default=False, nonnull=True, description='If true, only return the total for this query.'), } include_field = self._construct_include_field(fields) if include_field: schema['include'] = include_field exclude_field = self._construct_exclude_field(resource.id_field, fields) if exclude_field: schema['exclude'] = exclude_field sort_field = self._construct_sort_field(fields) if sort_field: schema['sort'] = sort_field operators = {} for name, field in fields.iteritems(): if field.operators: operator_field = self._construct_operator_field(field) if operator_field: operators[name] = operator_field if operators: schema['query'] = Structure( operators, description='The query to filter resources by.') response_schema = Structure({ 'total': Integer( nonnull=True, minimum=0, description= 'The total number of resources in the result set for this query.' ), 'resources': Sequence(Structure(fields), nonnull=True), }) return Request(name='query', endpoint=(GET, resource.name), auto_constructed=True, resource=resource, title='Querying %s' % pluralize(resource.title.lower()), schema=Structure(schema), responses={ OK: Response(response_schema), INVALID: Response(Errors), })
def construct_query_request(resource, declaration=None): fields = filter_schema_for_response(resource) schema = { 'fields': construct_fields_field(fields), 'limit': Integer(minimum=0, description= 'The maximum number of resources to return for this query.'), 'offset': Integer(minimum=0, default=0, description='The offset into the result set of this query.'), 'total': Boolean(default=False, nonnull=True, description='If true, only return the total for this query.'), } include_field = construct_include_field(fields) if include_field: schema['include'] = include_field exclude_field = construct_exclude_field(resource.id_field, fields) if exclude_field: schema['exclude'] = exclude_field tokens = [] for name, field in fields.iteritems(): if field.sortable: for suffix in ('', '+', '-'): tokens.append(name + suffix) if tokens: schema['sort'] = Sequence(Enumeration(sorted(tokens), nonnull=True), description='The sort order for this query.') operators = {} for name, field in fields.iteritems(): if field.operators: OperatorConstructor.construct(operators, field) if declaration: additions = getattr(declaration, 'operators', None) if additions: operators.update(additions) if operators: schema['query'] = Structure( operators, description='The query to filter resources by.') response_schema = Structure({ 'total': Integer( nonnull=True, minimum=0, description= 'The total number of resources in the result set for this query.'), 'resources': Sequence(Structure(fields), nonnull=True), }) valid_responses = [OK] if declaration: valid_responses = getattr(declaration, 'valid_responses', valid_responses) responses = {INVALID: Response(Errors)} for response_code in valid_responses: responses[response_code] = Response(response_schema) return Request( name='query', endpoint=(GET, resource.name), auto_constructed=True, resource=resource, title='Querying %s' % pluralize(resource.title.lower()), schema=Structure(schema), responses=responses, )
def construct_query_request(resource, declaration=None): fields = filter_schema_for_response(resource) schema = { 'fields': construct_fields_field(fields), 'limit': Integer(minimum=0, description='The maximum number of resources to return for this query.'), 'offset': Integer(minimum=0, default=0, description='The offset into the result set of this query.'), 'total': Boolean(default=False, nonnull=True, description='If true, only return the total for this query.'), } include_field = construct_include_field(fields) if include_field: schema['include'] = include_field exclude_field = construct_exclude_field(resource.id_field, fields) if exclude_field: schema['exclude'] = exclude_field tokens = [] for name, field in fields.iteritems(): if field.sortable: for suffix in ('', '+', '-'): tokens.append(name + suffix) if tokens: schema['sort'] = Sequence(Enumeration(sorted(tokens), nonnull=True), description='The sort order for this query.') operators = {} for name, field in fields.iteritems(): if field.operators: OperatorConstructor.construct(operators, field) if declaration: additions = getattr(declaration, 'operators', None) if additions: operators.update(additions) if operators: schema['query'] = Structure(operators, description='The query to filter resources by.') response_schema = Structure({ 'total': Integer(nonnull=True, minimum=0, description='The total number of resources in the result set for this query.'), 'resources': Sequence(Structure(fields), nonnull=True), }) valid_responses = [OK] if declaration: valid_responses = getattr(declaration, 'valid_responses', valid_responses) responses = {INVALID: Response(Errors)} for response_code in valid_responses: responses[response_code] = Response(response_schema) return Request( name = 'query', endpoint = (GET, resource.name), auto_constructed = True, resource = resource, title = 'Querying %s' % pluralize(resource.title.lower()), schema = Structure(schema), responses = responses, )