本文整理汇总了Python中sentry.constants.TAG_LABELS类的典型用法代码示例。如果您正苦于以下问题:Python TAG_LABELS类的具体用法?Python TAG_LABELS怎么用?Python TAG_LABELS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TAG_LABELS类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_attrs
def get_attrs(self, item_list, user):
from sentry.plugins import plugins
GroupMeta.objects.populate_cache(item_list)
attach_foreignkey(item_list, Group.project, ["team"])
if user.is_authenticated() and item_list:
bookmarks = set(
GroupBookmark.objects.filter(user=user, group__in=item_list).values_list("group_id", flat=True)
)
seen_groups = dict(
GroupSeen.objects.filter(user=user, group__in=item_list).values_list("group_id", "last_seen")
)
else:
bookmarks = set()
seen_groups = {}
tag_counts = defaultdict(dict)
tag_results = GroupTagKey.objects.filter(group__in=item_list).values_list("key", "group", "values_seen")
for key, group_id, values_seen in tag_results:
tag_counts[key][group_id] = values_seen
assignees = dict(
(a.group_id, a.user) for a in GroupAssignee.objects.filter(group__in=item_list).select_related("user")
)
result = {}
for item in item_list:
active_date = item.active_at or item.last_seen
tags = {}
for key in tag_counts.iterkeys():
label = TAG_LABELS.get(key, key.replace("_", " ")).lower()
try:
value = tag_counts[key].get(item.id, 0)
except KeyError:
value = 0
tags[key] = {"label": label, "count": value}
annotations = []
for plugin in plugins.for_project(project=item.project, version=1):
safe_execute(plugin.tags, None, item, annotations)
for plugin in plugins.for_project(project=item.project, version=2):
annotations.extend(safe_execute(plugin.get_annotations, item) or ())
result[item] = {
"assigned_to": serialize(assignees.get(item.id)),
"is_bookmarked": item.id in bookmarks,
"has_seen": seen_groups.get(item.id, active_date) > active_date,
"tags": tags,
"annotations": annotations,
}
return result
示例2: get_attrs
def get_attrs(self, item_list, user):
attach_foreignkey(item_list, Group.project, ['team'])
if user.is_authenticated() and item_list:
bookmarks = set(GroupBookmark.objects.filter(
user=user,
group__in=item_list,
).values_list('group_id', flat=True))
seen_groups = dict(GroupSeen.objects.filter(
user=user,
group__in=item_list,
).values_list('group_id', 'last_seen'))
else:
bookmarks = set()
seen_groups = {}
tag_counts = defaultdict(dict)
tag_results = GroupTagKey.objects.filter(
group__in=item_list,
).values_list('key', 'group', 'values_seen')
for key, group_id, values_seen in tag_results:
tag_counts[key][group_id] = values_seen
assignees = dict(
(a.group_id, a.user)
for a in GroupAssignee.objects.filter(
group__in=item_list,
).select_related('user')
)
result = {}
for item in item_list:
active_date = item.active_at or item.last_seen
tags = {}
for key in tag_counts.iterkeys():
label = TAG_LABELS.get(key, key.replace('_', ' ')).lower()
try:
value = tag_counts[key].get(item.id, 0)
except KeyError:
value = 0
tags[key] = {
'label': label,
'count': value,
}
result[item] = {
'assigned_to': serialize(assignees.get(item.id)),
'is_bookmarked': item.id in bookmarks,
'has_seen': seen_groups.get(item.id, active_date) > active_date,
'tags': tags,
}
return result
示例3: attach_metadata
def attach_metadata(self, objects, request=None):
from sentry.templatetags.sentry_plugins import handle_before_events
attach_foreignkey(objects, Group.project, ["team"])
if request and objects:
handle_before_events(request, objects)
if request and request.user.is_authenticated() and objects:
bookmarks = set(
GroupBookmark.objects.filter(user=request.user, group__in=objects).values_list("group_id", flat=True)
)
seen_groups = dict(
GroupSeen.objects.filter(user=request.user, group__in=objects).values_list("group_id", "last_seen")
)
else:
bookmarks = set()
seen_groups = {}
if objects:
historical_data = Group.objects.get_chart_data_for_group(instances=objects, max_days=1, key="group")
else:
historical_data = {}
project_list = set(o.project for o in objects)
tag_keys = set(["sentry:user"])
project_annotations = {}
for project in project_list:
enabled_annotations = ProjectOption.objects.get_value(project, "annotations", ["sentry:user"])
project_annotations[project] = enabled_annotations
tag_keys.update(enabled_annotations)
annotation_counts = defaultdict(dict)
annotation_results = GroupTagKey.objects.filter(group__in=objects, key__in=tag_keys).values_list(
"key", "group", "values_seen"
)
for key, group_id, values_seen in annotation_results:
annotation_counts[key][group_id] = values_seen
for g in objects:
g.is_bookmarked = g.pk in bookmarks
g.historical_data = [x[1] for x in historical_data.get(g.id, [])]
active_date = g.active_at or g.last_seen
g.has_seen = seen_groups.get(g.id, active_date) > active_date
g.annotations = []
for key in sorted(tag_keys):
if key in project_annotations[project]:
label = TAG_LABELS.get(key, key.replace("_", " ")).lower() + "s"
try:
value = annotation_counts[key].get(g.id, 0)
except KeyError:
value = 0
g.annotations.append({"label": label, "count": value})
示例4: attach_metadata
def attach_metadata(self, objects, user):
attach_foreignkey(objects, Group.project, ['team'])
# if request and objects:
# handle_before_events(request, objects)
if user.is_authenticated() and objects:
bookmarks = set(GroupBookmark.objects.filter(
user=user,
group__in=objects,
).values_list('group_id', flat=True))
seen_groups = dict(GroupSeen.objects.filter(
user=user,
group__in=objects,
).values_list('group_id', 'last_seen'))
else:
bookmarks = set()
seen_groups = {}
project_list = set(o.project for o in objects)
tag_keys = set(['sentry:user'])
project_annotations = {}
for project in project_list:
enabled_annotations = ProjectOption.objects.get_value(
project, 'annotations', ['sentry:user'])
project_annotations[project] = enabled_annotations
tag_keys.update(enabled_annotations)
annotation_counts = defaultdict(dict)
annotation_results = GroupTagKey.objects.filter(
group__in=objects,
key__in=tag_keys,
).values_list('key', 'group', 'values_seen')
for key, group_id, values_seen in annotation_results:
annotation_counts[key][group_id] = values_seen
for g in objects:
g.is_bookmarked = g.pk in bookmarks
active_date = g.active_at or g.last_seen
g.has_seen = seen_groups.get(g.id, active_date) > active_date
g.annotations = []
for key in sorted(tag_keys):
if key in project_annotations[project]:
label = TAG_LABELS.get(key, key.replace('_', ' ')).lower() + 's'
try:
value = annotation_counts[key].get(g.id, 0)
except KeyError:
value = 0
g.annotations.append({
'label': label,
'count': value,
})
示例5: __init__
def __init__(self, project, tag_list, *args, **kwargs):
self.project = project
super(ProjectTagsForm, self).__init__(*args, **kwargs)
tag_choices = []
for tag in tag_list:
tag_choices.append(
(tag, TAG_LABELS.get(tag) or tag.replace(u'_', u' ').title())
)
for field in ('filters', 'annotations'):
self.fields[field].choices = tag_choices
self.fields[field].widget.choices = self.fields[field].choices
enabled_filters = ProjectOption.objects.get_value(
self.project, 'tags', tag_list)
self.fields['filters'].initial = enabled_filters
enable_annotations = ProjectOption.objects.get_value(
self.project, 'annotations', ['sentry:user'])
self.fields['annotations'].initial = enable_annotations
示例6: get_filters
def get_filters(project, request):
filter_list = []
for class_path in settings.SENTRY_FILTERS:
try:
filter_cls = import_string(class_path)
except Exception:
logger = logging.getLogger('sentry.errors')
logger.exception('Unable to import %s', class_path)
continue
filter_list.append(filter_cls(request, project))
for tag in project.get_tags():
filter_list.append(Filter(
column=tag,
label=TAG_LABELS.get(tag) or tag.replace('_', ' ').title(),
request=request,
project=project,
))
return filter_list
示例7: get_label
def get_label(self):
return self.label \
or TAG_LABELS.get(self.key) \
or self.key.replace('_', ' ').title()
示例8: get_attrs
def get_attrs(self, item_list, user):
attach_foreignkey(item_list, Group.project, ['team'])
if user.is_authenticated() and item_list:
bookmarks = set(GroupBookmark.objects.filter(
user=user,
group__in=item_list,
).values_list('group_id', flat=True))
seen_groups = dict(GroupSeen.objects.filter(
user=user,
group__in=item_list,
).values_list('group_id', 'last_seen'))
else:
bookmarks = set()
seen_groups = {}
tag_counts = defaultdict(dict)
tag_results = GroupTagKey.objects.filter(
group__in=item_list,
).values_list('key', 'group', 'values_seen')
for key, group_id, values_seen in tag_results:
tag_counts[key][group_id] = values_seen
# we need to compute stats at 1d (1h resolution), and 14d/30d (1 day res)
group_ids = [g.id for g in item_list]
now = timezone.now()
hourly_stats = tsdb.get_range(
model=tsdb.models.group,
keys=group_ids,
end=now,
start=now - timedelta(days=1),
rollup=3600,
)
daily_stats = tsdb.get_range(
model=tsdb.models.group,
keys=group_ids,
end=now,
start=now - timedelta(days=30),
rollup=3600 * 24,
)
result = {}
for item in item_list:
active_date = item.active_at or item.last_seen
tags = {}
for key in tag_counts.iterkeys():
label = TAG_LABELS.get(key, key.replace('_', ' ')).lower()
try:
value = tag_counts[key].get(item.id, 0)
except KeyError:
value = 0
tags[key] = {
'label': label,
'count': value,
}
result[item] = {
'is_bookmarked': item.id in bookmarks,
'has_seen': seen_groups.get(item.id, active_date) > active_date,
'tags': tags,
'hourly_stats': hourly_stats[item.id],
'daily_stats': daily_stats[item.id],
}
return result
示例9: attach_metadata
def attach_metadata(self, objects, request=None):
from sentry.templatetags.sentry_plugins import handle_before_events
attach_foreignkey(objects, Group.project, ['team'])
GroupMeta.objects.populate_cache(objects)
if request and objects:
handle_before_events(request, objects)
if request and request.user.is_authenticated() and objects:
bookmarks = set(GroupBookmark.objects.filter(
user=request.user,
group__in=objects,
).values_list('group_id', flat=True))
seen_groups = dict(GroupSeen.objects.filter(
user=request.user,
group__in=objects,
).values_list('group_id', 'last_seen'))
else:
bookmarks = set()
seen_groups = {}
if objects:
end = timezone.now()
start = end - timedelta(days=1)
historical_data = tsdb.get_range(
model=tsdb.models.group,
keys=[g.id for g in objects],
start=start,
end=end,
)
else:
historical_data = {}
project_list = set(o.project for o in objects)
tag_keys = set(['sentry:user'])
project_annotations = {}
for project in project_list:
enabled_annotations = ProjectOption.objects.get_value(
project, 'annotations', ['sentry:user'])
project_annotations[project] = enabled_annotations
tag_keys.update(enabled_annotations)
annotation_counts = defaultdict(dict)
annotation_results = GroupTagKey.objects.filter(
group__in=objects,
key__in=tag_keys,
).values_list('key', 'group', 'values_seen')
for key, group_id, values_seen in annotation_results:
annotation_counts[key][group_id] = values_seen
for g in objects:
g.is_bookmarked = g.pk in bookmarks
g.historical_data = [x[1] for x in historical_data.get(g.id, [])]
active_date = g.active_at or g.last_seen
g.has_seen = seen_groups.get(g.id, active_date) > active_date
g.annotations = []
for key in sorted(tag_keys):
if key in project_annotations[project]:
label = TAG_LABELS.get(key, key.replace('_', ' ')).lower() + 's'
try:
value = annotation_counts[key].get(g.id, 0)
except KeyError:
value = 0
g.annotations.append({
'label': label,
'count': value,
})
示例10: get_tag_key_label
def get_tag_key_label(self, key):
return TAG_LABELS.get(key) or key.replace('_', ' ').title()
示例11: get_label
def get_label(self):
return self.label or TAG_LABELS.get(self.key) or self.key.replace("_", " ").title()
示例12: get_attrs
def get_attrs(self, item_list, user):
from sentry.plugins import plugins
GroupMeta.objects.populate_cache(item_list)
attach_foreignkey(item_list, Group.project, ['team'])
if user.is_authenticated() and item_list:
bookmarks = set(GroupBookmark.objects.filter(
user=user,
group__in=item_list,
).values_list('group_id', flat=True))
seen_groups = dict(GroupSeen.objects.filter(
user=user,
group__in=item_list,
).values_list('group_id', 'last_seen'))
else:
bookmarks = set()
seen_groups = {}
tag_counts = defaultdict(dict)
tag_results = GroupTagKey.objects.filter(
group__in=item_list,
).values_list('key', 'group', 'values_seen')
for key, group_id, values_seen in tag_results:
tag_counts[key][group_id] = values_seen
assignees = dict(
(a.group_id, a.user)
for a in GroupAssignee.objects.filter(
group__in=item_list,
).select_related('user')
)
result = {}
for item in item_list:
active_date = item.active_at or item.last_seen
tags = {}
for key in tag_counts.iterkeys():
label = TAG_LABELS.get(key, key.replace('_', ' ')).lower()
try:
value = tag_counts[key].get(item.id, 0)
except KeyError:
value = 0
tags[key] = {
'label': label,
'count': value,
}
annotations = []
for plugin in plugins.for_project(project=item.project, version=1):
safe_execute(plugin.tags, None, item, annotations)
for plugin in plugins.for_project(project=item.project, version=2):
annotations.extend(safe_execute(plugin.get_annotations, item) or ())
result[item] = {
'assigned_to': serialize(assignees.get(item.id)),
'is_bookmarked': item.id in bookmarks,
'has_seen': seen_groups.get(item.id, active_date) > active_date,
'tags': tags,
'annotations': annotations,
}
return result