From 71689fcf234ec3cc9349850de4e4afd7af574650 Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Wed, 7 Jul 2010 15:00:46 +0100 Subject: [PATCH] Got within_box working for Geo fields --- docs/changelog.rst | 14 ++++++++++++++ mongoengine/queryset.py | 2 ++ tests/queryset.py | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 479ea21c..6f2d6f1a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,20 @@ Changelog ========= +Changes in v0.4 +=============== +- Added ``SortedListField`` +- Added ``EmailField`` +- Added ``GeoLocationField`` +- Added ``exact`` and ``iexact`` match operators to ``QuerySet`` +- Added ``get_document_or_404`` and ``get_list_or_404`` Django shortcuts +- Fixed bug in Q-objects +- Fixed document inheritance primary key issue +- Base class can now be defined for ``DictField`` +- Fixed MRO error that occured on document inheritance +- Introduced ``min_length`` for ``StringField`` +- Other minor fixes + Changes in v0.3 =============== - Added MapReduce support diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 5a837c4f..4840b537 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -351,6 +351,8 @@ class QuerySet(object): value = {'$within': {'$center': value}} elif op == "near": value = {'$near': value} + elif op == 'within_box': + value = {'$within': {'$box': value}} else: raise NotImplementedError("Geo method '%s' has not " "been implemented" % op) diff --git a/tests/queryset.py b/tests/queryset.py index a7719b88..a84c8c50 100644 --- a/tests/queryset.py +++ b/tests/queryset.py @@ -1232,6 +1232,12 @@ class QuerySetTest(unittest.TestCase): events = events.order_by("-date") self.assertEqual(events.count(), 2) self.assertEqual(events[0], event3) + + # check that within_box works + box = [(35.0, -125.0), (40.0, -100.0)] + events = Event.objects(location__within_box=box) + self.assertEqual(events.count(), 1) + self.assertEqual(events[0].id, event2.id) Event.drop_collection()