Skip to content

Commit

Permalink
Recent modifications to underlying Representation behavior now reflec…
Browse files Browse the repository at this point in the history
…ted in the Resource.
  • Loading branch information
toastdriven committed Mar 29, 2010
1 parent 9c9d9c3 commit c0453ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
22 changes: 8 additions & 14 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ TODO
To demo-able:
-------------

- Finish the ``ModelRepresentation`` implementation.
- CRUD methods should be simple, relying on data to be pre-populated.
- The ``dehydrate/hydrate`` should be called as soon/late as possible
to make sure the representation is fully populated for serialization.
- ForeignKey/ManyToManyField are do-able, but require either the registry
pattern or overriding the representation. There should also be a way to
control "depth" (if sub-representations are allowed to traverse their
relations).
- Re-integrate the changes from the above into ``Resource``.
- Finish serialization bits.
- Implement the simple case for all.
- Serialize either a list or an object.
- Make sure the representation (specifically the ``dehydrate``) is what is
handed to the serializer, so that more complex things are possible.
- Tests.
- Examples.


Longer-term:
------------

- XML serialization/deserialization is not implemented and needs to be a
high priority.
- ``Resource`` needs to do content-type negotiation on the PUT/POST data.
- Finish the ``ModelRepresentation`` implementation.
- ForeignKey/ManyToManyField are do-able, but require either the registry
pattern or overriding the representation. There should also be a way to
control "depth" (if sub-representations are allowed to traverse their
relations).
- Registry for the full API to make the complete Barkeeper's Friend possible.
- FK/M2M representation fields.
- Authentication
Expand Down
4 changes: 2 additions & 2 deletions tastypie/representations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get(self, **kwargs):

self.full_dehydrate(model)

def create(self, data_dict):
def create(self, data_dict={}):
self.full_hydrate(data_dict)
newbie = self.model()

Expand All @@ -143,7 +143,7 @@ def create(self, data_dict):

newbie.save()

def update(self, **kwargs):
def update(self, data_dict={}, **kwargs):
try:
model = self.queryset.get(**kwargs)
except ObjectDoesNotExist:
Expand Down
33 changes: 20 additions & 13 deletions tastypie/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,25 @@ def put_list(self, request):
Replaces a collection of resources with another collection.
Return ``HttpAccepted`` (204 No Content).
"""
self.representation.delete()
self.representation.update()
return HttpAccepted()
# self.representation.delete()
# self.representation.update()
# return HttpAccepted()
raise NotImplementedError

def put_detail(self, request, obj_id):
"""
If a new resource is created, return ``HttpCreated`` (201 Created).
If an existing resource is modified, return ``HttpAccepted`` (204 No Content).
"""
# FIXME: Forced for now but needs content-type detection and error-handling.
deserialized = self.serializer.from_json(request.raw_post_data)
representation = self.representation()

try:
# FIXME: Should proxy through the representation?
obj = self.representation.get(obj_id)
resource = self.representation.update(obj)
resource = representation.update(pk=obj_id, data_dict=deserialized)
return HttpAccepted()
except:
resource = self.representation.create(obj)
resource = representation.create(data_dict=deserialized)
# FIXME: Include charset here.
return HttpCreated(location=resource.get_resource_uri())

Expand All @@ -207,8 +210,11 @@ def post_list(self, request):
"""
# TODO: What to do if the resource already exists at that id? Quietly
# update or complain loudly?
results = self.representation.create(obj)
return HttpCreated(location=results.get_resource_uri())
# FIXME: Forced for now but needs content-type detection and error-handling.
deserialized = self.serializer.from_json(request.raw_post_data)
representation = self.representation()
resource = self.representation.create(deserialized)
return HttpCreated(location=resource.get_resource_uri())

def post_detail(self, request, obj_id):
"""
Expand All @@ -225,17 +231,18 @@ def delete_list(self, request):
"""
# TODO: What range ought to be deleted? This seems particularly
# dangerous.
self.representation.delete()
representation = self.representation()
representation.queryset.all().delete()
return HttpAccepted()

def delete_detail(self, request, obj_id):
"""
If the resource is deleted, return ``HttpAccepted`` (204 No Content).
"""
representation = self.representation()

try:
# FIXME: Should proxy through the representation?
obj = self.representation.get(obj_id)
self.representation.delete(obj)
representation.delete(pk=obj_id)
return HttpAccepted()
except:
return HttpGone()

0 comments on commit c0453ba

Please sign in to comment.