Permalink
Browse files

Simple filtering feature added

  • Loading branch information...
1 parent 6af3d6f commit e21b99eb8533929085bc989bd3d39f4b31e6fa09 @mesuutt mesuutt committed Dec 11, 2013
Showing with 19 additions and 3 deletions.
  1. +19 −3 tastypie_mongodb/resources.py
@@ -21,13 +21,29 @@ def get_collection(self):
raise NotImplementedError("You should implement get_collection method.")
def get_object_list(self, request):
- return self.obj_get_list(request)
+ bundle = self.build_bundle(request=request)
+ return self.obj_get_list(bundle)
- def obj_get_list(self, request=None, **kwargs):
+ def obj_get_list(self, bundle, **kwargs):
"""
Maps mongodb documents to Document class.
"""
- return list(map(self.get_object_class(), self.get_collection().find()))
+ filters = {}
+
+ if hasattr(bundle.request, 'GET'):
+ filters = bundle.request.GET.copy()
+
+ # Update with the provided kwargs.
+ filters.update(kwargs)
+ applicable_filters = self.build_filters(filters=filters)
+
+ return self.apply_filters(bundle.request, applicable_filters)
+
+ def apply_filters(self, request, applicable_filters):
+ return list(map(self.get_object_class(), self.get_collection().find(applicable_filters)))
+
+ def build_filters(self, filters=None):
+ return filters
def obj_get(self, request=None, **kwargs):
"""

0 comments on commit e21b99e

Please sign in to comment.