本文整理汇总了Python中crashstats.supersearch.models.SuperSearchFields类的典型用法代码示例。如果您正苦于以下问题:Python SuperSearchFields类的具体用法?Python SuperSearchFields怎么用?Python SuperSearchFields使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SuperSearchFields类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_from_es
def get_from_es(namespace, baseline=None):
# @namespace is something like 'raw_crash' or 'processed_crash'
cache_key = 'api_supersearch_fields_%s' % namespace
fields = cache.get(cache_key)
if fields is None:
# This needs to be imported in runtime because otherwise you'll
# get a circular import.
from crashstats.supersearch.models import SuperSearchFields
all = SuperSearchFields().get()
fields = []
if baseline:
if isinstance(baseline, tuple):
baseline = list(baseline)
fields.extend(baseline)
for meta in all.itervalues():
if (
meta['namespace'] == namespace and
not meta['permissions_needed'] and
meta['is_returned']
):
if meta['in_database_name'] not in fields:
fields.append(meta['in_database_name'])
fields = tuple(fields)
# Cache for 1 hour.
cache.set(cache_key, fields, 60 * 60)
return fields
示例2: supersearch_field
def supersearch_field(request):
context = {}
field_name = request.GET.get("name")
if field_name:
all_fields = SuperSearchFields().get()
field_data = all_fields.get(field_name)
if not field_data:
return http.HttpResponseBadRequest('The field "%s" does not exist' % field_name)
else:
full_name = request.GET.get("full_name")
if full_name:
if "." not in full_name:
name = full_name
namespace = None
else:
namespace, name = full_name.rsplit(".", 1)
field_data = {"in_database_name": name, "namespace": namespace}
else:
field_data = {}
context["field"] = field_data
perms = Permission.objects.filter(content_type__model="").order_by("name")
context["all_permissions"] = ["crashstats." + x.codename for x in perms]
return render(request, "manage/supersearch_field.html", context)
示例3: get_from_es
def get_from_es(namespace, baseline=None):
# @namespace is something like 'raw_crash' or 'processed_crash'
fields = cache.get("api_supersearch_fields_%s" % namespace)
if fields is None:
# This needs to be imported in runtime because otherwise you'll
# get a circular import.
from crashstats.supersearch.models import SuperSearchFields
all = SuperSearchFields().get()
fields = []
if baseline:
if isinstance(baseline, tuple):
baseline = list(baseline)
fields.extend(baseline)
for meta in all.itervalues():
if meta["namespace"] == namespace and not meta["permissions_needed"] and meta["is_returned"]:
if meta["in_database_name"] not in fields:
fields.append(meta["in_database_name"])
fields = tuple(fields)
return fields
示例4: supersearch_field
def supersearch_field(request):
context = {}
field_name = request.GET.get('name')
if field_name:
all_fields = SuperSearchFields().get()
field_data = all_fields.get(field_name)
if not field_data:
return http.HttpResponseBadRequest(
'The field "%s" does not exist' % field_name
)
else:
field_data = {}
context['field'] = field_data
perms = Permission.objects.filter(content_type__model='').order_by('name')
context['all_permissions'] = [
'crashstats.' + x.codename for x in perms
]
return render(request, 'manage/supersearch_field.html', context)
示例5: report_index
#.........这里部分代码省略.........
if context['report']['signature'].startswith('shutdownhang'):
# For shutdownhang signatures, we want to use thread 0 as the
# crashing thread, because that's the thread that actually contains
# the useful data about what happened.
context['crashing_thread'] = 0
context['parsed_dump'] = parsed_dump
context['bug_product_map'] = settings.BUG_PRODUCT_MAP
context['bug_associations'] = list(
models.BugAssociation.objects
.filter(signature=context['report']['signature'])
.values('bug_id', 'signature')
.order_by('-bug_id')
)
context['raw_keys'] = []
if request.user.has_perm('crashstats.view_pii'):
# hold nothing back
context['raw_keys'] = context['raw'].keys()
else:
context['raw_keys'] = [
x for x in context['raw']
if x in models.RawCrash.API_ALLOWLIST()
]
# Sort keys case-insensitively
context['raw_keys'] = sorted(context['raw_keys'], key=lambda s: s.lower())
if request.user.has_perm('crashstats.view_rawdump'):
context['raw_dump_urls'] = [
reverse('crashstats:raw_data', args=(crash_id, 'dmp')),
reverse('crashstats:raw_data', args=(crash_id, 'json'))
]
if context['raw'].get('additional_minidumps'):
suffixes = [
x.strip()
for x in context['raw']['additional_minidumps'].split(',')
if x.strip()
]
for suffix in suffixes:
name = 'upload_file_minidump_%s' % (suffix,)
context['raw_dump_urls'].append(
reverse('crashstats:raw_data_named', args=(crash_id, name, 'dmp'))
)
if (
context['raw'].get('ContainsMemoryReport') and
context['report'].get('memory_report') and
not context['report'].get('memory_report_error')
):
context['raw_dump_urls'].append(
reverse('crashstats:raw_data_named', args=(crash_id, 'memory_report', 'json.gz'))
)
# Add descriptions to all fields.
all_fields = SuperSearchFields().get()
descriptions = {}
for field in all_fields.values():
key = '{}.{}'.format(field['namespace'], field['in_database_name'])
descriptions[key] = '{} Search: {}'.format(
field.get('description', '').strip() or 'No description for this field.',
field['is_exposed'] and field['name'] or 'N/A',
)
def make_raw_crash_key(key):
"""In the report_index.html template we need to create a key
that we can use to look up against the 'fields_desc' dict.
Because you can't do something like this in jinja::
{{ fields_desc.get(u'raw_crash.{}'.format(key), empty_desc) }}
we do it here in the function instead.
The trick is that the lookup key has to be a unicode object or
else you get UnicodeEncodeErrors in the template rendering.
"""
return u'raw_crash.{}'.format(key)
context['make_raw_crash_key'] = make_raw_crash_key
context['fields_desc'] = descriptions
context['empty_desc'] = 'No description for this field. Search: unknown'
context['BUG_PRODUCT_MAP'] = settings.BUG_PRODUCT_MAP
# report.addons used to be a list of lists.
# In https://bugzilla.mozilla.org/show_bug.cgi?id=1250132
# we changed it from a list of lists to a list of strings, using
# a ':' to split the name and version.
# See https://bugzilla.mozilla.org/show_bug.cgi?id=1250132#c7
# Considering legacy, let's tackle both.
# In late 2017, this code is going to be useless and can be removed.
if (
context['report'].get('addons') and
isinstance(context['report']['addons'][0], (list, tuple))
):
# This is the old legacy format. This crash hasn't been processed
# the new way.
context['report']['addons'] = [
':'.join(x) for x in context['report']['addons']
]
return render(request, 'crashstats/report_index.html', context)
示例6: report_index
#.........这里部分代码省略.........
# If the parsed_dump lacks a `parsed_dump.crash_info.crashing_thread`
# we can't loop over the frames :(
crashing_thread = parsed_dump.get('crash_info', {}).get('crashing_thread')
if crashing_thread is None:
# the template does a big `{% if parsed_dump.threads %}`
parsed_dump['threads'] = None
else:
context['crashing_thread'] = crashing_thread
if context['report']['signature'].startswith('shutdownhang'):
# For shutdownhang signatures, we want to use thread 0 as the
# crashing thread, because that's the thread that actually contains
# the usefull data about the what happened.
context['crashing_thread'] = 0
context['parsed_dump'] = parsed_dump
context['bug_product_map'] = settings.BUG_PRODUCT_MAP
process_type = 'unknown'
if context['report']['process_type'] is None:
process_type = 'browser'
elif context['report']['process_type'] == 'plugin':
process_type = 'plugin'
elif context['report']['process_type'] == 'content':
process_type = 'content'
context['process_type'] = process_type
bugs_api = models.Bugs()
hits = bugs_api.get(signatures=[context['report']['signature']])['hits']
# bugs_api.get(signatures=...) will return all signatures associated
# with the bugs found, but we only want those with matching signature
context['bug_associations'] = [
x for x in hits
if x['signature'] == context['report']['signature']
]
context['bug_associations'].sort(
key=lambda x: x['id'],
reverse=True
)
context['raw_keys'] = []
if request.user.has_perm('crashstats.view_pii'):
# hold nothing back
context['raw_keys'] = context['raw'].keys()
else:
context['raw_keys'] = [
x for x in context['raw']
if x in models.RawCrash.API_WHITELIST
]
# Sort keys case-insensitively
context['raw_keys'].sort(key=lambda s: s.lower())
if request.user.has_perm('crashstats.view_rawdump'):
context['raw_dump_urls'] = [
reverse('crashstats:raw_data', args=(crash_id, 'dmp')),
reverse('crashstats:raw_data', args=(crash_id, 'json'))
]
if context['raw'].get('additional_minidumps'):
suffixes = [
x.strip()
for x in context['raw']['additional_minidumps'].split(',')
if x.strip()
]
for suffix in suffixes:
name = 'upload_file_minidump_%s' % (suffix,)
context['raw_dump_urls'].append(
reverse(
'crashstats:raw_data_named',
args=(crash_id, name, 'dmp')
)
)
if (
context['raw'].get('ContainsMemoryReport') and
context['report'].get('memory_report') and
not context['report'].get('memory_report_error')
):
context['raw_dump_urls'].append(
reverse(
'crashstats:raw_data_named',
args=(crash_id, 'memory_report', 'json.gz')
)
)
# Add descriptions to all fields.
all_fields = SuperSearchFields().get()
descriptions = {}
for field in all_fields.values():
key = '{}.{}'.format(field['namespace'], field['in_database_name'])
descriptions[key] = '{} Search: {}'.format(
field.get('description', '').strip() or
'No description for this field.',
field['is_exposed'] and field['name'] or 'N/A',
)
context['fields_desc'] = descriptions
context['empty_desc'] = 'No description for this field. Search: unknown'
context['BUG_PRODUCT_MAP'] = settings.BUG_PRODUCT_MAP
return render(request, 'crashstats/report_index.html', context)