joestump / django-ajax

A simple framework for creating AJAX endpoints in Django.
http://github.com/joestump/django-ajax
BSD 3-Clause "New" or "Revised" License
260 stars 54 forks source link

Add list as base method and allowed_methods decorator #25

Closed toast38coza closed 11 years ago

toast38coza commented 12 years ago

Hey, me again:

I added list() to the ModelEndpoint base class so that it is now automatically available at:

/ajax/{app}/{model}/list.json

I also added a decorator called allowed_methods which can be used to limit the methods that can be accessed on a ModelEndpoint.

The idea is that you decorate your ModelEndpoint's authenticate model with it.

Something like:

class CategoryEndpoint(ajax.endpoints.ModelEndpoint):

@allowed_methods(['get','list'])
def authenticate(self, request, application, method):        
    return True

    ...

I also updated the README to reflect these changes.

As before .. feel free to use or discard as you like :)

joestump commented 12 years ago

This is a really awesome pull request. If you want to rejigger it a bit, I'm ready to merge. :)

toast38coza commented 12 years ago

Re-jiggering done. Had some questions re: #r488266. Let me know what you think about those, and I will make any appropriate changes, then we should be good to go :).

joestump commented 12 years ago

Shit. I waited far too long to followup on this. To answer your questions:

lgfausak commented 11 years ago

I think the list is a fantastic addition to an already great piece of code. I am new to python, django and github, I don't know what the correct etiquette is for voting for this, or for using it? I have tried the patch provided by toast38coza and it works great for me. It looks like joestump approves as well, is it already part of the master branch? Also, I'd like to use this addition to the code. What's the correct way to do that, from what I can tell I can:

  1. copy the code in to my directory (this is what I did).
  2. fork the code and apply toast38coza's changes to my fork of the master branch.
  3. fork toast38coza's branch (but it seems to be sort of out of date). Anyway, sorry if I'm going about this the wrong way. I'm looking for the correct way to use the changes introduced by toast38coza. Thanks a lot guys, this is a great piece of work.

-g

joestump commented 11 years ago

@toast38coza Any updates on your end? I might give this a shot this weekend on merging things in and refactoring the Meta thing I mentioned.

toast38coza commented 11 years ago

Hey @joestump. My bad .. just noticed that I somehow missed your reply 11 months ago!

No updates this side. Let me know if you you need anything!

lgfausak commented 11 years ago

Hi Toast, I have been using the list method a bit. I had some questions about the 'qual' and 'order' variables. How does that work? The order should result in something like 'order by employee_name ascending, birthdate descending' and the qual needs to be 'birthdate > 'February 21, 2013' and employee_name = 'Toast''. Looking and the qual and order variables I can't see what to pass them to get this sort of query response. Are they documented somewhere?

justinabrahms commented 11 years ago

This has been merged with a few additions. See commit f1d117cf9045cf461e8165fc901bd55dff2f812e for information.