Git Product home page Git Product logo

nap's People

Contributors

fcurella avatar jacobb avatar matteius avatar mcordes avatar neruson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nap's Issues

"No theme named 'flask' found" when building docs

$ 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

current handling of Meta/options is icky.

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.

Overview

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...

Example

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": ""}

Example resources

class PersonAddressResource(ResourceModel):
""" A person address - boilerplate to make the example work """

... a bunch of address fields

How to cause the error

class PersonResource(ResourceModel):
""" A person """
# ... other fields

address = fields.ResourceField(PersonAddressResource)   # incorrect - I actually need a list

How to fix the error

class PersonResource(ResourceModel):
""" A person """
# ... other fields

address = fields.ListField(PersonAddressResource)   # correct definition

`_full_url` breaks URL params in `save`

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

Error when update returns 204

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.

POST request issued on update.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.