Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use `pk` as index everywhere.

  • Loading branch information...
commit be9a5451bbe3b714a80be473c5875a74c328b942 1 parent d6d20f0
Mitar mitar authored
Showing with 10 additions and 15 deletions.
  1. +10 −15 tastypie_mongoengine/resources.py
25 tastypie_mongoengine/resources.py
View
@@ -20,14 +20,6 @@ class ListQuerySet(list):
def filter(self, **kwargs):
result = self
- if 'index' in kwargs:
- index = kwargs.pop('index')
- try:
- # index can be always converted to int because of the matching regex
- result = [result[int(index)]]
- except IndexError:
- result = []
-
for field, value in kwargs.items():
if '__' in field:
# TODO: Implement
@@ -463,10 +455,6 @@ def __init__(self, parent=None, attribute=None, api_name=None):
def _safe_get(self, request, **kwargs):
filters = self.remove_api_resource_names(kwargs)
- try:
- del(filters['index'])
- except KeyError:
- pass
try:
return self.parent.cached_obj_get(request=request, **filters)
@@ -474,14 +462,21 @@ def _safe_get(self, request, **kwargs):
raise tastypie_exceptions.ImmediateHttpResponse(response=http.HttpNotFound())
def dispatch(self, request_type, request, **kwargs):
+ index = None
+ if 'index' in kwargs:
+ index = kwargs.pop('index')
+
self.instance = self._safe_get(request, **kwargs)
+ # We use pk as index from now on
+ kwargs['pk'] = index
+
return super(MongoEngineListResource, self).dispatch(request_type, request, **kwargs)
def remove_api_resource_names(self, url_dict):
kwargs_subset = super(MongoEngineListResource, self).remove_api_resource_names(url_dict)
- for key in ['subresource_name', 'pk']:
+ for key in ['subresource_name']:
try:
del(kwargs_subset[key])
except KeyError:
@@ -506,7 +501,7 @@ def get_object_list(self, request):
return ListQuerySet()
def add_index(index, obj):
- obj.pk = index
+ obj.pk = unicode(index)
return obj
return ListQuerySet([add_index(index, obj) for index, obj in enumerate(getattr(self.instance, self.attribute))])
@@ -542,7 +537,7 @@ def obj_update(self, bundle, request=None, **kwargs):
bundle = self.full_hydrate(bundle)
object_list = getattr(self.instance, self.attribute)
- object_list[bundle.obj.pk] = bundle.obj
+ object_list[int(bundle.obj.pk)] = bundle.obj
self.save_related(bundle)
Please sign in to comment.
Something went wrong with that request. Please try again.