Skip to content

Commit

Permalink
change create/update commands to PUT POST. It is possible to update u…
Browse files Browse the repository at this point in the history
…sing PATCH.
  • Loading branch information
pavlov99 committed Feb 7, 2015
1 parent fca8133 commit 6cd5289
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
10 changes: 1 addition & 9 deletions jsonapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Meta:
import logging
import json

from .utils import Choices
from .model_inspector import ModelInspector

logger = logging.getLogger(__name__)
Expand All @@ -36,12 +35,6 @@ class API(object):

""" API handler."""

HTTP_METHODS = Choices(
('GET', 'get'),
('POST', 'create'),
('PUT', 'update'),
('DELETE', 'delete'),
)
CONTENT_TYPE = "application/vnd.api+json"

def __init__(self):
Expand Down Expand Up @@ -229,8 +222,7 @@ def handler_view(self, request, resource_name, ids=None):
self.update_urls(request, resource_name=resource_name, ids=ids)
resource = self.resource_map[resource_name]

allowed_http_methods = {
getattr(API.HTTP_METHODS, x) for x in resource.Meta.allowed_methods}
allowed_http_methods = resource.Meta.allowed_methods
if request.method not in allowed_http_methods:
return HttpResponseNotAllowed(
permitted_methods=allowed_http_methods)
Expand Down
4 changes: 2 additions & 2 deletions jsonapi/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Meta:
* fieldnames_include = None
* fieldnames_exclude = None
* page_size = None
* allowed_methods = ('get',)
* allowed_methods = ('GET',)
Properties:
Expand Down Expand Up @@ -155,7 +155,7 @@ class Meta:
fieldnames_include = None
fieldnames_exclude = None
page_size = None
allowed_methods = 'get',
allowed_methods = 'GET',

@classproperty
def name_plural(cls):
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Meta:
class AuthorResource(Resource):
class Meta:
model = 'testapp.Author'
allowed_methods = 'get', 'create', 'update', 'delete'
allowed_methods = 'GET', 'POST', 'PUT', 'DELETE'


@api.register
Expand Down

0 comments on commit 6cd5289

Please sign in to comment.