jacobb / nap Goto Github PK
View Code? Open in Web Editor NEWapi access modeling and tools
api access modeling and tools
$ make html
sphinx-build -b html -d _build/doctrees . _build/html
Making output directory...
Running Sphinx v1.1.3
loading pickled environment... not yet created
Theme error:
no theme named 'flask' found (missing theme.conf?)
make: *** [html] Error 1
Right now, options are passed via a simple inner Class of the ResourceModel declaration, then shoved manually into a dictionary using a whole bunch of getattr()s.
There's probably a much better way both to declare the Meta options and to set them up with sensible defaults.
The error provided, "DataModelMetaClass object argument after ** must be a mapping, not list" coud be more specific.
I was able to cause the following error by incorrectly linking a ResourceField to a ListField. Having an error seems ok, but returning a more clear error would be helpful.
...snip...
File "/Users/jcosta/.virtualenvs/order_service/lib/python2.7/site-packages/nap/resources.py", line 86, in update_fields
value = model_field.scrub_value(field_data[api_name])
File "/Users/jcosta/.virtualenvs/order_service/lib/python2.7/site-packages/nap/fields.py", line 70, in scrub_value
resource = self.coerce(val)
File "/Users/jcosta/.virtualenvs/order_service/lib/python2.7/site-packages/nap/fields.py", line 61, in coerce
return self.resource_model(*val)
TypeError: DataModelMetaClass object argument after * must be a mapping, not list
...snip...
JSON Example - a person can have more than one address, so its stored in a list element
"person": {
"address": [
{"city": "portland", "country_code": null, "fax": "",
"phone": "207-999-9999", "phone_ext": "", "state": "ME",
"street": "street data", "street2": "extended street data", "zip_code":
"04101"}],
"email": "[email protected]", "first_name": "John",
"full_name": "John Costa", "last_name": "Costa", "reference_key": null,
"sms_number": null, "title": ""}
class PersonAddressResource(ResourceModel):
""" A person address - boilerplate to make the example work """
class PersonResource(ResourceModel):
""" A person """
# ... other fields
address = fields.ResourceField(PersonAddressResource) # incorrect - I actually need a list
class PersonResource(ResourceModel):
""" A person """
# ... other fields
address = fields.ListField(PersonAddressResource) # correct definition
Please add support for passing a list as a query string param.
I would like to be able to call a url with the following query string:
http://myurl.com/myresource/?animals=DOGS&animals=CATS&colors=BROWN"
resulting in Querydict() d for which the following would be true.
d.getlist('animals') == ['DOGS,'CATS']
d.getlist('colors') == ['BROWN']
class Fish(ResourceModel):
token = fields.Field(resource_id=True)
I did this in the console and was pleased:
>>> f = Fish(token='t')
>>> f.save(filet=True)
PUT http://localhost:8000/fish/t/?filet=True
Then I did it this way and was confused:
>>> f = Fish.objects.lookup(token='t')
>>> f.save(filet=True)
PUT http://localhost:8000/fish/t/
Notice how the URL param is gone, as if I passed nothing to save()
?
This seems to fix it, but I'd prefer for it to use save
kwargs without having to do this:
>>> f = Fish.objects.lookup(token='t')
>>> del f._full_url
>>> f.save(filet=True)
PUT http://localhost:8000/fish/t/?filet=True
If the API returns a 204 No Content on a successful update, then ResourceModel.save will fail with AttributeError: 'NoneType' object has no attribute '_raw_field_data'
because the returned object is None.
When a Resource has a resource_id
field not named id
, it will issue POST requests instead of PUT when updating the resource.
Example:
#resources.py
class Grain(nap.ResourceModel):
name = nap.Field()
grain_id = nap.Field(api_name='id', resource_id=True)
class Meta:
root_url = '/api/v1/'
resource_name = 'food/grain'
collection_field = 'objects'
object_name = 'grain'
valid_update_status = (200, 201, 204,)
>>> scoop = Grain(name='wheat', grain_id=1)
>>> scoop.save()
>>> # a POST request is issued instead of PUT
GET responses with "Cache-Control: max-age=0" or "Cache-Control: no-cache" still get cached. The problem is in BaseCacheBackend.get_timeout where I believe it ends up using the default_cache values for these.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.