本文整理汇总了Python中sentry.api.serializers.serialize函数的典型用法代码示例。如果您正苦于以下问题:Python serialize函数的具体用法?Python serialize怎么用?Python serialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serialize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, request, share_id):
"""
Retrieve an aggregate
Return details on an individual aggregate specified by it's shared ID.
{method} {path}
Note: This is not the equivilant of what you'd receive with the standard
group details endpoint. Data is more restrictive and designed
specifically for sharing.
"""
try:
group = Group.from_share_id(share_id)
except Group.DoesNotExist:
raise ResourceDoesNotExist
if group.organization.flags.disable_shared_issues:
raise ResourceDoesNotExist
event = group.get_latest_event()
context = serialize(group, request.user, SharedGroupSerializer())
context['latestEvent'] = serialize(event, request.user, SharedEventSerializer())
# TODO(dcramer): use specific serializer for public group and embed
# event details as part of api response
return Response(context)
示例2: get_attrs
def get_attrs(self, item_list, user):
# TODO(dcramer); assert on relations
users = {
d['id']: d
for d in serialize(set(i.user for i in item_list if i.user_id), user)
}
commit_ids = {
i.data['commit']
for i in item_list
if i.type == Activity.SET_RESOLVED_IN_COMMIT
}
if commit_ids:
commit_list = list(Commit.objects.filter(id__in=commit_ids))
commits_by_id = {
c.id: d
for c, d in zip(commit_list, serialize(commit_list, user))
}
commits = {
i: commits_by_id.get(i.data['commit'])
for i in item_list
if i.type == Activity.SET_RESOLVED_IN_COMMIT
}
else:
commits = {}
return {
item: {
'user': users[six.text_type(item.user_id)] if item.user_id else None,
'commit': commits.get(item),
} for item in item_list
}
示例3: test_simple
def test_simple(self):
user = self.create_user(username='foo')
organization = self.create_organization(owner=user)
team = self.create_team(organization=organization)
project = self.create_project(teams=[team], organization=organization, name='foo')
project2 = self.create_project(teams=[team], organization=organization, name='bar')
result = serialize(team, user, TeamWithProjectsSerializer())
serialized_projects = serialize([project2, project], user)
assert result == {
'slug': team.slug,
'name': team.name,
'hasAccess': True,
'isPending': False,
'isMember': False,
'id': six.text_type(team.id),
'projects': serialized_projects,
'avatar': {
'avatarType': 'letter_avatar',
'avatarUuid': None,
},
'memberCount': 0,
'dateCreated': team.date_added,
}
示例4: get
def get(self, request, organization_slug):
organization = Organization.objects.get_from_cache(
slug=organization_slug,
)
assert_perm(organization, request.user, request.auth)
team_list = Team.objects.get_for_user(
organization=organization,
user=request.user,
)
project_list = []
for team in team_list:
project_list.extend(Project.objects.get_for_user(
team=team,
user=request.user,
))
project_list.sort(key=lambda x: x.name)
team_map = dict(
(t.id, c) for (t, c) in zip(team_list, serialize(team_list, request.user)),
)
context = []
for project, pdata in zip(project_list, serialize(project_list, request.user)):
pdata['team'] = team_map[project.team_id]
context.append(pdata)
return Response(context)
示例5: get
def get(self, request, organization):
"""
List an organization's projects
Return a list of projects bound to a organization.
{method} {path}
"""
team_list = Team.objects.get_for_user(
organization=organization,
user=request.user,
)
project_list = []
for team in team_list:
project_list.extend(Project.objects.get_for_user(
team=team,
user=request.user,
))
project_list.sort(key=lambda x: x.name)
team_map = dict(
(t.id, c) for (t, c) in zip(team_list, serialize(team_list, request.user)),
)
context = []
for project, pdata in zip(project_list, serialize(project_list, request.user)):
pdata['team'] = team_map[project.team_id]
context.append(pdata)
return Response(context)
示例6: test_simple
def test_simple(self):
projects_ids = [self.project.id, self.project_2.id]
org_members = list(self.org.member_set.filter(
user__in=[
self.owner_user,
self.user_2,
],
).order_by('user__email'))
result = serialize(
org_members,
self.user_2,
OrganizationMemberWithProjectsSerializer(project_ids=projects_ids),
)
expected_projects = [
[self.project.slug, self.project_2.slug],
[self.project.slug]
]
expected_projects[0].sort()
assert [r['projects'] for r in result] == expected_projects
projects_ids = [self.project_2.id]
result = serialize(
org_members,
self.user_2,
OrganizationMemberWithProjectsSerializer(project_ids=projects_ids),
)
expected_projects = [
[self.project_2.slug],
[],
]
assert [r['projects'] for r in result] == expected_projects
示例7: get
def get(self, request, wizard_hash=None):
"""
This tries to retrieve and return the cache content if possible
otherwise creates new cache
"""
if wizard_hash is not None:
key = '%s%s' % (SETUP_WIZARD_CACHE_KEY, wizard_hash)
wizard_data = default_cache.get(key)
if wizard_data is None:
return Response(status=404)
elif wizard_data == 'empty':
# when we just created a clean cache
return Response(status=400)
return Response(serialize(wizard_data))
else:
# This creates a new available hash url for the project wizard
rate_limited = ratelimits.is_limited(
key='rl:setup-wizard:ip:%s' % request.META['REMOTE_ADDR'],
limit=10,
)
if rate_limited:
logger.info('setup-wizard.rate-limit')
return Response(
{
'Too wizard requests',
}, status=403
)
wizard_hash = get_random_string(
64, allowed_chars='abcdefghijklmnopqrstuvwxyz012345679')
key = '%s%s' % (SETUP_WIZARD_CACHE_KEY, wizard_hash)
default_cache.set(key, 'empty', SETUP_WIZARD_CACHE_TIMEOUT)
return Response(serialize({'hash': wizard_hash}))
示例8: react_plugin_config
def react_plugin_config(plugin, project, request):
response = client.get(
'/projects/{}/{}/plugins/{}/'.format(
project.organization.slug,
project.slug,
plugin.slug,
),
request=request
)
return mark_safe(
"""
<div id="ref-plugin-config"></div>
<script>
$(function(){
ReactDOM.render(React.createFactory(Sentry.PluginConfig)({
project: %s,
organization: %s,
data: %s
}), document.getElementById('ref-plugin-config'));
});
</script>
""" % (
json.dumps_htmlsafe(serialize(project, request.user)),
json.dumps_htmlsafe(serialize(project.organization, request.user)),
json.dumps_htmlsafe(response.data)
)
)
示例9: test_environment
def test_environment(self):
group = self.group
environment = Environment.get_or_create(group.project, 'production')
from sentry.api.serializers.models.group import tsdb
with mock.patch(
'sentry.api.serializers.models.group.tsdb.get_range',
side_effect=tsdb.get_range) as get_range:
serialize(
[group],
serializer=StreamGroupSerializer(
environment_func=lambda: environment,
stats_period='14d',
),
)
assert get_range.call_count == 1
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_id'] == environment.id
def get_invalid_environment():
raise Environment.DoesNotExist()
with mock.patch(
'sentry.api.serializers.models.group.tsdb.make_series',
side_effect=tsdb.make_series) as make_series:
serialize(
[group],
serializer=StreamGroupSerializer(
environment_func=get_invalid_environment,
stats_period='14d',
)
)
assert make_series.call_count == 1
示例10: get
def get(self, request, organization):
"""
Retrieve an organization
Return details on an individual organization including various details
such as membership access, features, and teams.
{method} {path}
"""
team_list = list(Team.objects.filter(
organization=organization,
status=TeamStatus.VISIBLE,
))
feature_list = []
if features.has('organizations:sso', organization, actor=request.user):
feature_list.append('sso')
if getattr(organization.flags, 'allow_joinleave'):
feature_list.append('open-membership')
context = serialize(organization, request.user)
context['access'] = access.from_user(request.user, organization).scopes
context['features'] = feature_list
context['teams'] = serialize(
team_list, request.user, TeamWithProjectsSerializer())
return Response(context)
示例11: test_simple
def test_simple(self):
user = self.create_user(username='foo')
organization = self.create_organization(owner=user)
team = self.create_team(organization=organization)
project = self.create_project(teams=[team], organization=organization, name='foo')
project2 = self.create_project(teams=[team], organization=organization, name='bar')
result = serialize(team, user, TeamWithProjectsSerializer())
result.pop('dateCreated')
# don't compare dateCreated because of mysql
serialized_projects = serialize([project2, project], user)
for p in serialized_projects:
p.pop('dateCreated')
for p in result['projects']:
p.pop('dateCreated')
assert result == {
'slug': team.slug,
'name': team.name,
'hasAccess': True,
'isPending': False,
'isMember': False,
'id': six.text_type(team.id),
'projects': serialized_projects,
'avatar': {
'avatarType': 'letter_avatar',
'avatarUuid': None,
},
}
示例12: test_environment
def test_environment(self):
group = self.group
environment = Environment.get_or_create(group.project, 'production')
with mock.patch(
'sentry.api.serializers.models.group.snuba_tsdb.get_range',
side_effect=snuba_tsdb.get_range) as get_range:
serialize(
[group],
serializer=StreamGroupSerializerSnuba(
environment_ids=[environment.id],
stats_period='14d',
),
)
assert get_range.call_count == 1
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_ids'] == [environment.id]
with mock.patch(
'sentry.api.serializers.models.group.snuba_tsdb.get_range',
side_effect=snuba_tsdb.get_range) as get_range:
serialize(
[group],
serializer=StreamGroupSerializerSnuba(
environment_ids=None,
stats_period='14d',
)
)
assert get_range.call_count == 1
for args, kwargs in get_range.call_args_list:
assert kwargs['environment_ids'] is None
示例13: get
def get(self, request, project):
"""
List a Project's DSym Files
```````````````````````````
Retrieve a list of dsym files for a given project.
:pparam string organization_slug: the slug of the organization the
release belongs to.
:pparam string project_slug: the slug of the project to list the
dsym files of.
:auth: required
"""
apps = DSymApp.objects.filter(project=project)
dsym_files = VersionDSymFile.objects.filter(
dsym_app=apps
).select_related('dsym_file').order_by('-build', 'version')
file_list = ProjectDSymFile.objects.filter(
project=project,
versiondsymfile__isnull=True,
).select_related('file')[:100]
download_requested = request.GET.get('download_id') is not None
if download_requested and (request.access.has_scope('project:write')):
return self.download(request.GET.get('download_id'), project)
return Response(
{
'apps': serialize(list(apps)),
'debugSymbols': serialize(list(dsym_files)),
'unreferencedDebugSymbols': serialize(list(file_list)),
}
)
示例14: test_seen_stats
def test_seen_stats(self):
group = self.create_group(first_seen=self.week_ago, times_seen=5)
# should use group columns when no environments arg passed
result = serialize(group, serializer=GroupSerializerSnuba())
assert result['count'] == '5'
assert result['lastSeen'] == group.last_seen
assert result['firstSeen'] == group.first_seen
environment = self.create_environment(project=group.project)
environment2 = self.create_environment(project=group.project)
self.create_event(
'a' * 32, group=group, datetime=self.day_ago, tags={'environment': environment.name}
)
self.create_event(
'b' * 32, group=group, datetime=self.min_ago, tags={'environment': environment.name}
)
self.create_event(
'c' * 32, group=group, datetime=self.min_ago, tags={'environment': environment2.name}
)
result = serialize(
group, serializer=GroupSerializerSnuba(
environment_ids=[environment.id, environment2.id])
)
assert result['count'] == '3'
# result is rounded down to nearest second
assert result['lastSeen'] == self.min_ago - timedelta(microseconds=self.min_ago.microsecond)
assert result['firstSeen'] == self.day_ago - \
timedelta(microseconds=self.day_ago.microsecond)
示例15: get_payload_v0
def get_payload_v0(event):
from sentry.api.serializers import serialize
group = event.group
project = group.project
project_url_base = absolute_uri(u'/{}/{}'.format(
project.organization.slug,
project.slug,
))
group_context = serialize(group)
group_context['url'] = u'{}/issues/{}/'.format(
project_url_base,
group.id,
)
event_context = serialize(event)
event_context['url'] = u'{}/issues/{}/events/{}/'.format(
project_url_base,
group.id,
event.id,
)
data = {
'project': {
'slug': project.slug,
'name': project.name,
},
'group': group_context,
'event': event_context,
}
return data