Return unique and slugged field names.
179439
def make_header(field_names, permit_not=False):
    """"""
    slug_chars = SLUG_CHARS if not permit_not else SLUG_CHARS + "^"

    header = [
        slug(field_name, permitted_chars=slug_chars) for field_name in field_names
    ]
    result = []
    for index, field_name in enumerate(header):
        if not field_name:
            field_name = "field_{}".format(index)
        elif field_name[0].isdigit():
            field_name = "field_{}".format(field_name)

        if field_name in result:
            field_name = make_unique_name(
                name=field_name, existing_names=result, start=2
            )
        result.append(field_name)

    return result
93263
def unique_slug(manager, slug_field, slug):
    
    max_length = manager.model._meta.get_field(slug_field).max_length
    slug = slug[:max_length]
    i = 0
    while True:
        if i > 0:
            if i > 1:
                slug = slug.rsplit("-", 1)[0]
            # We need to keep the slug length under the slug fields max length. We need to
            # account for the length that is added by adding a random integer and `-`.
            slug = "%s-%s" % (slug[:max_length - len(str(i)) - 1], i)
        if not manager.filter(**{slug_field: slug}):
            break
        i += 1
    return slug
746038
def get_unique_groups(input_list):
    """"""
    out_list = []
    for item in input_list:
        if item not in out_list:
            out_list.append(item)
    return out_list
1061505
def generate_slug(self, model_instance):
        """"""
        queryset = model_instance.__class__._default_manager.all()

        # Only count slugs that match current length to prevent issues
        # when pre-existing slugs are a different length.
        lookup = {'%s__regex' % self.attname: r'^.{%s}$' % self.length}
        if queryset.filter(**lookup).count() >= len(self.chars)**self.length:
            raise FieldError("No available slugs remaining.")

        slug = get_random_string(self.length, self.chars)

        # Exclude the current model instance from the queryset used in
        # finding next valid slug.
        if model_instance.pk:
            queryset = queryset.exclude(pk=model_instance.pk)

        # Form a kwarg dict used to impliment any unique_together
        # contraints.
        kwargs = {}
        for params in model_instance._meta.unique_together:
            if self.attname in params:
                for param in params:
                    kwargs[param] = getattr(model_instance, param, None)
        kwargs[self.attname] = slug

        while queryset.filter(**kwargs):
            slug = get_random_string(self.length, self.chars)
            kwargs[self.attname] = slug

        return slug
165019
def select_distinct_field(col, field_or_fields, filters=None):
    
    fields = _preprocess_field_or_fields(field_or_fields)

    if filters is None:
        filters = dict()

    if len(fields) == 1:
        key = fields[0]
        data = list(col.find(filters).distinct(key))
        return data
    else:
        pipeline = [
            {
                "$match": filters
            },
            {
                "$group": {
                    "_id": {key: "$" + key for key in fields},
                },
            },
        ]
        data = list()
        for doc in col.aggregate(pipeline):
            # doc = {"_id": {"a": 0, "b": 0}} ...
            data.append([doc["_id"][key] for key in fields])
        return data
21264
def _get_fields(self, fields, excludes, hotfixes):
        '''
        
        '''
        final_fields = {}
        fields = fields or []
        excludes = excludes or []

        for f in self.model._meta.fields:
            # If the field name is already present, skip
            if f.name in self.fields:
                continue

            # If field is not present in explicit field listing, skip
            if fields and f.name not in fields:
                continue

            # If field is in exclude list, skip
            if excludes and f.name in excludes:
                continue

            # If field is a relation, skip.
            if getattr(f, 'rel'):
                continue

            attr = {'model_attr': f.name}
            if f.has_default():
                attr['null_value'] = f.default

            if f.name in hotfixes:
                attr.update(hotfixes[f.name])

            final_fields[f.name] = django_field_to_index(f, **attr)

        return final_fields
630415
def get_inconsistent_fieldnames():
    
    field_name_list = []
    for fieldset_title, fields_list in settings.CONFIG_FIELDSETS.items():
        for field_name in fields_list:
            field_name_list.append(field_name)
    if not field_name_list:
        return {}
    return set(set(settings.CONFIG.keys()) - set(field_name_list))
550018
def field_names(options)
      names = (as_attributes.keys + attribute_names).uniq.sort

      only = Array.wrap(options[:only]).map(&:to_s)
      except = Array.wrap(options[:except]).map(&:to_s)
      except |= ['_type'] unless Mongoid.include_type_for_serialization

      if !only.empty?
        names &= only
      elsif !except.empty?
        names -= except
      end
      names
    end
507438
def _get_name_filters(cls, filters):
        """"""
        filters = filters.get(cls.__uid_field__)
        if not filters:
            filters = '.*'
        elif not isinstance(filters, string_types):
            filters = r'(%s)' % ('|'.join(filters))
        return filters
1251885
public function getUniqueFieldNames()
    {
        $results = [ $this->getPrimaryFieldName() ];
        if (!isset($this->data['fields']) || empty($this->data['fields'])) {
            return $results;
        }

        $table = $this->data['name'];
        foreach ($this->data['fields'] as $field) {
            $name = $table . '_' . $field['name'];

            if ($field['field']['type'] === 'uuid') {
                $results[] = $name;
                continue;
            }

            if (!isset($field['validation'])) {
                continue;
            }

            foreach ($field['validation'] as $validation) {
                if ($validation['method'] === 'unique') {
                    $results[] = $name;
                }
            }
        }

        return $results;
    }
727056
def normal_fields(self):
        """"""
        return {f:v for f, v in self.fields.items() if not f.startswith('_')}
515565
public function getSlugableFieldNames($primary = false)
    {
        $results = [];
        if ($primary) {
            $results[] = $primary;
        }

        if (!isset($this->data['fields']) || empty($this->data['fields'])) {
            return $results;
        }

        $table = $this->data['name'];
        foreach ($this->data['fields'] as $field) {
            $name = $table . '_' . $field['name'];
            if (isset($field['type'])) {
                if ($field['type'] === 'slug') {
                    $results[] = $name;
                }
            }
        }

        return $results;
    }
1231417
def getFieldNames( dbid = nil, lowerOrUppercase = "", exclude_built_in_fields = false )
      fieldNames = []
      dbid ||= @dbid
      getSchema(dbid)
      if @fields
         @fields.each_element_with_attribute( "id" ){ |f|
            next if exclude_built_in_fields and isBuiltInField?(f.attributes["id"])
            if f.name == "field"
               if lowerOrUppercase == "lowercase"
                  fieldNames << f.elements[ "label" ].text.downcase
               elsif lowerOrUppercase == "uppercase"
                  fieldNames << f.elements[ "label" ].text.upcase
               else
                  fieldNames << f.elements[ "label" ].text.dup
               end
            end
         }
      end
      fieldNames
    end
315427
def _clean_schema_fields(self, fields):
        """"""
        fields_sorted = sorted(fields, key=lambda field: field["name"])
        # Ignore mode and description when comparing schemas.
        return [
            {"name": field["name"], "type": field["type"]}
            for field in fields_sorted
        ]
257949
def get_column_names(context, query):
        """"""
        table_info = context.sql_client.send(query)
        if 'fields' in table_info:
            return table_info['fields']

        return None
980754
def _get_csv_fieldnames(csv_reader):
    """"""
    fieldnames = []
    for row in csv_reader:
        for col in row:
            field = (
                col.strip()
                .replace('"', "")
                .replace(" ", "")
                .replace("(", "")
                .replace(")", "")
                .lower()
            )
            fieldnames.append(field)
        if "id" in fieldnames:
            break
        else:
            # this is not a row with fieldnames
            del fieldnames[:]
    if not fieldnames:
        return None
    # remove trailing unannotated fields
    while True:
        field = fieldnames.pop()
        if field:
            fieldnames.append(field)
            break
    # name unannotated fields
    suffix = 1
    for index, field in enumerate(fieldnames):
        if not field:
            fieldnames[index] = "field{}".format(suffix)
            suffix += 1

    return fieldnames
1248096
def unique_list(input_, key=lambda x:x):
    """"""
    seen = set()
    output = []
    for x in input_:
        keyx = key(x)
        if keyx not in seen:
            seen.add(keyx)
            output.append(x)
    return output