Make list of properties into 2 things:
        (1) dictionary of { 'aliased-field': 1, ... } for a mongodb query eg. {''}
        (2) dictionary, keyed by aliased field, for display
193539
def _parse_properties(self, properties):
        
        props = {}
        # TODO: clean up prop_dict?
        prop_dict = OrderedDict()
        # We use a dict instead of list to provide for a richer syntax
        for p in properties:
            if p in self.aliases:
                if isinstance(properties, dict):
                    props[self.aliases[p]] = properties[p]
                else:
                    props[self.aliases[p]] = 1
                prop_dict[p] = self.aliases[p].split(".")
            else:
                if isinstance(properties, dict):
                    props[p] = properties[p]
                else:
                    props[p] = 1
                prop_dict[p] = p.split(".")
        # including a lower-level key after a higher level key e.g.:
        # {'output': 1, 'output.crystal': 1} instead of
        # {'output.crystal': 1, 'output': 1}
        # causes mongo to skip the other higher level keys.
        # this is a (sketchy) workaround for that. Note this problem
        # doesn't appear often in python2 because the dictionary ordering
        # is more stable.
        props = OrderedDict(sorted(props.items(), reverse=True))
        return props, prop_dict
835285
def _serialize_model_helper(self, model, field_dict=None):
        
        field_dict = field_dict or self.dot_field_list_to_dict()
        if model is None:
            return None

        if isinstance(model, Query):
            model = model.all()

        if isinstance(model, (list, set)):
            return [self.serialize_model(m, field_dict=field_dict) for m in model]

        model_dict = {}
        for name, sub in six.iteritems(field_dict):
            value = getattr(model, name)
            if sub:
                value = self.serialize_model(value, field_dict=sub)
            model_dict[name] = value
        return model_dict
604153
def model_to_dict(instance, **options):
    ""

    options = _defaults(options)
    attrs = {}

    if options['prehook']:
        if isinstance(options['prehook'], collections.Callable):
            instance = options['prehook'](instance)
            if instance is None:
                return attrs

    # Items in the `fields` list are the output aliases, not the raw
    # accessors (field, method, property names)
    for alias in options['fields']:

        # Get the accessor for the object
        accessor = options['aliases'].get(alias, alias)

        # Create the key that will be used in the output dict
        key = options['prefix'] + alias

        # Optionally camelcase the key
        if options['camelcase']:
            key = convert_to_camel(key)

        # Get the field value. Use the mapped value to the actually property or
        # method name. `value` may be a number of things, so the various types
        # are checked below.
        value = get_field_value(instance, accessor,
                                allow_missing=options['allow_missing'])

        # Related objects, perform some checks on their options
        if isinstance(value, (models.Model, QuerySet)):
            _options = _defaults(options['related'].get(accessor, {}))

            # If the `prefix` follows the below template, generate the
            # `prefix` for the related object
            if '%(accessor)s' in _options['prefix']:
                _options['prefix'] = _options['prefix'] % {'accessor': alias}

            if isinstance(value, models.Model):
                if len(_options['fields']) == 1 and _options['flat'] \
                        and not _options['merge']:
                    value = list(serialize(value, **_options).values())[0]
                else:
                    # Recurse, get the dict representation
                    _attrs = serialize(value, **_options)

                    # Check if this object should be merged into the parent,
                    # otherwise nest it under the accessor name
                    if _options['merge']:
                        attrs.update(_attrs)
                        continue

                    value = _attrs
            else:
                value = serialize(value, **_options)

        attrs[key] = value

    # Apply post-hook to serialized attributes
    if options['posthook']:
        attrs = options['posthook'](instance, attrs)

    return attrs
672697
def to_query(self):
        
        query = {}

        for field_instance in self.fields:
            query.update(field_instance.to_query())

        return query
373989
function(fields, data) {
    if (!_.isString(fields)) {
      return data;
    }

    // If a field is specified as `foo.bar` or `foo.bar.baz`,
    // Convert it to just `foo`
    var map = {};
    _.forEach(fields.split(','), function(field) {
      map[field.split('.')[0]] = 1;
    });

    var keys = _.keys(map);
    if (_.isArray(data)) {
      data = _.map(data, function(object) {
        return _.pick(object, keys);
      });
    } else if (_.isObject(data)) {
      data = _.pick(data, keys);
    }

    return data;
  }
1363678
def alias_field(model, field):
    
    for part in field.split(LOOKUP_SEP)[:-1]:
        model = associate_model(model,part)
    return model.__name__ + "-" + field.split(LOOKUP_SEP)[-1]
1032775
def fields(cls):
        
        for property, descriptor in cls.__dict__.items():
            if isinstance(descriptor, MediaField):
                if isinstance(property, bytes):
                    # On Python 2, class field names are bytes. This method
                    # produces text strings.
                    yield property.decode('utf8', 'ignore')
                else:
                    yield property
174321
def make_field_objects(field_data, names):
        # type: (List[Dict[Text, Text]], Names) -> List[Field]
        """"""
        field_objects = []
        field_names = []  # type: List[Text]
        for field in field_data:
            if hasattr(field, 'get') and callable(field.get):
                atype = cast(Text, field.get('type'))
                name = cast(Text, field.get('name'))

                # null values can have a default value of None
                has_default = False
                default = None
                if 'default' in field:
                    has_default = True
                    default = field.get('default')

                order = field.get('order')
                doc = field.get('doc')
                other_props = get_other_props(field, FIELD_RESERVED_PROPS)
                new_field = Field(atype, name, has_default, default, order, names, doc,
                                 other_props)
                # make sure field name has not been used yet
                if new_field.name in field_names:
                    fail_msg = 'Field name %s already in use.' % new_field.name
                    raise SchemaParseException(fail_msg)
                field_names.append(new_field.name)
            else:
                raise SchemaParseException('Not a valid field: %s' % field)
            field_objects.append(new_field)
        return field_objects
768614
function fieldsToMongo(fields) {
    if (!fields) return null
    var hash = {}
    fields.split(',').forEach(function(field) {
        hash[field.trim()] = 1
    })
    return hash
}
516744
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'document_id' in _dict:
            args['document_id'] = _dict.get('document_id')
        if 'field' in _dict:
            args['field'] = _dict.get('field')
        if 'start_offset' in _dict:
            args['start_offset'] = _dict.get('start_offset')
        if 'end_offset' in _dict:
            args['end_offset'] = _dict.get('end_offset')
        if 'entities' in _dict:
            args['entities'] = [
                QueryEvidenceEntity._from_dict(x)
                for x in (_dict.get('entities'))
            ]
        return cls(**args)
1192650
def _fields_list_to_dict(fields):
    
    for key in fields:
        assert isinstance(key, (str,unicode))
    return dict([[key, 1] for key in fields])
707308
function flattenFields(fields) {
	const fieldsObj = {};
	fields.forEach(function(field) {
		if (!fields.hasOwnProperty(field.name)) {
			fieldsObj[field.name] = field.value;
		}
	});
	return fieldsObj;
}
684431
function parse_field_property(obj, key, value) {
			//debug.log('key = ', key);
			var a = key[0];
			var b = key[1];
			//debug.log('key_a = ', a);
			//debug.log('key_b = ', b);

			if(!is.obj(obj['$'+a])) {
				obj['$'+a] = {};
			}

			obj['$'+a][b] = value;
		}
814058
function showFields (data, version, fields) {
  var o = {}
  ;[data,version].forEach(function (s) {
    Object.keys(s).forEach(function (k) {
      o[k] = s[k]
    })
  })
  return search(o, fields.split("."), version._id, fields)
}
870030
def filter_dict(self, query, **kwargs):
        ''' 
        '''
        for name, value in query.items():
            field = name.split(".")[0]
            try:
                getattr(self.type, field)
            except AttributeError:
                raise FieldNotFoundException("Field not found %s" % (field))
        self.query_bypass(query, raw_output=False, **kwargs)
        return self
775179
def get_dict_for_mongodb_queries(self):
        
        d = {}
        return d
        # TODO
        all_structures = [task.input.structure for task in self.iflat_tasks()]
        all_pseudos = [task.input.pseudos for task in self.iflat_tasks()]
1230539
def as_dict(self):
        ''''''
        pk = self.pk
        id_type = 3
        if pk.type == 'auto':
            id_type = 1
        return {'id_name': pk.name,
                'id_type': id_type,
                'sorted': bool(self.ordering),
                'autoincr': self.ordering and self.ordering.auto,
                'multi_fields': [field.name for field in self.multifields],
                'indices': dict(((idx.attname, idx.unique)
                                 for idx in self.indices))}