When fields are specified with [~fieldname] syntax, where *fieldname* is the Python name of a field, *fieldname* will be substituted for the MongoDB name of the field (specified using the :attr:`name` keyword argument in a field's constructor).
(self, code)
| 1992 | return tuple(data) |
| 1993 | |
| 1994 | def _sub_js_fields(self, code): |
| 1995 | """When fields are specified with [~fieldname] syntax, where |
| 1996 | *fieldname* is the Python name of a field, *fieldname* will be |
| 1997 | substituted for the MongoDB name of the field (specified using the |
| 1998 | :attr:`name` keyword argument in a field's constructor). |
| 1999 | """ |
| 2000 | |
| 2001 | def field_sub(match): |
| 2002 | # Extract just the field name, and look up the field objects |
| 2003 | field_name = match.group(1).split(".") |
| 2004 | fields = self._document._lookup_field(field_name) |
| 2005 | # Substitute the correct name for the field into the javascript |
| 2006 | return '["%s"]' % fields[-1].db_field |
| 2007 | |
| 2008 | def field_path_sub(match): |
| 2009 | # Extract just the field name, and look up the field objects |
| 2010 | field_name = match.group(1).split(".") |
| 2011 | fields = self._document._lookup_field(field_name) |
| 2012 | # Substitute the correct name for the field into the javascript |
| 2013 | return ".".join([f.db_field for f in fields]) |
| 2014 | |
| 2015 | code = re.sub(r"\[\s*~([A-z_][A-z_0-9.]+?)\s*\]", field_sub, code) |
| 2016 | code = re.sub(r"\{\{\s*~([A-z_][A-z_0-9.]+?)\s*\}\}", field_path_sub, code) |
| 2017 | return code |
| 2018 | |
| 2019 | def _chainable_method(self, method_name, val): |
| 2020 | """Call a particular method on the PyMongo cursor call a particular chainable method |
no outgoing calls