本文整理汇总了Python中sentry.plugins.helpers.get_option函数的典型用法代码示例。如果您正苦于以下问题:Python get_option函数的具体用法?Python get_option怎么用?Python get_option使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_option函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manage_project
def manage_project(request, project):
result = plugins.first('has_perm', request.user, 'edit_project', project)
if result is False and not request.user.has_perm('sentry.can_change_project'):
return HttpResponseRedirect(reverse('sentry'))
# XXX: We probably shouldnt allow changing the team unless they're the project owner
team_list = Team.objects.get_for_user(project.owner or request.user, MEMBER_OWNER)
if request.user.has_perm('sentry.can_change_project'):
form_cls = EditProjectAdminForm
else:
form_cls = EditProjectForm
form = form_cls(request, team_list, request.POST or None, instance=project, initial={
'origins': '\n'.join(get_option('sentry:origins', project) or []),
'owner': project.owner,
})
if form.is_valid():
project = form.save()
set_option('sentry:origins', form.cleaned_data.get('origins') or [], project)
return HttpResponseRedirect(request.path + '?success=1')
context = csrf(request)
context.update({
'can_remove_project': can_remove_project(request.user, project),
'page': 'details',
'form': form,
'project': project,
'TEAM_LIST': team_list.values(),
'SECTION': 'settings',
})
return render_to_response('sentry/projects/manage.html', context, request)
示例2: test_get_option_with_project
def test_get_option_with_project(self):
with mock.patch('sentry.models.ProjectOption.objects.get_value') as get_value:
project = mock.Mock()
result = get_option('key', project)
self.assertEquals(result, get_value.return_value)
get_value.assert_called_once_with(project, 'key', None)
示例3: test_run_check_update_task_with_bad_response
def test_run_check_update_task_with_bad_response(self):
with mock.patch('sentry.tasks.check_update.fetch_url_content') as fetch:
fetch.return_value = (None, None, '')
check_update() # latest_version == current_version
fetch.assert_called_once_with(PYPI_URL)
self.assertEqual(get_option(key=self.KEY), None)
示例4: test_run_check_update_task
def test_run_check_update_task(self, safe_urlread, safe_urlopen):
safe_urlread.return_value = json.dumps({'info': {'version': self.NEW}})
check_update() # latest_version > current_version
safe_urlopen.assert_called_once_with(PYPI_URL)
safe_urlread.assert_called_once_with(safe_urlopen.return_value)
self.assertEqual(get_option(key=self.KEY), self.NEW)
示例5: test_run_check_update_task
def test_run_check_update_task(self):
with mock.patch('sentry.tasks.check_update.fetch_url_content') as fetch:
fetch.return_value = (
None, None, json.dumps({'info': {'version': self.NEW}})
)
check_update() # latest_version > current_version
fetch.assert_called_once_with(PYPI_URL)
self.assertEqual(get_option(key=self.KEY), self.NEW)
示例6: test_run_check_update_task_with_bad_response
def test_run_check_update_task_with_bad_response(self, safe_urlread,
safe_urlopen):
safe_urlread.return_value = ''
check_update() # latest_version == current_version
safe_urlopen.assert_called_once_with(PYPI_URL)
safe_urlread.assert_called_once_with(safe_urlopen.return_value)
self.assertEqual(get_option(key=self.KEY), None)
示例7: get_option
def get_option(self, key, project=None, user=None):
"""
Returns the value of an option in your plugins keyspace, or ``None`` if
one is not present.
If ``project`` is passed, it will limit the scope to that project's keyspace.
>>> value = plugin.get_option('my_option')
"""
from sentry.plugins.helpers import get_option
return get_option(self._get_option_key(key), project, user)
示例8: get_origins
def get_origins(project=None):
if settings.ALLOW_ORIGIN == '*':
return '*'
elif settings.ALLOW_ORIGIN:
result = settings.ALLOW_ORIGIN.split(' ')
else:
result = []
if project:
optval = get_option('sentry:origins', project)
if optval:
result.extend(map(lambda x: x.lower(), optval))
return frozenset(filter(bool, result))
示例9: is_valid_origin
def is_valid_origin(origin, project=None):
if settings.ALLOW_ORIGIN == '*':
return True
origin = origin.lower()
if origin in (settings.ALLOW_ORIGIN or '').split(' '):
return True
if not project:
return False
optval = get_option('sentry:origins', project)
if not optval:
return False
return origin not in itertools.imap(unicode.lower, unicode(optval))
示例10: get_origins
def get_origins(project=None):
# TODO: we should cache this
if settings.ALLOW_ORIGIN == '*':
return frozenset(['*'])
elif settings.ALLOW_ORIGIN:
result = settings.ALLOW_ORIGIN.split(' ')
else:
result = []
if project:
optval = get_option('sentry:origins', project)
if optval:
result.extend(optval)
# lowercase and strip the trailing slash from all origin values
# filter out empty values
return frozenset(filter(bool, map(lambda x: x.lower().rstrip('/'), result)))
示例11: apply_access_control_headers
def apply_access_control_headers(response, project=None):
"""
Provides the Access-Control headers to enable cross-site HTTP requests. You
can find more information about these headers here:
https://developer.mozilla.org/En/HTTP_access_control#Simple_requests
"""
origin = settings.ALLOW_ORIGIN or ''
if project and origin is not '*':
optval = get_option('sentry:origins', project)
if optval:
origin = ('%s %s' % (origin, ' '.join(optval))).strip()
if origin:
response['Access-Control-Allow-Origin'] = origin
response['Access-Control-Allow-Headers'] = 'X-Sentry-Auth, Authentication'
response['Access-Control-Allow-Methods'] = 'POST'
return response
示例12: manage_project
def manage_project(request, project):
result = plugins.first("has_perm", request.user, "edit_project", project)
if result is False and not request.user.has_perm("sentry.can_change_project"):
return HttpResponseRedirect(reverse("sentry"))
team_list = Team.objects.get_for_user(request.user, MEMBER_OWNER)
if request.user.has_perm("sentry.can_change_project"):
form_cls = EditProjectAdminForm
else:
form_cls = EditProjectForm
form = form_cls(
request,
team_list,
request.POST or None,
instance=project,
initial={"origins": "\n".join(get_option("sentry:origins", project) or []), "owner": project.owner},
)
if form.is_valid():
project = form.save()
set_option("sentry:origins", form.cleaned_data.get("origins") or [], project)
return HttpResponseRedirect(request.path + "?success=1")
if not project.team:
member_list = []
else:
member_list = [(tm, tm.user) for tm in project.team.member_set.select_related("user")]
context = csrf(request)
context.update(
{
"can_remove_project": can_remove_project(request.user, project),
"page": "details",
"form": form,
"project": project,
"member_list": member_list,
"TEAM_LIST": team_list.values(),
}
)
return render_to_response("sentry/projects/manage.html", context, request)
示例13: manage_project
def manage_project(request, team, project):
result = plugins.first('has_perm', request.user, 'edit_project', project)
if result is False and not request.user.has_perm('sentry.can_change_project'):
return HttpResponseRedirect(reverse('sentry'))
# XXX: We probably shouldnt allow changing the team unless they're the project owner
team_list = Team.objects.get_for_user(project.owner or request.user, MEMBER_OWNER)
can_admin_project = request.user == project.owner or request.user.has_perm('sentry.can_change_project')
if can_admin_project:
form_cls = EditProjectAdminForm
else:
form_cls = EditProjectForm
form = form_cls(request, team_list, request.POST or None, instance=project, initial={
'origins': '\n'.join(get_option('sentry:origins', project) or []),
'owner': project.owner,
})
if form.is_valid():
project = form.save()
set_option('sentry:origins', form.cleaned_data.get('origins') or [], project)
messages.add_message(request, messages.SUCCESS,
_('Changes to your project were saved.'))
return HttpResponseRedirect(reverse('sentry-manage-project', args=[team.slug, project.slug]))
context = csrf(request)
context.update({
'team': team,
'can_remove_project': can_remove_project(request.user, project),
'page': 'details',
'form': form,
'project': project,
'SECTION': 'team',
'SUBSECTION': 'projects'
})
return render_to_response('sentry/projects/manage.html', context, request)
示例14: manage_project
def manage_project(request, project):
result = plugins.first('has_perm', request.user, 'edit_project', project)
if result is False and not request.user.has_perm('sentry.can_change_project'):
return HttpResponseRedirect(reverse('sentry'))
team_list = Team.objects.get_for_user(request.user, MEMBER_OWNER)
if request.user.has_perm('sentry.can_change_project'):
form_cls = EditProjectAdminForm
else:
form_cls = EditProjectForm
form = form_cls(request, team_list, request.POST or None, instance=project, initial={
'origins': '\n'.join(get_option('sentry:origins', project) or []),
'owner': project.owner,
})
if form.is_valid():
project = form.save()
set_option('sentry:origins', form.cleaned_data.get('origins') or [], project)
return HttpResponseRedirect(request.path + '?success=1')
if not project.team:
member_list = []
else:
member_list = [(tm, tm.user) for tm in project.team.member_set.select_related('user')]
context = csrf(request)
context.update({
'can_remove_project': can_remove_project(request.user, project),
'page': 'details',
'form': form,
'project': project,
'member_list': member_list,
'TEAM_LIST': team_list.values(),
})
return render_to_response('sentry/projects/manage.html', context, request)
示例15: test_set_sentry_version_empty_latest
def test_set_sentry_version_empty_latest(self):
set_sentry_version(latest=self.NEW)
self.assertEqual(get_option(key=self.KEY), self.NEW)