Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@view(renderer='json', accept=_accept)
def get(self):
return FRUITS.get(int(self.request.matchdict['id']))
@view(renderer='json', accept='text/json')
def collection_post(self):
return {'test': 'yeah'}
@view()
def collection_post(self):
"""
Create a new model with default settings.
"""
model = self.settings.Model.create()
self.request.session[self.settings['model_session_key']] = model.id
return schema.ModelSchema().bind().serialize(model.to_dict())
@view(validators=util.valid_model_id,
schema=schema.RandomMoverSchema)
def collection_post(self):
"""
Create a :class:`model_manager.WebRandomMover` from a JSON
representation.
"""
data = self.request.validated
model = data.pop('model')
mover = WebRandomMover(**data)
model.movers.add(mover)
mover_data = mover.to_dict(do='create')
return schema.RandomMoverSchema().bind().serialize(mover_data)
@view(validators=[has_provider_id], schema=EventCollectionSchema,
content_type=CONTENT_TYPES)
def put(self):
return ResourceMixin.put(self)
def __new__(mcs, name, bases, dct):
schema = dct.get('schema')
validators = dct.get('validators', {})
for method in ('post', 'put'):
if method in dct:
continue
try:
_validators = validators.get(method, None)
except AttributeError:
_validators = validators
view_fn = lambda request: {'valid': True}
if _validators:
_view = view(schema=schema, validators=_validators)(view_fn)
else:
_view = view(schema=schema)(view_fn)
dct[method] = _view
return super(ResourceValidatorMetaclass, mcs).__new__(
mcs, name, bases, dct)
@view(permission = 'node_access')
def delete(self):
openwrt = get_node_by_request(self.request)
if openwrt:
DBSession.delete(openwrt)
return True
else:
return False
@resource.view(permission='readwrite')
def collection_post(self, *args, **kwargs):
try:
return super(Article, self).collection_post(*args, **kwargs)
except httpexceptions.HTTPConflict as e:
self.request.response.status_code = 200
return e.existing
@view(renderer='json')
def collection_get(self):
"""Tenders List
Get Tenders List
----------------
Example request to get tenders list:
.. sourcecode:: http
GET /tenders HTTP/1.1
Host: example.com
Accept: application/json
This is what one should expect in response:
@view(renderer='json')
def get(self):
models = self.get_repo_models()
uuid = self.request.matchdict['uuid']
try:
page = models.GitPageModel.get(uuid)
return page.to_dict()
except DoesNotExist:
self.request.errors.add('api', 'DoesNotExist', 'Page not found.')
return