Created
March 11, 2011 11:12
-
-
Save kosmikko/865753 to your computer and use it in GitHub Desktop.
get app engine Query decoded to string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def show_query(query): | |
| """ | |
| Represent a query as a string | |
| Based on http://kupuguy.googlecode.com/svn/trunk/appengine-doctests/showquery.py | |
| """ | |
| from google.appengine.api import datastore | |
| kind = query._model_class.kind() | |
| ancestor = query._Query__ancestor | |
| filters = query._Query__query_sets[0] | |
| orderings = query._Query__orderings | |
| res = ["%s.all()" % kind] | |
| if ancestor is not None: | |
| res.append("ancestor(%r)" % ancestor) | |
| for k in sorted(filters): | |
| res.append("filter(%r, %r)" % (k, filters[k])) | |
| for p, o in orderings: | |
| if o==datastore.Query.DESCENDING: | |
| p = '-'+p | |
| res.append("order(%r)" % p) | |
| return '.'.join(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment