Git Product home page Git Product logo

tastypie-queryset-client's Introduction

Tastypie Queryset Client

Client for Tastypie. Provide operation similar to the Django Model API .

Usage

Get

>>> client = Client("http://api.server.com/your/v1/")
>>> client.your.objects.get(name="your")
<your: {u"id": u"1", u"name": u"your", u"status": u"any"}>

Count

>>> client = Client("http://api.server.com/your/v1/")
>>> client.your.objects.count()
100

Filter

>>> client = Client("http://api.server.com/your/v1/")
>>> client.your.objects.filter(name="your")
<QuerySet <class 'Response'> (3/3)>

Save

>>> client = Client("http://api.server.com/your/v1/")
>>> your = client.your(name="name")
>>> your
<your: {u"name": u"name"}>
>>> your.save()  # save Your object.
>>> your
<your: {u"id": u"2", u"name": u"name"}>

Delete

>>> client = Client("http://api.server.com/your/v1/")
>>> message = client.message(subject="subject delete 1", body="body delete 1")
>>> message.save()
>>> message.id
<message: {u"id": u"1", u"subject": u"subject delete 1", u"body": u"body delete 1"}>
>>> message.delete()  # remove Message object.
>>> try:
>>>     message.id
>>> except AttributeError:
>>>     assert True  # throw AttributeError.

Requirements

Tastypie: Over the 0.9.12-alpha.

Setup

$ pip install tastypie-queryset-client

Documentation

tastypie-queryset-client.readthedocs.org

License

MIT License

tastypie-queryset-client's People

Contributors

ikeikeikeike avatar stringfellow avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

tastypie-queryset-client's Issues

create seems like it shouldn't ever work (and I can't get it to)

the save() method does this:

if hasattr(self, "id"):
    self._client(self.id).put(self._get_fields())  # return bool
else:
    self._setattrs(**self._client.post(self._get_fields()))

See: https://github.com/ikeikeikeike/tastypie-queryset-client/blob/master/queryset_client/client.py#L664

The problem is, that in the TastyPie docs, it says that a create will return a header that shows the new location of the created object. But the code here is expecting some content - there is always a zero response:

http://django-tastypie.readthedocs.org/en/v0.9.11/interacting.html#creating-a-new-resource-post

And slumber does not pass on the response headers, it just clobbers the whole thing and turns it into a string.

So - very likely this should not be expecting a response string at all.

Pagination Performance.

× Multiple iteration.

paginator = Paginator(objects, 100)
for i in paginator.page(1):
    print i

○ Single iteration.

paginator = Paginator(objects, 100)
for i in paginator.page(1).object_list:
    print i

bug: QuerySet Length.

from queryset_client.client import Client
client = Client("http://api.server.com/message/v1/")
message = client.message.objects.all()
print len(message)  # output 0

only

QuerySet.only

save foreignkey

×

inbox_message = client.inbox_message()
inbox_message.message = message.resource_uri
inbox_message.inbox = inbox.resource_uri
inbox_message.save()

inbox_message = client.inbox_message()
inbox_message.message = message
inbox_message.inbox = inbox
inbox_message.save()

Related resources with non-standard names don't work

I have a related attribute on my objects that aren't named according to the related type.

So, suppose I had a BlogResource and a PostResource, my PostResource's name for its parent Blog wasn't simply "blog", but rather, say, "foo". This causes accesses to post.foo to fail due to _model_gen looking up the model_name (which is the attribute name) in the schema.

If this doesn't make sense, I can provide some sample code. I'm just knee deep in debugging something and wanted to make sure I made a note of this before I forgot.

Two Client objects using different api use same model -> raise error

In code i have something like this:

api_priv = Client(settings.API, auth=(username, password))
api_pub = Client(settings.PUBLIC_API)

Both of those API have different models except class Client. With differs with fields and queryset. Both objects have same content in _schema_store field and if one of those load schema other does't do it.( because -> https://github.com/ikeikeikeike/tastypie-queryset-client/blob/master/queryset_client/client.py#L758). Call this code raise error:

api_priv.client.objects.first().private_field
api_pub.client.objects.first().public_field  #  <- raise exception "obj have no attribute public_field"

It's happens because while creating Client obj metaclass set _schema_store on static class field( code -> https://github.com/ikeikeikeike/tastypie-queryset-client/blob/master/queryset_client/client.py#L710)

Possible solution is change ClientMeta that way to create new SchemaStore when obj use different base_url parameter or store some how SchemaStore dict where key is base_url and value schema_store.

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.