def search_fields(request): products = models.ProductsVersions().get() versions = models.CurrentVersions().get() platforms = models.Platforms().get() form = forms.SearchForm(products, versions, platforms, request.user.is_authenticated(), request.GET) return form.get_fields_list()
def search_fields(request): products = models.ProductsVersions().get() versions = models.CurrentVersions().get() platforms = models.Platforms().get() form = forms.SearchForm(products, versions, platforms, request.user.has_perm('crashstats.view_pii'), request.GET) return form.get_fields_list()
def get_supersearch_form(request): products = models.ProductsVersions().get() versions = models.CurrentVersions().get() platforms = models.Platforms().get() all_fields = SuperSearchFields().get() form = forms.SearchForm(all_fields, products, versions, platforms, request.user, request.GET) return form
def search_results(request): products = models.ProductsVersions().get() versions = models.CurrentVersions().get() platforms = models.Platforms().get() form = forms.SearchForm(products, versions, platforms, request.user.is_authenticated(), request.GET) if not form.is_valid(): return http.HttpResponseBadRequest(str(form.errors)) params = {} for key in form.cleaned_data: if hasattr(form.fields[key], 'prefixed_value'): value = form.fields[key].prefixed_value else: value = form.cleaned_data[key] params[key] = value data = {} data['query'] = {'total': 0, 'total_count': 0, 'total_pages': 0} allowed_fields = ALL_POSSIBLE_FIELDS if request.user.is_authenticated(): allowed_fields += ADMIN_RESTRICTED_FIELDS current_query = request.GET.copy() if 'page' in current_query: del current_query['page'] data['params'] = current_query.copy() if '_columns' in data['params']: del data['params']['_columns'] if '_facets' in params: del data['params']['_facets'] params['_facets'] = request.GET.getlist('_facets') or DEFAULT_FACETS data['columns'] = request.GET.getlist('_columns') or DEFAULT_COLUMNS # Make sure only allowed fields are used params['_facets'] = [x for x in params['_facets'] if x in allowed_fields] data['columns'] = [x for x in data['columns'] if x in allowed_fields] try: current_page = int(request.GET.get('page', 1)) except ValueError: return http.HttpResponseBadRequest('Invalid page') if current_page <= 0: current_page = 1 results_per_page = 50 data['current_page'] = current_page data['results_offset'] = results_per_page * (current_page - 1) params['_results_number'] = results_per_page params['_results_offset'] = data['results_offset'] data['current_url'] = '%s?%s' % (reverse('supersearch.search'), current_query.urlencode()) api = SuperSearch() search_results = api.get(**params) if 'signature' in search_results['facets']: # Bugs for each signature signatures = [h['term'] for h in search_results['facets']['signature']] if signatures: bugs = defaultdict(list) bugs_api = models.Bugs() for b in bugs_api.get(signatures=signatures)['hits']: bugs[b['signature']].append(b['id']) for hit in search_results['facets']['signature']: sig = hit['term'] if sig in bugs: if 'bugs' in hit: hit['bugs'].extend(bugs[sig]) else: hit['bugs'] = bugs[sig] search_results['total_pages'] = int( math.ceil(search_results['total'] / float(results_per_page))) search_results['total_count'] = search_results['total'] data['query'] = search_results data['report_list_query_string'] = urllib.urlencode( utils.sanitize_dict(get_report_list_parameters(params)), True) return render(request, 'supersearch/search_results.html', data)