def signature_comments(request, params): '''Return a list of non-empty comments. ''' signature = params['signature'][0] context = {} context['query'] = { 'total': 0, 'total_count': 0, 'total_pages': 0 } current_query = request.GET.copy() if 'page' in current_query: del current_query['page'] context['params'] = current_query.copy() 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 context['current_page'] = current_page context['results_offset'] = results_per_page * (current_page - 1) params['signature'] = '=' + signature params['user_comments'] = '!__null__' params['_columns'] = ['uuid', 'user_comments', 'date', 'useragent_locale'] params['_results_number'] = results_per_page params['_results_offset'] = context['results_offset'] params['_facets'] = [] # We don't need no facets. context['current_url'] = '%s?%s' % ( reverse('signature:signature_report'), urlencode_obj(current_query) ) api = SuperSearchUnredacted() try: search_results = api.get(**params) except BadArgumentError as e: # We need to return the error message in some HTML form for jQuery to # pick it up. return http.HttpResponseBadRequest(render_exception(e)) search_results['total_pages'] = int( math.ceil( search_results['total'] / float(results_per_page) ) ) search_results['total_count'] = search_results['total'] context['query'] = search_results return render(request, 'signature/signature_comments.html', context)
def signature_comments(request, params): '''Return a list of non-empty comments. ''' signature = params['signature'][0] context = {} context['query'] = {'total': 0, 'total_count': 0, 'total_pages': 0} current_query = request.GET.copy() if 'page' in current_query: del current_query['page'] context['params'] = current_query.copy() 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 context['current_page'] = current_page context['results_offset'] = results_per_page * (current_page - 1) params['signature'] = '=' + signature params['user_comments'] = '!__null__' params['_columns'] = ['uuid', 'user_comments', 'date', 'useragent_locale'] params['_sort'] = '-date' params['_results_number'] = results_per_page params['_results_offset'] = context['results_offset'] params['_facets'] = [] # We don't need no facets. context['current_url'] = '%s?%s' % (reverse('signature:signature_report'), urlencode_obj(current_query)) api = SuperSearchUnredacted() try: search_results = api.get(**params) except BadArgumentError as e: # We need to return the error message in some HTML form for jQuery to # pick it up. return http.HttpResponseBadRequest(render_exception(e)) search_results['total_pages'] = int( math.ceil(search_results['total'] / float(results_per_page))) search_results['total_count'] = search_results['total'] context['query'] = search_results return render(request, 'signature/signature_comments.html', context)
def signature_report(request, params, default_context=None): context = default_context signature = request.GET.get('signature') if not signature: return http.HttpResponseBadRequest( '"signature" parameter is mandatory' ) context['signature'] = signature fields = sorted( x['name'] for x in SuperSearchFields().get().values() if x['is_exposed'] and x['is_returned'] and has_permissions(request.user, x['permissions_needed']) and x['name'] != 'signature' # exclude the signature field ) context['fields'] = [ {'id': field, 'text': field.replace('_', ' ')} for field in fields ] columns = request.GET.getlist('_columns') columns = [x for x in columns if x in fields] context['columns'] = columns or DEFAULT_COLUMNS sort = request.GET.getlist('_sort') sort = [x for x in sort if x in fields] context['sort'] = sort or DEFAULT_SORT context['channels'] = ','.join(settings.CHANNELS).split(',') context['channel'] = settings.CHANNEL context['report_list_query_string'] = urlencode_obj( utils.sanitize_dict( get_report_list_parameters(params) ) ) return render(request, 'signature/signature_report.html', context)
def make_query_string(**kwargs): return urlencode_obj(kwargs)
def signature_reports(request, params): '''Return the results of a search. ''' signature = params['signature'][0] context = {} context['query'] = {'total': 0, 'total_count': 0, 'total_pages': 0} allowed_fields = get_allowed_fields(request.user) current_query = request.GET.copy() if 'page' in current_query: del current_query['page'] context['params'] = current_query.copy() if '_sort' in context['params']: del context['params']['_sort'] if '_columns' in context['params']: del context['params']['_columns'] context['sort'] = request.GET.getlist('_sort') context['columns'] = request.GET.getlist('_columns') or DEFAULT_COLUMNS # Make sure only allowed fields are used. context['sort'] = [ x for x in context['sort'] if x in allowed_fields or ( x.startswith('-') and x[1:] in allowed_fields) ] context['columns'] = [x for x in context['columns'] if x in allowed_fields] params['_sort'] = context['sort'] # Copy the list of columns so that they can differ. params['_columns'] = list(context['columns']) # The uuid is always displayed in the UI so we need to make sure it is # always returned by the model. if 'uuid' not in params['_columns']: params['_columns'].append('uuid') # We require the cpu_info field to show a special marker on some AMD CPU # related crash reports. if 'cpu_info' not in params['_columns']: params['_columns'].append('cpu_info') # The `uuid` field is a special case, it is always displayed in the first # column of the table. Hence we do not want to show it again in the # auto-generated list of columns, so we its name from the list of # columns to display. if 'uuid' in context['columns']: context['columns'].remove('uuid') 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 context['current_page'] = current_page context['results_offset'] = results_per_page * (current_page - 1) params['signature'] = '=' + signature params['_results_number'] = results_per_page params['_results_offset'] = context['results_offset'] params['_facets'] = [] # We don't need no facets. context['current_url'] = '%s?%s' % (reverse('signature:signature_report'), urlencode_obj(current_query)) api = SuperSearchUnredacted() try: search_results = api.get(**params) except BadArgumentError as e: # We need to return the error message in some HTML form for jQuery to # pick it up. return http.HttpResponseBadRequest(render_exception(e)) search_results['total_pages'] = int( math.ceil(search_results['total'] / float(results_per_page))) search_results['total_count'] = search_results['total'] context['query'] = search_results return render(request, 'signature/signature_reports.html', context)
def search_results(request): '''Return the results of a search. ''' try: params = get_params(request) except ValidationError as e: # There was an error in the form, let's return it. return http.HttpResponseBadRequest(str(e)) context = {} context['query'] = { 'total': 0, 'total_count': 0, 'total_pages': 0 } current_query = request.GET.copy() if 'page' in current_query: del current_query['page'] context['params'] = current_query.copy() if '_columns' in context['params']: del context['params']['_columns'] if '_facets' in context['params']: del context['params']['_facets'] context['sort'] = list(params['_sort']) # Copy the list of columns so that they can differ. context['columns'] = list(params['_columns']) # The `uuid` field is a special case, it is always displayed in the first # column of the table. Hence we do not want to show it again in the # auto-generated list of columns, so we remove it from the list of # columns to display. if 'uuid' in context['columns']: context['columns'].remove('uuid') 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 context['current_page'] = current_page context['results_offset'] = results_per_page * (current_page - 1) params['_results_number'] = results_per_page params['_results_offset'] = context['results_offset'] context['current_url'] = '%s?%s' % ( reverse('supersearch.search'), urlencode_obj(current_query) ) api = SuperSearchUnredacted() try: search_results = api.get(**params) except BadArgumentError as exception: # We need to return the error message in some HTML form for jQuery to # pick it up. return http.HttpResponseBadRequest( render_exception(exception) ) 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] # most recent bugs first hit['bugs'].sort(reverse=True) search_results['total_pages'] = int(math.ceil( search_results['total'] / float(results_per_page))) search_results['total_count'] = search_results['total'] context['query'] = search_results return render(request, 'supersearch/search_results.html', context)
def signature_reports(request, params): '''Return the results of a search. ''' signature = params['signature'][0] context = {} context['query'] = { 'total': 0, 'total_count': 0, 'total_pages': 0 } allowed_fields = get_allowed_fields(request.user) current_query = request.GET.copy() if 'page' in current_query: del current_query['page'] context['params'] = current_query.copy() if '_sort' in context['params']: del context['params']['_sort'] if '_columns' in context['params']: del context['params']['_columns'] context['sort'] = request.GET.getlist('_sort') context['columns'] = request.GET.getlist('_columns') or DEFAULT_COLUMNS # Make sure only allowed fields are used. context['sort'] = [ x for x in context['sort'] if x in allowed_fields or (x.startswith('-') and x[1:] in allowed_fields) ] context['columns'] = [ x for x in context['columns'] if x in allowed_fields ] params['_sort'] = context['sort'] # Copy the list of columns so that they can differ. params['_columns'] = list(context['columns']) # The uuid is always displayed in the UI so we need to make sure it is # always returned by the model. if 'uuid' not in params['_columns']: params['_columns'].append('uuid') # We require the cpu_info field to show a special marker on some AMD CPU # related crash reports. if 'cpu_info' not in params['_columns']: params['_columns'].append('cpu_info') # The `uuid` field is a special case, it is always displayed in the first # column of the table. Hence we do not want to show it again in the # auto-generated list of columns, so we its name from the list of # columns to display. if 'uuid' in context['columns']: context['columns'].remove('uuid') 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 context['current_page'] = current_page context['results_offset'] = results_per_page * (current_page - 1) params['signature'] = '=' + signature params['_results_number'] = results_per_page params['_results_offset'] = context['results_offset'] params['_facets'] = [] # We don't need no facets. context['current_url'] = '%s?%s' % ( reverse('signature:signature_report'), urlencode_obj(current_query) ) api = SuperSearchUnredacted() try: search_results = api.get(**params) except BadArgumentError as e: # We need to return the error message in some HTML form for jQuery to # pick it up. return http.HttpResponseBadRequest(render_exception(e)) search_results['total_pages'] = int( math.ceil( search_results['total'] / float(results_per_page) ) ) search_results['total_count'] = search_results['total'] context['query'] = search_results return render(request, 'signature/signature_reports.html', context)
def search_results(request): '''Return the results of a search. ''' try: params = get_params(request) except ValidationError as e: # There was an error in the form, let's return it. return http.HttpResponseBadRequest(str(e)) context = {} context['query'] = {'total': 0, 'total_count': 0, 'total_pages': 0} current_query = request.GET.copy() if 'page' in current_query: del current_query['page'] context['params'] = current_query.copy() if '_columns' in context['params']: del context['params']['_columns'] if '_facets' in context['params']: del context['params']['_facets'] context['sort'] = list(params['_sort']) # Copy the list of columns so that they can differ. context['columns'] = list(params['_columns']) # The `uuid` field is a special case, it is always displayed in the first # column of the table. Hence we do not want to show it again in the # auto-generated list of columns, so we remove it from the list of # columns to display. if 'uuid' in context['columns']: context['columns'].remove('uuid') 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 context['current_page'] = current_page context['results_offset'] = results_per_page * (current_page - 1) params['_results_number'] = results_per_page params['_results_offset'] = context['results_offset'] context['current_url'] = '%s?%s' % (reverse('supersearch.search'), urlencode_obj(current_query)) api = SuperSearchUnredacted() try: search_results = api.get(**params) except BadArgumentError as exception: # We need to return the error message in some HTML form for jQuery to # pick it up. return http.HttpResponseBadRequest(render_exception(exception)) 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] # most recent bugs first hit['bugs'].sort(reverse=True) search_results['total_pages'] = int( math.ceil(search_results['total'] / float(results_per_page))) search_results['total_count'] = search_results['total'] context['query'] = search_results return render(request, 'supersearch/search_results.html', context)