本文整理汇总了Python中sentry.permissions.can_create_teams函数的典型用法代码示例。如果您正苦于以下问题:Python can_create_teams函数的具体用法?Python can_create_teams怎么用?Python can_create_teams使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了can_create_teams函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dashboard
def dashboard(request, template='dashboard.html'):
team_list = Team.objects.get_for_user(request.user, with_projects=True)
if not team_list:
if can_create_teams(request.user):
return HttpResponseRedirect(reverse('sentry-new-team'))
return render_to_response('sentry/generic_error.html', {
'title': _('No Membership'),
'message': _('You are not a member of any teams in Sentry and you do not have access to create a new team.'),
}, request)
return render_to_response('sentry/select_team.html', {
'team_list': team_list.values(),
'can_create_teams': can_create_teams(request.user),
}, request)
示例2: new_project
def new_project(request):
from django.contrib.auth.models import User
if not can_create_projects(request.user):
return HttpResponseRedirect(reverse('sentry'))
allow_create_teams = can_create_teams(request.user)
team_list = Team.objects.get_for_user(request.user)
if request.user.has_perm('sentry.can_add_project') and User.objects.all()[0:2] == 2:
project_form_cls = NewProjectAdminForm
project_initial = {
'owner': request.user.username,
}
else:
project_form_cls = NewProjectForm
project_initial = {}
if len(team_list) > 0:
select_team_form = SelectTeamForm(team_list, request.POST or None, prefix='st')
elif not allow_create_teams:
return render_to_response('sentry/projects/cannot_create_teams.html', {}, request)
else:
select_team_form = None
if allow_create_teams:
new_team_form = NewTeamForm(request.POST or None, prefix='nt')
else:
new_team_form = None
project_form = project_form_cls(request.POST or None, initial=project_initial, prefix='prj')
is_new_team = new_team_form and new_team_form.is_valid()
if is_new_team or not select_team_form:
team_form = new_team_form
else:
team_form = select_team_form
if project_form.is_valid() and team_form.is_valid():
project = project_form.save(commit=False)
if not project.owner:
project.owner = request.user
if is_new_team:
team = new_team_form.save(commit=False)
team.owner = project.owner
team.save()
else:
team = select_team_form.cleaned_data['team']
project.team = team
project.save()
return HttpResponseRedirect(reverse('sentry-get-started', args=[project.slug]))
return render_to_response('sentry/projects/new.html', {
'project_form': project_form,
'select_team_form': select_team_form,
'new_team_form': new_team_form,
}, request)
示例3: get_default_context
def get_default_context(request, existing_context=None, team=None):
from sentry.plugins import plugins
context = {
'HAS_SEARCH': settings.USE_SEARCH,
'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE,
'URL_PREFIX': settings.URL_PREFIX,
'PLUGINS': plugins,
}
if request:
context.update({
'request': request,
'can_create_teams': can_create_teams(request.user),
})
if team:
context.update({
'can_admin_team': Team.objects.get_for_user(request.user, MEMBER_OWNER),
'can_create_projects': can_create_projects(request.user, team=team),
})
else:
context['can_create_projects'] = can_create_projects(request.user)
if not existing_context or 'PROJECT_LIST' not in existing_context:
project_list = Project.objects.get_for_user(request.user, team=team)
context['PROJECT_LIST'] = sorted(project_list, key=lambda x: x.name)
if not existing_context or 'TEAM_LIST' not in existing_context:
context['TEAM_LIST'] = sorted(Team.objects.get_for_user(request.user).values(), key=lambda x: x.name)
return context
示例4: post
def post(self, request, organization_slug):
organization = Organization.objects.get_from_cache(
slug=organization_slug,
)
if not can_create_teams(request.user, organization):
return Response(status=403)
serializer = TeamSerializer(data=request.DATA)
if serializer.is_valid():
result = serializer.object
team = Team.objects.create(
name=result['name'],
slug=result.get('slug'),
owner=result.get('owner') or organization.owner,
organization=organization,
)
AuditLogEntry.objects.create(
organization=organization,
actor=request.user,
ip_address=request.META['REMOTE_ADDR'],
target_object=team.id,
event=AuditLogEntryEvent.TEAM_ADD,
data=team.get_audit_log_data(),
)
return Response(serialize(team, request.user), status=201)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例5: get_default_context
def get_default_context(request, existing_context=None, team=None):
from sentry.plugins import plugins
context = {
"HAS_SEARCH": settings.USE_SEARCH,
"MESSAGES_PER_PAGE": settings.MESSAGES_PER_PAGE,
"INTERNAL_PROJECT": get_internal_project(),
"PROJECT_ID": str(settings.PROJECT),
"URL_PREFIX": settings.URL_PREFIX,
"PLUGINS": plugins,
"USE_JS_CLIENT": settings.USE_JS_CLIENT,
}
if request:
context.update(
{
"request": request,
"can_create_projects": can_create_projects(request.user),
"can_create_teams": can_create_teams(request.user),
}
)
if team:
context.update({"can_admin_team": Team.objects.get_for_user(request.user, MEMBER_OWNER)})
if not existing_context or "PROJECT_LIST" not in existing_context:
project_list = Project.objects.get_for_user(request.user, team=team)
context["PROJECT_LIST"] = sorted(project_list, key=lambda x: x.name)
if not existing_context or "TEAM_LIST" not in existing_context:
context["TEAM_LIST"] = sorted(Team.objects.get_for_user(request.user).values(), key=lambda x: x.name)
return context
示例6: dashboard
def dashboard(request, template='dashboard.html'):
team_list = Team.objects.get_for_user(request.user)
if not team_list:
if can_create_teams(request.user):
return HttpResponseRedirect(reverse('sentry-new-team'))
return render_to_response('sentry/generic_error.html', {
'title': _('No Membership'),
'message': _('You are not a member of any teams in Sentry and you do not have access to create a new team.'),
}, request)
# This cookie gets automatically set by render_to_response
if len(team_list) == 1:
team = team_list.values()[0]
return HttpResponseRedirect(reverse('sentry', args=[team.slug]))
# these kinds of queries make people sad :(
results = []
for team in sorted(team_list.itervalues(), key=lambda x: x.name):
project_list = list(team.project_set.filter(
status=STATUS_VISIBLE,
).order_by('name')[:20])
results.append((team, project_list))
return render_to_response('sentry/select_team.html', {
'team_list': results,
}, request)
示例7: get_default_context
def get_default_context(request, existing_context=None):
from sentry.plugins import plugins
context = {
'HAS_SEARCH': settings.USE_SEARCH,
'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE,
'PROJECT_ID': str(settings.PROJECT),
'VIEWS': list(View.objects.all()),
'URL_PREFIX': settings.URL_PREFIX,
'PLUGINS': plugins,
'USE_JS_CLIENT': settings.USE_JS_CLIENT,
}
if request:
context.update({
'request': request,
'can_create_projects': can_create_projects(request.user),
'can_create_teams': can_create_teams(request.user),
})
if not existing_context or 'PROJECT_LIST' not in existing_context:
context['PROJECT_LIST'] = get_project_list(request.user).values()
if not existing_context or 'TEAM_LIST' not in existing_context:
context['TEAM_LIST'] = get_team_list(request.user).values()
return context
示例8: get_default_context
def get_default_context(request, existing_context=None):
from sentry.plugins import plugins
context = {
'COMPRESS_ENABLED': dj_settings.COMPRESS_ENABLED,
'COMPRESS_LESS': dj_settings.COMPRESS_ENABLED and dj_settings.LESS_BIN,
'HAS_SEARCH': settings.USE_SEARCH,
'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE,
'INTERNAL_PROJECT': get_internal_project(),
'PROJECT_ID': str(settings.PROJECT),
'VIEWS': list(View.objects.all()),
'URL_PREFIX': settings.URL_PREFIX,
'PLUGINS': plugins,
'USE_JS_CLIENT': settings.USE_JS_CLIENT,
}
if request:
context.update({
'request': request,
'can_create_projects': can_create_projects(request.user),
'can_create_teams': can_create_teams(request.user),
})
if not existing_context or 'PROJECT_LIST' not in existing_context:
context['PROJECT_LIST'] = get_project_list(request.user).values()
if not existing_context or 'TEAM_LIST' not in existing_context:
context['TEAM_LIST'] = Team.objects.get_for_user(request.user).values()
return context
示例9: get_default_context
def get_default_context(request, existing_context=None):
from sentry.plugins import plugins
context = {
"HAS_SEARCH": settings.USE_SEARCH,
"MESSAGES_PER_PAGE": settings.MESSAGES_PER_PAGE,
"PROJECT_ID": str(settings.PROJECT),
"VIEWS": list(View.objects.all()),
"URL_PREFIX": settings.URL_PREFIX,
"PLUGINS": plugins,
"USE_JS_CLIENT": settings.USE_JS_CLIENT,
}
if request:
context.update(
{
"request": request,
"can_create_projects": can_create_projects(request.user),
"can_create_teams": can_create_teams(request.user),
}
)
if not existing_context or "PROJECT_LIST" not in existing_context:
context["PROJECT_LIST"] = get_project_list(request.user).values()
if not existing_context or "TEAM_LIST" not in existing_context:
context["TEAM_LIST"] = Team.objects.get_for_user(request.user).values()
return context
示例10: create_new_team
def create_new_team(request):
if not can_create_teams(request.user):
return missing_perm(request, Permissions.ADD_TEAM)
if request.user.has_perm('sentry.can_add_team'):
form_cls = NewTeamAdminForm
initial = {
'owner': request.user.username,
}
else:
form_cls = NewTeamForm
initial = {}
form = form_cls(request.POST or None, initial=initial)
if form.is_valid():
team = form.save(commit=False)
if not team.owner_id:
team.owner = request.user
team.save()
return HttpResponseRedirect(reverse('sentry-new-project', args=[team.slug]))
context = csrf(request)
context.update({
'form': form,
})
return render_to_response('sentry/teams/new.html', context, request)
示例11: new_project
def new_project(request):
from django.contrib.auth.models import User
if not can_create_projects(request.user):
return HttpResponseRedirect(reverse("sentry"))
allow_create_teams = can_create_teams(request.user)
team_list = Team.objects.get_for_user(request.user)
if request.user.has_perm("sentry.can_add_project") and User.objects.all()[0:2] == 2:
project_form_cls = NewProjectAdminForm
project_initial = {"owner": request.user.username}
else:
project_form_cls = NewProjectForm
project_initial = {}
if len(team_list) > 0:
select_team_form = SelectTeamForm(team_list, request.POST or None, prefix="st")
elif not allow_create_teams:
return render_to_response("sentry/projects/cannot_create_teams.html", {}, request)
else:
select_team_form = None
if allow_create_teams:
new_team_form = NewTeamForm(request.POST or None, prefix="nt")
else:
new_team_form = None
project_form = project_form_cls(request.POST or None, initial=project_initial, prefix="prj")
is_new_team = new_team_form and new_team_form.is_valid()
if is_new_team or not select_team_form:
team_form = new_team_form
else:
team_form = select_team_form
if project_form.is_valid() and team_form.is_valid():
project = project_form.save(commit=False)
if not project.owner:
project.owner = request.user
if is_new_team:
team = new_team_form.save(commit=False)
team.owner = project.owner
team.save()
else:
team = select_team_form.cleaned_data["team"]
project.team = team
project.save()
return HttpResponseRedirect(reverse("sentry-project-client-help", args=[project.slug]))
return render_to_response(
"sentry/projects/new.html",
{"project_form": project_form, "select_team_form": select_team_form, "new_team_form": new_team_form},
request,
)
示例12: handle
def handle(self, request, organization):
if not can_create_teams(request.user, organization):
return missing_perm(request, Permissions.ADD_TEAM)
session_data = request.session.get(self.session_key, {})
if request.method == 'GET':
logging.debug('GET request; resetting create team form wizard')
current_step = 0
try:
del request.session[self.session_key]
except KeyError:
pass
else:
current_step = int(request.POST.get('step', 0))
last_step = len(self.steps) - 1
if current_step > last_step:
logging.debug('Invalid step passed; resetting create team form wizard')
return self.render_validation_error(request, organization)
op = request.POST.get('op')
if op != 'continue':
data = None
else:
data = request.POST or None
form = self.get_step_form(current_step, data)
if op == 'continue' and form.is_valid():
session_data['step%d' % current_step] = form.cleaned_data
request.session[self.session_key] = session_data
if current_step == last_step:
# no more steps, render done view
return self.render_done(request, organization, form)
else:
# proceed to the next step
return self.render_next_step(request, organization, current_step + 1)
elif op == 'back' and current_step > 0:
return self.render_next_step(request, organization, current_step - 1)
elif op == 'skip' and current_step > 0:
session_data['step%d' % current_step] = {}
request.session[self.session_key] = session_data
if current_step == last_step:
# no more steps, render done view
return self.render_done(request, organization, form)
else:
# proceed to the next step
return self.render_next_step(request, organization, current_step + 1)
return self.render(request, organization, current_step, form)
示例13: dashboard
def dashboard(request, template="dashboard.html"):
team_list = Team.objects.get_for_user(request.user, with_projects=True)
if not team_list:
if can_create_teams(request.user):
return HttpResponseRedirect(reverse("sentry-new-team"))
return render_to_response(
"sentry/generic_error.html",
{
"title": _("No Membership"),
"message": _(
"You are not a member of any teams in Sentry and you do not have access to create a new team."
),
},
request,
)
return render_to_response("sentry/select_team.html", {"team_list": team_list.values()}, request)
示例14: post
def post(self, request):
if not can_create_teams(request.user):
return Response(status=403)
if request.user.is_superuser:
serializer = TeamAdminSerializer(data=request.DATA)
else:
serializer = TeamSerializer(data=request.DATA)
if serializer.is_valid():
result = serializer.object
team = Team.objects.create(
name=result['name'],
slug=result.get('slug'),
owner=result.get('owner') or request.user,
)
return Response(serialize(team, request.user), status=201)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例15: dashboard
def dashboard(request, template='dashboard.html'):
team_list = Team.objects.get_for_user(request.user)
if not team_list:
if can_create_teams(request.user):
return HttpResponseRedirect(reverse('sentry-new-team'))
return render_to_response('sentry/generic_error.html', {
'title': _('No Membership'),
'message': _('You are not a member of any teams in Sentry and you do not have access to create a new team.'),
}, request)
# This cookie gets automatically set by render_to_response
last_team = request.session.get('team')
if last_team in team_list:
team = team_list[last_team]
else:
team = team_list.values()[0]
# Redirect to first team
# TODO: maybe store this in a cookie and redirect to last seen team?
return HttpResponseRedirect(reverse('sentry', args=[team.slug]))