Return dict of extra fields added to the historical record model
883
def get_extra_fields(self, model, fields):
        """"""

        def revert_url(self):
            """URL for this change in the default admin site."""
            opts = model._meta
            app_label, model_name = opts.app_label, opts.model_name
            return reverse(
                "%s:%s_%s_simple_history" % (admin.site.name, app_label, model_name),
                args=[getattr(self, opts.pk.attname), self.history_id],
            )

        def get_instance(self):
            attrs = {
                field.attname: getattr(self, field.attname) for field in fields.values()
            }
            if self._history_excluded_fields:
                excluded_attnames = [
                    model._meta.get_field(field).attname
                    for field in self._history_excluded_fields
                ]
                values = (
                    model.objects.filter(pk=getattr(self, model._meta.pk.attname))
                    .values(*excluded_attnames)
                    .get()
                )
                attrs.update(values)
            return model(**attrs)

        def get_next_record(self):
            """
            Get the next history record for the instance. `None` if last.
            """
            history = utils.get_history_manager_for_model(self.instance)
            return (
                history.filter(Q(history_date__gt=self.history_date))
                .order_by("history_date")
                .first()
            )

        def get_prev_record(self):
            """
            Get the previous history record for the instance. `None` if first.
            """
            history = utils.get_history_manager_for_model(self.instance)
            return (
                history.filter(Q(history_date__lt=self.history_date))
                .order_by("history_date")
                .last()
            )

        extra_fields = {
            "history_id": self._get_history_id_field(),
            "history_date": models.DateTimeField(),
            "history_change_reason": self._get_history_change_reason_field(),
            "history_type": models.CharField(
                max_length=1,
                choices=(("+", _("Created")), ("~", _("Changed")), ("-", _("Deleted"))),
            ),
            "history_object": HistoricalObjectDescriptor(
                model, self.fields_included(model)
            ),
            "instance": property(get_instance),
            "instance_type": model,
            "next_record": property(get_next_record),
            "prev_record": property(get_prev_record),
            "revert_url": revert_url,
            "__str__": lambda self: "{} as of {}".format(
                self.history_object, self.history_date
            ),
        }

        extra_fields.update(self._get_history_related_field(model))
        extra_fields.update(self._get_history_user_fields())

        return extra_fields
707246
def make_extra_json_fields(args):
    
    extra_json_fields = {
        'data_group': _get_data_group(args.query),
        'data_type': _get_data_type(args.query),
        'data_group_data_type': _get_data_group_data_type(args.query),
        'query': _get_query_params(args.query),
    }
    if "path_to_json_file" in args.query:
        extra_json_fields['path_to_query'] = _get_path_to_json_file(args.query)
    return extra_json_fields
4674
def field_dict(self, model):
        
        if self.field_names is None:
            return dict([(f.name, f) for f in model._meta.fields
                         if isinstance(f, models.DateField)])
        else:
            return dict([(f.name, f)
                         for f in model._meta.fields
                         if isinstance(f, models.DateField) and
                            (f.name in self.field_names)])
1056046
def magic_fields(self):
        """"""
        return {f:v for f, v in self.fields.items() if f.startswith('_')}
812130
def _process_include_fields(self, include_fields, exclude_fields,
                                extra_fields):
        
        def _convert_fields(_in):
            if not _in:
                return _in

            for newname, oldname in self._get_api_aliases():
                if oldname in _in:
                    _in.remove(oldname)
                    if newname not in _in:
                        _in.append(newname)
            return _in

        ret = {}
        if self._check_version(4, 0):
            if include_fields:
                include_fields = _convert_fields(include_fields)
                if "id" not in include_fields:
                    include_fields.append("id")
                ret["include_fields"] = include_fields
            if exclude_fields:
                exclude_fields = _convert_fields(exclude_fields)
                ret["exclude_fields"] = exclude_fields
        if self._supports_getbug_extra_fields:
            if extra_fields:
                ret["extra_fields"] = _convert_fields(extra_fields)
        return ret
1165215
def find_extra(self, record):
        
        rv = vars(record).copy()
        for key in ('name', 'msg', 'args', 'levelname', 'levelno',
                    'pathname', 'filename', 'module', 'exc_info',
                    'exc_text', 'lineno', 'funcName', 'created',
                    'msecs', 'relativeCreated', 'thread', 'threadName',
                    'processName', 'process'):
            rv.pop(key, None)
        return rv
249455
def refkeys(self,fields):
    ""
    # todo doc: better explanation of what refkeys are and how fields plays in
    dd=collections.defaultdict(list)
    if any(f not in self.REFKEYS for f in fields): raise ValueError(fields,'not all in',self.REFKEYS.keys())
    for f in fields:
      rk=self.REFKEYS[f]
      for model in rk.refmodels: dd[model].extend(rk.pkeys(self,f))
    return dd
435542
def namedb_find_missing_and_extra(cur, record, table_name):
    
    rec_missing = []
    rec_extra = []
    
    # sanity check: all fields must be defined
    name_fields_rows = db_query_execute(cur, 'PRAGMA table_info({})'.format(table_name), ())
    name_fields = []
    for row in name_fields_rows:
        name_fields.append( row['name'] )

    # make sure each column has a record field
    for f in name_fields:
        if f not in record.keys():
            rec_missing.append( f )

    # make sure each record field has a column
    for k in record.keys():
        if k not in name_fields:
            rec_extra.append( k )

    return rec_missing, rec_extra
701435
def additionalProperties(self):
        """"""
        value = self._schema.get("additionalProperties", {})
        if not isinstance(value, dict) and value is not False:
            raise SchemaError(
                "additionalProperties value {0!r} is neither false nor"
                " an object".format(value))
        return value
1189878
def dump_extra_diffs(field)
      extra_diffs = diffs_by_field_type(field, TYPE_EXTRA)

      if extra_diffs.length > 0
        header = "Table #{@table_name} has extra #{field}:\n"
        diff_str = extra_diffs.map do |diff|
          dump_single(field, diff[:generator], diff[:elem])
        end.join("\n\t")

        "#{header}\n\t#{diff_str}\n"
      end
    end
459774
def get_params_with_extra(self, rule_name, params):
        
        # HACK for prefer-local
        result = []
        extra_params = self._rules_vars_extra.get(rule_name, {})[0]
        _tmp_params = copy.deepcopy(params)
        _fixed_params = {}

        # Save params with list type - this type not changed
        for key, value in _tmp_params.items():
            if isinstance(value, list):
                _fixed_params[key] = value
        _tmp_params = {k: v for k, v in _tmp_params.items() if k not in _fixed_params}

        # extend with extra_vars - like 'any'
        for key, value in _tmp_params.items():
            if not isinstance(value, list) and key:
                _tmp_params[key] = list([value])
            if key in extra_params:
                _tmp_params[key].extend(extra_params[key])

        # get combinations
        keys = sorted(_tmp_params)
        combinations = itertools.product(*(_tmp_params[x] for x in keys))
        for comb in combinations:
            _dict = dict(zip(keys, comb))
            _dict.update(_fixed_params)
            result.append(_dict)

        return result
312076
def get_default_field_names(self, declared_fields, model_info):
        
        return (
            [model_info.pk.name] +
            list(declared_fields.keys()) +
            list(model_info.fields.keys()) +
            list(model_info.forward_relations.keys())
        )
149493
def _convert(cls, record):
        
        if not record:
            return {}

        converted_dict = {}
        for field in cls.conversion:
            key = field[0]
            if len(field) >= 2 and field[1]:
                converted_key = field[1]
            else:
                converted_key = key
            if len(field) >= 3 and field[2]:
                conversion_method = field[2]
            else:
                conversion_method = cls.default_conversion_method
            if len(field) >= 4:
                converter = field[3]
            else:
                converter = None
            try:
                value = conversion_method(record[key])
            except KeyError:
                continue
            if converter:
                value = converter._convert_internal(value)
            if converted_key is APPEND:
                if isinstance(value, list):
                    for v in value:
                        converted_dict.update(v)
                else:
                    converted_dict.update(value)
            else:
                converted_dict[converted_key] = value
        return converted_dict
470609
def _get_related_fields(self, model):
        ""
        reverse_fk = self._get_all_related_objects(model)
        reverse_m2m = self._get_all_related_many_to_many_objects(model)

        fields = tuple(reverse_fk + reverse_m2m)
        names = tuple([x.get_accessor_name() for x in fields])

        return {
            ':related': dict(list(zip(names, fields))),
        }
1320201
def get_fields_dict(self):
        
        fields = []
        for field_name in self.model_admin.get_inspect_view_fields():
            fields.append(self.get_dict_for_field(field_name))
        return fields
650689
def get_fields(self):
        
        prefix = getattr(self.Meta, 'source_prefix', '')
        fields = super(ModelSubSerializer, self).get_fields()
        fields_without_prefix = OrderedDict()
        for field_name, field in fields.items():
            if field_name.startswith(prefix):
                # Set real model field name as field's `source` unless the
                # source is already explicitly set, in which case it is
                # probably a method name not the direct field name
                if not field.source:
                    field.source = field_name
                field_name = field_name[len(prefix):]
            fields_without_prefix[field_name] = field
        return fields_without_prefix
278828
def fields(self):
        
        return {k:getattr(self, k, None) for k in self.schema.fields}