本文整理汇总了Python中openspending.lib.browser.Browser类的典型用法代码示例。如果您正苦于以下问题:Python Browser类的具体用法?Python Browser怎么用?Python Browser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Browser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_union
def test_filter_union(self):
f = {'foo': ['bar', 'baz']}
b = Browser(filter=f)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert '+foo:"bar" OR +foo:"baz"' in solr_args['fq']
示例2: search
def search(self):
parser = SearchParamParser(request.params)
params, errors = parser.parse()
if errors:
response.status = 400
return {'errors': errors}
expand_facets = params.pop('expand_facet_dimensions')
datasets = params.pop('dataset', None)
if datasets is None or not len(datasets):
q = model.Dataset.all_by_account(c.account)
if params.get('category'):
q = q.filter_by(category=params.pop('category'))
datasets = q.all()
expand_facets = False
if not len(datasets):
return {'errors': [_("No dataset available.")]}
params['filter']['dataset'] = []
for dataset in datasets:
require.dataset.read(dataset)
params['filter']['dataset'].append(dataset.name)
response.last_modified = max([d.updated_at for d in datasets])
etag_cache_keygen(parser.key(), response.last_modified)
b = Browser(**params)
try:
stats, facets, entries = b.execute()
except SolrException, e:
return {'errors': [unicode(e)]}
示例3: search
def search(self):
parser = SearchParamParser(request.params)
params, errors = parser.parse()
if errors:
response.status = 400
return {'errors': errors}
expand_facets = params.pop('expand_facet_dimensions')
datasets = params.pop('dataset', None)
if datasets is None:
datasets = model.Dataset.all_by_account(c.account)
expand_facets = False
for dataset in datasets:
require.dataset.read(dataset)
b = Browser(**params)
stats, facets, entries = b.execute()
entries = [entry_apply_links(d.name, e) for d, e in entries]
if expand_facets and len(datasets) == 1:
_expand_facets(facets, datasets[0])
return {
'stats': stats,
'facets': facets,
'results': entries
}
示例4: index
def index(self, dataset, format='html'):
# Get the dataset into the context variable 'c'
self._get_dataset(dataset)
# If the format is either json or csv we direct the user to the search
# API instead
if format in ['json', 'csv']:
return redirect(h.url_for(controller='api/version2',
action='search',
format=format, dataset=dataset,
**request.params))
# Get the default view
handle_request(request, c, c.dataset)
# Parse the parameters using the SearchParamParser (used by the API)
parser = EntryIndexParamParser(request.params)
params, errors = parser.parse()
# We have to remove page from the parameters because that's also
# used in the Solr browser (which fetches the queries)
params.pop('page')
# We limit ourselve to only our dataset
params['filter']['dataset'] = [c.dataset.name]
facet_dimensions = {field.name: field
for field in c.dataset.dimensions
if field.facet}
params['facet_field'] = facet_dimensions.keys()
# Create a Solr browser and execute it
b = Browser(**params)
try:
b.execute()
except SolrException as e:
return {'errors': [unicode(e)]}
# Get the entries, each item is a tuple of the dataset and entry
solr_entries = b.get_entries()
entries = [entry for (dataset, entry) in solr_entries]
# Get expanded facets for this dataset,
c.facets = b.get_expanded_facets(c.dataset)
# Create a pager for the entries
c.entries = templating.Page(entries, **request.params)
# Set the search word and default to empty string
c.search = params.get('q', '')
# Set filters (but remove the dataset as we don't need it)
c.filters = params['filter']
del c.filters['dataset']
# We also make the facet dimensions and dimension names available
c.facet_dimensions = facet_dimensions
c.dimensions = [dimension.name for dimension in c.dataset.dimensions]
# Render the entries page
return templating.render('entry/index.html')
示例5: test_fractional_page_pagesize
def test_fractional_page_pagesize(self):
b = Browser(page=2.5, pagesize=50)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args['start'] == 75
assert solr_args['rows'] == 50
示例6: test_facets_page_pagesize
def test_facets_page_pagesize(self):
b = Browser(facet_field=["one"], facet_page=2, facet_pagesize=50)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args["facet.offset"] == 50
assert solr_args["facet.limit"] == 50
示例7: test_page_pagesize
def test_page_pagesize(self):
b = Browser(page=2, pagesize=50)
b.execute()
_, solr_args = self.conn.raw_query.call_args
h.assert_equal(solr_args['start'], 50)
h.assert_equal(solr_args['rows'], 50)
示例8: test_page_pagesize
def test_page_pagesize(self):
b = Browser(page=2, pagesize=50)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args["start"] == 50
assert solr_args["rows"] == 50
示例9: test_facets_page_pagesize
def test_facets_page_pagesize(self):
b = Browser(facet_field=['one'], facet_page=2, facet_pagesize=50)
b.execute()
_, solr_args = self.conn.raw_query.call_args
h.assert_equal(solr_args['facet.offset'], 50)
h.assert_equal(solr_args['facet.limit'], 50)
示例10: test_entries_order
def test_entries_order(self):
self.conn.raw_query.return_value = make_response([1, 2, 3])
self.dataset.entries.return_value = make_entries([3, 1, 2])
b = Browser()
_, _, entries = b.execute()
h.assert_equal(map(lambda (a, b): b, entries), make_entries([1, 2, 3]))
示例11: test_filter
def test_filter(self):
f = {'foo': 'bar', 'baz': 'with "quotes"'}
b = Browser(filter=f)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert '+foo:"bar"' in solr_args['fq']
assert '+baz:"with \\"quotes\\""' in solr_args['fq']
示例12: test_filter
def test_filter(self):
f = {"foo": "bar", "baz": 'with "quotes"'}
b = Browser(filter=f)
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert '+foo:"bar"' in solr_args["fq"]
assert '+baz:"with \\"quotes\\""' in solr_args["fq"]
示例13: test_fractional_page_pagesize
def test_fractional_page_pagesize(self):
b = Browser(page=2.5, pagesize=50)
b.execute()
_, solr_args = self.conn.raw_query.call_args
# Use assert_is rather than assert_equal to verify
# that it's an integer.
h.assert_is(solr_args['start'], 75)
h.assert_equal(solr_args['rows'], 50)
示例14: test_facets
def test_facets(self):
b = Browser(facet_field=['foo', 'bar'])
b.execute()
ignore, solr_args = self.conn.raw_query.call_args
assert solr_args['facet'] == 'true'
assert solr_args['facet.mincount'] == 1
assert solr_args['facet.sort'] == 'count'
assert solr_args['facet.field'] == ['foo', 'bar']
示例15: test_entries_stats
def test_entries_stats(self):
self.conn.raw_query.return_value = make_response([1, 2, 3])
self.dataset.entries.return_value = make_entries([3, 1, 2])
b = Browser()
stats, _, _ = b.execute()
h.assert_equal(stats['results_count'], 3)
h.assert_equal(stats['results_count_query'], 1234)