示例#1
0
def render_search():
    params = multi_to_dict(request.args)
    params['facets'] = True
    # We only fetch relevant data for the given filter.
    if 'tag' in params:
        search_queries = [
            search.SearchQuery(Dataset, **params),
            search.SearchQuery(Reuse, **params)
        ]
        results_labels = ['datasets', 'reuses']
    elif 'badge' in params:
        search_queries = [
            search.SearchQuery(Dataset, **params),
            search.SearchQuery(Organization, **params)
        ]
        results_labels = ['datasets', 'organizations']
    else:
        search_queries = [
            search.SearchQuery(Dataset, **params),
            search.SearchQuery(Reuse, **params),
            search.SearchQuery(Organization, **params),
            search.SearchQuery(User, **params)
        ]
        results_labels = ['datasets', 'reuses', 'organizations', 'users']
    results = search.multiquery(*search_queries)
    context = dict(zip(results_labels, results))
    context['territories'] = check_for_territories(params.get('q'))
    return theme.render('search.html', **context)
示例#2
0
 def get(self):
     args = suggest_parser.parse_args()
     territories = check_for_territories(args['q'].decode('utf-8'))
     if args['size']:
         territories = territories[:args['size']]
     return [{
         'id': territory.id,
         'title': territory.name,
         'parent': territory.parent and territory.parent.name or None,
         'image_url': territory.logo_url(external=True),
         'page': territory.external_url
     } for territory in territories]
示例#3
0
文件: api.py 项目: michelbl/udata
 def get(self):
     args = suggest_parser.parse_args()
     territories = check_for_territories(args['q'].decode('utf-8'))
     if args['size']:
         territories = territories[:args['size']]
     return [{
         'id': territory.id,
         'title': territory.name,
         'county': territory.county.name,
         'image_url': territory.logo_url(external=True),
         'page': url_for('territories.territory',
                         territory=territory, _external=True)
     } for territory in territories]
示例#4
0
文件: api.py 项目: opendatateam/udata
 def get(self):
     args = suggest_parser.parse_args()
     territories = check_for_territories(args['q'])
     if args['size']:
         territories = territories[:args['size']]
     return [{
         'id': territory.id,
         'title': territory.name,
         'image_url': territory.logo_url(external=True),
         'parent': (territory.current_parent and
                    territory.current_parent.name or None),
         'page': territory.external_url
     } for territory in territories]
示例#5
0
def render_search():
    params = multi_to_dict(request.args)
    params['facets'] = True
    # We only fetch relevant data for the given filter.
    if 'tag' in params:
        types = ['datasets', 'reuses']
    elif 'badge' in params:
        types = ['datasets', 'organizations']
    else:
        types = ['datasets', 'reuses', 'organizations']
    models = [MAPPING[typ] for typ in types]
    results = search.multisearch(*models, **params)
    context = dict(zip(types, results))
    territories = check_for_territories(params.get('q'))
    context['territories'] = territories
    return theme.render('search.html', **context)
示例#6
0
 def get(self):
     args = suggest_parser.parse_args()
     territories = check_for_territories(args['q'].decode('utf-8'))
     if args['size']:
         territories = territories[:args['size']]
     return [{
         'id':
         territory.id,
         'title':
         territory.name,
         'county':
         territory.county.name,
         'image_url':
         territory.logo_url(external=True),
         'page':
         url_for('territories.territory',
                 territory=territory,
                 _external=True)
     } for territory in territories]
示例#7
0
文件: views.py 项目: rfResearch/udata
def render_search():
    # We only fetch relevant data for the given filter.
    # To do so, we parse query for each type
    # and we only keep types supporting all parameters
    adapters = {t: search.adapter_for(m) for t, m in MAPPING.items()}
    type_args = {
        t: not_none_dict(a.as_request_parser().parse_args())
        for t, a in adapters.items()
    }
    all_args = set.union(*[set(args.keys()) for args in type_args.values()])
    types = [
        typ for typ, args in type_args.items() if set(args.keys()) == all_args
    ]
    params = type_args[types[0]]
    params['facets'] = True
    models = [MAPPING[typ] for typ in types]
    results = search.multisearch(*models, **params)
    context = dict(zip(types, results))
    territories = check_for_territories(params.get('q'))
    context['territories'] = territories
    return theme.render('search.html', **context)
示例#8
0
文件: views.py 项目: odtvince/udata
def render_search():
    # We only fetch relevant data for the given filter.
    # To do so, we parse query for each type
    # and we only keep types supporting all parameters
    adapters = {t: search.adapter_for(m) for t, m in MAPPING.items()}
    type_args = {
        t: not_none_dict(a.as_request_parser().parse_args())
        for t, a in adapters.items()
    }
    all_args = set.union(*[
        set(args.keys()) for args in type_args.values()
    ])
    types = [
        typ for typ, args in type_args.items()
        if set(args.keys()) == all_args
    ]
    params = type_args[types[0]]
    params['facets'] = True
    models = [MAPPING[typ] for typ in types]
    results = search.multisearch(*models, **params)
    context = dict(zip(types, results))
    territories = check_for_territories(params.get('q'))
    context['territories'] = territories
    return theme.render('search.html', **context)