Coder Social home page Coder Social logo

django-conduit's People

Contributors

akoumjian avatar blturner avatar keppy avatar ranchodeluxe 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-conduit's Issues

python setup.py install issue || management command issue

I'm not entirely sure where the issue is here, so correct me if I'm off:

When cloning this project and running python setup.py install I expect that the .egg file and source code will be copied for the build to the correct virtualvenv /lib/python<version/site-packages directory. The .egg file is copied, but the source code is not ( see listing below ).

I ran into this problem when i was trying to figure out why after running setup.py the create_api command was not showing up in python manage ---help options. To resolve it i just used django-conduit as a local ( non-site-package ) django app.

Adding django-conduit 0.1.0-beta to easy-install.pth file
Saving /usr/local/src/conduit_example/avenv/lib/python2.7/site-packages/easy-install.pth

Installed /usr/local/src/conduit_example/avenv/lib/python2.7/site-packages/django_conduit-0.1.0_beta-py2.7.egg
Processing dependencies for django-conduit==0.1.0-beta
Searching for python-dateutil==2.1
Best match: python-dateutil 2.1
Adding python-dateutil 2.1 to easy-install.pth file

Using /usr/local/src/conduit_example/avenv/lib/python2.7/site-packages
Searching for six==1.3.0
Best match: six 1.3.0
Adding six 1.3.0 to easy-install.pth file

Using /usr/local/src/conduit_example/avenv/lib/python2.7/site-packages
Finished processing dependencies for django-conduit==0.1.0-beta

update_objs_from_data does not use pk_field override from resource metaclass

This issue seems to be related to #9 but was not caught.

Problem:
Assuming i have the following resource with a pk_field override and unique IDs for that field:

class FooResource(ModelResource):
    class Meta(ModelResource.Meta):
        model = Foo
        pk_field = 'name' 
    class Fields:
        bar = ForeignKeyField(attribute='bar', resource_cls=BarResource, embed=False)
        bazzes = ManyToManyField(attribute='bazzes', resource_cls=BazResource, embed=False)

Then I should be able to PUT new data against that detailed view, this curl however generates the following error:

curl -X PUT -H "Content-Type: application/json" -d '{"float_field": 99999.123456789, "bar": "/api/v1/bar/1/", "name": "264b8e4b", "created": "2013-06-21T01:44:57.367956+00:00", "text":"WhoooHoooo, update_objs_from_data works!", "decimal": "110.12", "birthday": "2013-06-19", "boolean": false, "bazzes": ["/api/v1/baz/1/", "/api/v1/baz/198/"], "integer": 12, "file_field": "test/test.txt"}' http://localhost:9999/api/v1/foo/264b8e4b/


Internal Server Error: /api/v1/foo/264b8e4b/
Traceback (most recent call last):
  File "/usr/local/src/conduit_contrib/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/src/conduit_contrib/conduit/base.py", line 35, in view
    (request, args, kwargs,) = method(self, request, *args, **kwargs)
  File "/usr/local/src/conduit_contrib/conduit/subscribe.py", line 15, in returned_wrapper
    return func(self, request, *args, **kwargs)
  File "/usr/local/src/conduit_contrib/conduit/api/base.py", line 639, in update_objs_from_data
    bundle['obj'] = self.Meta.model.objects.get(**{self.Meta.pk_field: obj.pk})
  File "/usr/local/src/conduit_contrib/venv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 143, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/usr/local/src/conduit_contrib/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 389, in get
    (self.model._meta.object_name, kwargs))

The issue is the same as it was in #9 just in a different method:
https://github.com/akoumjian/django-conduit/blob/master/conduit/api/base.py#L625

AutoModelResource has no 'Fields' attribute

Looks like a consequence of this addition:

https://github.com/akoumjian/django-conduit/blob/master/conduit/api/utils.py#L32-L36

is that now all requests work on an instance of AutoModelResource. And since our AutoModelResource has taken the place of the ModelResouce sublcass, we don't have access to attributes like 'Fields' anymore. This function returns empty explicit fields:

https://github.com/akoumjian/django-conduit/blob/master/conduit/api/base.py#L103

I'm surprised more didn't break with this change, but maybe i'm misunderstanding something.

One potential solution ( though a magic one ) is to make AutoModelResource sublcass the explicit ModelResource sublcasses. The code below works but relies on imports, naming conventions and knowing what mods the resource sublcasses are stored in:

    def _get_explicit_model_resource( self, model ):
        ''' 
        with some magic naming assumptions:
        1) views are always in a file called 'views.py' # bad assumption
        2) all model resources are named as class in the views as '<ModelName>Resource' # bad assumption
        '''
        try:
            module_magic_name = 'example.views'
            resource_magic_name = '%sResource'  % model.__name__
            _temp = __import__( module_magic_name, fromlist=[ resource_magic_name, ] ) 
            return _temp.__getattribute__( resource_magic_name )
        except ImportError, e:
            logger.error( "ModelResource = %s not found" % resource_magic_name )
            return None

    def _gen_resource(self, model):
        explicit_model_resource = self._get_explicit_model_resource( model ) 
        class AutoModelResource( explicit_model_resource ):
            class Meta( explicit_model_resource.Meta ):
                pass
        #AutoModelResource.Meta.model = model
        return AutoModelResource

Add Documentation for common Use Cases

  1. Add Quick Start to github README
  2. Add HowTos for Common Use Cases & Problems
    • API Throttling (new middleware?)
    • Authentication via key vs oauth vs cookies vs basic auth
  3. HowTo Debug with Conduit
  4. How to handle CSRF for spa / ajax

pip install not finding django-conduit distributions

I'm using virtualvenv on Ubuntu 12.10 ( Python 2.7 ) and CentOS 6.4 ( Python 2.6 ). In both cases running pip install -v django-conduit gives a similar error about not finding it:

(venv)gcorradini@twinkie:$ pip install -v django-conduit
...
Downloading/unpacking django-conduit
  Could not find any downloads that satisfy the requirement django-conduit
No distributions at all found for django-conduit
Exception information:
Traceback (most recent call last):
  File "/usr/local/src/conduit_example/avenv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 104, in main
    status = self.run(options, args)
  File "/usr/local/src/conduit_example/avenv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/commands/install.py", line 245, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/local/src/conduit_example/avenv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/req.py", line 978, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/usr/local/src/conduit_example/avenv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg/pip/index.py", line 157, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for django-conduit

Storing complete log in /home/gcorradini/.pip/pip.log

Update PyPI with newer release

Tried playing around with conduit tonight using the install instructions from https://django-conduit.readthedocs.org/en/latest/#getting-started The tagged 0.1.0 release doesn't include the management directory when it's installed so management commands aren't available after installing with pip.

It looks like some recent commits fix this problem in setup.py so just updating the package index ought to fix this for anyone who wants to try out conduit using:

pip install django-conduit

๐Ÿ˜ฆ ๐Ÿผ

POST(ing) empty related resource_uri with embed=False raises generic error

Problem:
I have related resources on Foo set to use embed=False like below

class FooResource(ModelResource):
    class Meta(ModelResource.Meta):
        model = Foo 
    class Fields:
        bar = ForeignKeyField(attribute='bar', resource_cls=BarResource)
        bazzes = ManyToManyField(attribute='bazzes', resource_cls=BazResource)

If i POST to /api/v1/foo/ with a new object that does not have a related resource_uri specified ( below example leaves bar resource_uri blank ) I get the generic and unfriendly Django 404 html response for /api/v1/foo/.

curl -X POST -H "Content-Type: application/json" -d '{"float_field": 99999.123456789, "bar": "", "name": "TEST_RELATED", "created": "2013-06-21T01:44:57.367956+00:00", "text":      "Testing      relates saves", "decimal": "110.12", "birthday": "2013-06-19", "boolean": false, "bazzes": ["/api/v1/baz/1/", "/api/v1/baz/198/"], "integer": 12, "file_field": "test/test.txt"}' http://localhost:9999/api/v1/foo/

It would be nice to get an error that is more specifc error.

The problem seems to be Resolver404 is not caught at all:
https://github.com/akoumjian/django-conduit/blob/master/conduit/api/fields.py#L105

POST should allow omitting non-required fields

We discussed this and decided Conduit should be as flexibile as possible regarding creating resources that have non-required fields. When making a POST request, the payload will not require null values to be present.

Exploratory work is started in #36

pk_field(s) in resource metaclass still output default pk_field resource_uri

Problem:
Changing the pk_field in class Meta for a resource still dumps default ( id ) resource_uri. In example below i made names unique on Foo objects, but resource_uri is wrong:

class FooResource(ModelResource):
    class Meta(ModelResource.Meta):
        model = Foo 
        pk_field = 'name' 
    class Fields:
        bar = ForeignKeyField(attribute='bar', resource_cls=BarResource, embed=True)
        bazzes = ManyToManyField(attribute='bazzes', resource_cls=BazResource, embed=True)
{
   "float_field":100000.123456789,
   "bar":{
      "resource_uri":"/api/v1/bar/3/",
      "id":3,
      "name":""
   },
   "name":"d9bdd5f45",
   "created":"2013-06-21T01:44:57.367956+00:00",
   "text":"My foo text g     oes here",
   "decimal":"110.12",
   "birthday":"2013-06-19",
   "id":1,
   "boolean":false,
   "bazzes":[
      {
         "resource_uri":"/api/v1/baz/1/",
         "id":1,
         "name":"3"
      },
      {
         "resource_uri":"/api/v1/baz/198/",
         "id":198,
         "name":"Complete New Baz"
      }
   ],
   "integer":12,
   "file_field":"test/test.txt",
   "resource_uri":"/api/v1/foo/1/"
}

Problem code:
https://github.com/akoumjian/django-conduit/blob/master/conduit/api/base.py#L94

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.