Creates a list of dictionaries with the field names, labels,
        field links, field css classes, order_url and order_direction,
        this simplifies the creation of a table in a template.
770740
def get_list_header(self):
        
        model = self.object_list.model
        result = []
        if not self.get_fields():
            result.append(
                {"name": "", "verbose": str(model._meta.verbose_name)}
            )
        else:
            prefix = self.get_prefix()
            ordering_fields = self.get_ordering_fields()
            for field_name in self.get_fields():
                item = {}
                if isinstance(field_name, tuple):
                    # custom property that is not a field of the model
                    name = field_name[0]
                    item["label"] = field_name[1]
                else:
                    name = field_name
                    try:
                        field_meta = find_field_meta(model, field_name)
                        if field_meta._verbose_name:  # noqa
                            # explicitly set on the model, so don't change
                            item["label"] = field_meta._verbose_name  # noqa
                        else:
                            # title-case the field name (issue #80)
                            item["label"] = field_meta.verbose_name.title()
                    except FieldDoesNotExist:
                        item["label"] = field_name
                    except AttributeError:
                        item["label"] = field_name
                item["name"] = prefix + name
                if name in ordering_fields:
                    item["order_url"], item[
                        "order_direction"
                    ] = self.ordering_url(name)
                result.append(item)

        return result
525409
def make_table_map(table, headers):
    """"""

    header_parts = {}
    for i, h in enumerate(headers):
        header_parts[h] = 'row[{}]'.format(i)

    body_code = 'lambda row: [{}]'.format(','.join(header_parts.get(c.name, 'None') for c in table.columns))
    header_code = 'lambda row: [{}]'.format(
        ','.join(header_parts.get(c.name, "'{}'".format(c.name)) for c in table.columns))

    return eval(header_code), eval(body_code)
1317167
def _html(title: str, field_names: List[str]) -> str:
    
    inputs = ''.join(_SINGLE_INPUT_TEMPLATE.substitute(field_name=field_name)
                     for field_name in field_names)

    quoted_field_names = [f"'{field_name}'" for field_name in field_names]
    quoted_field_list = f"[{','.join(quoted_field_names)}]"

    return _PAGE_TEMPLATE.substitute(title=title,
                                     css=_CSS,
                                     inputs=inputs,
                                     qfl=quoted_field_list)
355100
def namedlist(objname, fieldnames):
    ''
    class NamedListTemplate(list):
        __name__ = objname
        _fields = fieldnames

        def __init__(self, L=None, **kwargs):
            if L is None:
                L = [None]*len(fieldnames)
            super().__init__(L)
            for k, v in kwargs.items():
                setattr(self, k, v)

        @classmethod
        def length(cls):
            return len(cls._fields)

    for i, attrname in enumerate(fieldnames):
        # create property getter/setter for each field
        setattr(NamedListTemplate, attrname, property(operator.itemgetter(i), itemsetter(i)))

    return NamedListTemplate
483667
def _init_fields(self):
        
        fields = {}
        forms = {}
        sets = {}

        for name in dir(self):
            if name.startswith('_'):
                continue
            field = getattr(self, name)
            is_field = isinstance(field, Field)
            is_form = isinstance(field, Form) or (
                inspect.isclass(field) and issubclass(field, Form))
            is_set = isinstance(field, FormSet)

            if is_field:
                field = copy(field)
                field.name = self._prefix + name
                field.form = self
                if field.prepare is None:
                    field.prepare = getattr(self, 'prepare_' + name, None)
                if field.clean is None:
                    field.clean = getattr(self, 'clean_' + name, None)
                fields[name] = field
                setattr(self, name, field)
            elif is_form:
                forms[name] = field
            elif is_set:
                field._name = self._prefix + name  # REALLY IMPORTANT
                sets[name] = field

        self._fields = fields
        self._forms = forms
        self._sets = sets
371489
def generate_list_view(self):
        """"""

        name = model_class_form(self.model + 'ListView')
        list_args = dict(
            model=self.get_model_class,
            context_object_name=plural(self.model),
            template_name=self.get_template('list'),
            table_class=self.get_actual_table(),
            context_table_name='table_objects',
            crud=self.crud,
            permissions=self.view_permission('list'),
            permission_required=self.check_permission_required,
            login_required=self.check_login_required,
            table_pagination={'per_page': self.tables2_pagination or 10},
            custom_queryset=self.custom_queryset,
            custom_context=self.custom_context,
            custom_postfix_url=self.custom_postfix_url
        )

        list_class = type(
            name,
            (BaseListViewMixin, SingleTableView),
            list_args
        )
        self.classes[name] = list_class
        return list_class
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
1066939
def _descriptor_names(self):
        

        descriptor_names = []

        for name in dir(self):
            try:
                attr = getattr(type(self), name)

                if isinstance(attr, DJANGO_RELATED_FIELD_DESCRIPTOR_CLASSES):
                    descriptor_names.append(name)

            except AttributeError:
                pass

        return descriptor_names
895114
def _build_template_map(cookbook, cookbook_name, stencil):
    
    template_map = {
        'cookbook': {"name": cookbook_name},
        'options': stencil['options']
    }

    # Cookbooks may not yet have metadata, so we pass an empty dict if so
    try:
        template_map['cookbook'] = cookbook.metadata.to_dict().copy()
    except ValueError:
        # ValueError may be returned if this cookbook does not yet have any
        # metadata.rb written by a stencil. This is okay, as everyone should
        # be using the base stencil first, and then we'll try to call
        # cookbook.metadata again in this method later down.
        pass

    template_map['cookbook']['year'] = datetime.datetime.now().year
    return template_map
593185
def make_table(file_dict):
        """"""
        col_key = Column(name='key', dtype=int)
        col_path = Column(name='path', dtype='S256')
        col_creator = Column(name='creator', dtype=int)
        col_timestamp = Column(name='timestamp', dtype=int)
        col_status = Column(name='status', dtype=int)
        col_flags = Column(name='flags', dtype=int)
        columns = [col_key, col_path, col_creator,
                   col_timestamp, col_status, col_flags]
        table = Table(data=columns)
        for val in file_dict.values():
            val.append_to_table(table)
        return table
611068
def _list_view(self, model, **kwargs):
        
        from uliweb import request

        #add download fields process
        fields = kwargs.pop('fields', None)
        meta = kwargs.pop('meta', 'Table')
        if 'download' in request.GET:
            if 'download_fields' in kwargs:
                fields = kwargs.pop('download_fields', fields)
            if 'download_meta' in kwargs:
                meta = kwargs.pop('download_meta')
            else:
                if hasattr(model, 'Download'):
                    meta = 'Download'
                else:
                    meta = meta

        view = functions.ListView(model, fields=fields, meta=meta, **kwargs)
        return view
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
869188
def _build_object_table(self):
        ''''''
        types = self.domain.types
        objects = dict(self.non_fluents.objects)
        self.object_table = dict()
        for name, value in self.domain.types:
            if value == 'object':
                objs = objects[name]
                idx = { obj: i for i, obj in enumerate(objs) }
                self.object_table[name] = {
                    'size': len(objs),
                    'idx': idx,
                    'objects': objs
                }
388120
def _format_fields(cls, declared_fields: typing.List[tuple]):
        
        formatted_fields = []
        for declared_field in declared_fields:
            field_name = field_type = field_defn = None

            # Case when only (name), or "name", is specified
            if isinstance(declared_field, str) or len(declared_field) == 1:
                field_name = declared_field
                field_type = typing.Any
                field_defn = field(default=None)

            # Case when (name, type) are specified
            elif len(declared_field) == 2:
                field_name = declared_field[0]
                field_type = declared_field[1]
                field_defn = field(default=None)

            # Case when (name, type, field) are specified
            elif len(declared_field) == 3:
                field_name = declared_field[0]
                field_type = declared_field[1]

                # Process the definition and create a `field` object
                # Definition will be of the form `{'required': False, 'default': 'John'}`
                assert isinstance(declared_field[2], dict)
                metadata = default = None
                if 'required' in declared_field[2] and declared_field[2]['required']:
                    metadata = {'required': True}
                if 'default' in declared_field[2]:
                    default = declared_field[2]['default']
                field_defn = field(default=default, metadata=metadata)

            formatted_fields.append((field_name, field_type, field_defn))

        return formatted_fields
578252
def field_pklist_to_json(self, model, pks):
        
        app_label = model._meta.app_label
        model_name = model._meta.model_name
        return {
            'app': app_label,
            'model': model_name,
            'pks': list(pks),
        }
1192650
def _fields_list_to_dict(fields):
    
    for key in fields:
        assert isinstance(key, (str,unicode))
    return dict([[key, 1] for key in fields])
570248
def add_fields(store_name, field_names):
    
    def decorate(cls):
        def _add(index, name):
            def _set_dir(self, value): getattr(self, store_name)[index] = value
            def _get_dir(self): return getattr(self, store_name)[index]
            setattr(cls, name, property(_get_dir, _set_dir))

        for index, field_name in enumerate(field_names):
            _add(index, field_name)

        return cls

    return decorate