Query the given fields of items in the given view.

            The result list contains named tuples,
            so you can access the fields directly by their name.
519925
def multicall(self, viewname, fields):
        
        commands = tuple('d.{}='.format(x) for x in fields)
        result_type = namedtuple('DownloadItem', [x.replace('.', '_') for x in fields])
        items = self.open().d.multicall(viewname, *commands)
        return [result_type(*x) for x in items]
36484
def _query(cls, **kwargs):
        
        from sevenbridges.models.link import Link
        from sevenbridges.meta.collection import Collection

        api = kwargs.pop('api', cls._API)
        url = kwargs.pop('url')
        extra = {'resource': cls.__name__, 'query': kwargs}
        logger.info('Querying {} resource'.format(cls), extra=extra)
        response = api.get(url=url, params=kwargs)
        data = response.json()
        total = response.headers['x-total-matching-query']

        items = [cls(api=api, **item) for item in data['items']]
        links = [Link(**link) for link in data['links']]
        href = data['href']
        return Collection(
            resource=cls, href=href, total=total, items=items,
            links=links, api=api
        )
382893
def query_item(self, key, abis):
        """"""
        try:
            key = int(key)
            field = 'number'
        except ValueError:
            try:
                key = int(key, 16)
                field = 'number'
            except ValueError:
                field = 'name'
        arg = and_(getattr(Item, field) == key,
                   or_(Item.abi == abi for abi in abis))
        return self.session.query(Item).filter(arg).all()
470225
@SuppressWarnings("unchecked")
	public <P extends ParaObject> List<P> getItemsFromList(List<?> result) {
		if (result != null && !result.isEmpty()) {
			// this isn't very efficient but there's no way to know what type of objects we're reading
			ArrayList<P> objects = new ArrayList<>(result.size());
			for (Object map : result) {
				P p = ParaObjectUtils.setAnnotatedFields((Map<String, Object>) map);
				if (p != null) {
					objects.add(p);
				}
			}
			return objects;
		}
		return Collections.emptyList();
	}
331463
def get_fields(self):
        """"""
        fields = super(DataSerializer, self).get_fields()

        # Hide collections/entities fields on list views as fetching them may be expensive.
        if self.parent is not None:
            del fields['collections']
            del fields['entities']

        return fields
467403
def get_items(self, paginator, current_page):
        """"""
        fields = self.get_model_config().get_list_fields()

        page = paginator.page(current_page)

        items = []
        for item in page:
            items.append({
                'id': item.id,
                'url': item.get_absolute_url(),
                'row_data': [
                    fields[field]['renderer'](item, field)
                    for field in self.get_current_fields()
                ]
            })
        return items
331196
def get_by_string(cls, fields, query):
	''''''
	try: pk = int(query)
	except ValueError: pass
	else: return cls.objects.get(pk=pk)
	obj = list(cls.objects.filter(reduce( op.or_,
		list(Q(**{'{}__icontains'.format(f): query}) for f in fields) )))
	if len(obj) > 1:
		raise cls.MultipleObjectsReturned((
			u'Unable to uniquely identify {}'
				' by provided criteria: {!r} (candidates: {})' )\
			.format(cls.__name__, query, ', '.join(it.imap(unicode, obj))) )
	elif not len(obj):
		raise cls.DoesNotExist(
			u'Unable to find site by provided criteria: {!r}'.format(query) )
	return obj[0]
1006174
def get_first_field_values_as_list(self, field):
        '''
        
        '''
        for doc in self.docs:
            if field in doc.keys():
                return doc[field]
        raise SolrResponseError("No field in result set")
1272052
def _get_field_values(item, fldnames, rpt_fmt=None, itemid2name=None):
        """"""
        if hasattr(item, "_fldsdefprt"): # Is a GOEnrichmentRecord
            return item.get_field_values(fldnames, rpt_fmt, itemid2name)
        if hasattr(item, "_fields"): # Is a namedtuple
            return [getattr(item, f) for f in fldnames]
690218
def get_fields_by_class(cls, field_class):
        

        ret = []

        for key, val in getattr(cls, '_fields').items():
            if isinstance(val, field_class):
                ret.append(key)
        return ret
257491
def get_queryset_filters(self, query):
        
        conditions = Q()
        for field_name in self.fields:
            conditions |= Q(**{
                self._construct_qs_filter(field_name): query
            })
        return conditions
1013505
def items(self):
        
        if ver == (2, 7):
            return self.viewitems()
        elif ver == (2, 6):
            return self.iteritems()
        elif ver >= (3, 0):
            return self.items()
872671
def group_by(self, fields, items=None):
        
        result = defaultdict(list)
        if items is None:
            items = self.items()

        try:
            key = operator.attrgetter(fields + '')
        except TypeError:
            def key(obj, names=tuple(fields)):
                'Helper to return group key tuple'
                return tuple(getattr(obj, x) for x in names)

        for item in items:
            result[key(item)].append(item)

        return result
1220519
def parse_fields(attributes):
        """"""
        return tuple(field.bind_name(name)
                     for name, field in six.iteritems(attributes)
                     if isinstance(field, fields.Field))
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
217200
protected List<T> queryView(String viewName, ComplexKey key) {
		return db.queryView(createQuery(viewName)
								.includeDocs(true)
								.key(key),
							type);
	}
1033323
def result_list(context):
    
    view = context['view']
    object_list = context['object_list']
    headers = list(result_headers(view))
    num_sorted_fields = 0
    for h in headers:
        if h['sortable'] and h['sorted']:
            num_sorted_fields += 1
    context.update({
        'result_headers': headers,
        'num_sorted_fields': num_sorted_fields,
        'results': list(results(view, object_list))})
    return context