本文整理汇总了Python中sentry.permissions.can_create_projects函数的典型用法代码示例。如果您正苦于以下问题:Python can_create_projects函数的具体用法?Python can_create_projects怎么用?Python can_create_projects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了can_create_projects函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例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):
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
示例4: 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
示例5: 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
示例6: create_new_team_project
def create_new_team_project(request, team):
from sentry.web.forms.projects import NewProjectAdminForm, NewProjectForm
if not can_create_projects(request.user, team):
return HttpResponseRedirect(reverse("sentry"))
if request.user.has_perm("sentry.can_add_project"):
form_cls = NewProjectAdminForm
initial = {"owner": request.user.username}
else:
form_cls = NewProjectForm
initial = {}
form = form_cls(request.POST or None, initial=initial)
if form.is_valid():
project = form.save(commit=False)
project.team = team
if not project.owner:
project.owner = request.user
project.save()
if project.platform not in (None, "other"):
return HttpResponseRedirect(reverse("sentry-docs-client", args=[project.slug, project.platform]))
return HttpResponseRedirect(reverse("sentry-get-started", args=[project.slug]))
context = csrf(request)
context.update({"form": form, "team": team, "page": "projects"})
return render_to_response("sentry/teams/projects/new.html", context, request)
示例7: 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
示例8: manage_team
def manage_team(request, team):
result = plugins.first('has_perm', request.user, 'edit_team', team)
if result is False and not request.user.has_perm('sentry.can_change_team'):
return HttpResponseRedirect(reverse('sentry'))
form = EditTeamForm(request.POST or None, instance=team)
if form.is_valid():
team = form.save()
return HttpResponseRedirect(request.path + '?success=1')
member_list = [(pm, pm.user) for pm in team.member_set.select_related('user').order_by('user__username')]
pending_member_list = [(pm, pm.email) for pm in team.pending_member_set.all().order_by('email')]
project_list = list(team.project_set.all())
context = csrf(request)
context.update({
'can_add_project': can_create_projects(request.user, team),
'can_add_member': can_add_team_member(request.user, team),
'can_remove_team': can_remove_team(request.user, team),
'page': 'details',
'form': form,
'team': team,
'member_list': member_list,
'pending_member_list': pending_member_list,
'project_list': project_list,
})
return render_to_response('sentry/teams/manage.html', context, request)
示例9: create_new_team_project
def create_new_team_project(request, team):
from sentry.web.forms import NewProjectAdminForm, NewProjectForm
if not can_create_projects(request.user, team):
return HttpResponseRedirect(reverse('sentry'))
if request.user.has_perm('sentry.can_add_project'):
form_cls = NewProjectAdminForm
initial = {
'owner': request.user.username,
}
else:
form_cls = NewProjectForm
initial = {}
form = form_cls(request.POST or None, initial=initial)
if form.is_valid():
project = form.save(commit=False)
project.team = team
if not project.owner:
project.owner = request.user
project.save()
return HttpResponseRedirect(reverse('sentry-manage-project', args=[project.pk]))
context = csrf(request)
context.update({
'form': form,
'team': team,
})
return render_to_response('sentry/teams/projects/new.html', context, request)
示例10: create_new_team_project
def create_new_team_project(request, team):
from sentry.web.forms.projects import NewProjectAdminForm, NewProjectForm
if not can_create_projects(request.user, team):
return HttpResponseRedirect(reverse('sentry'))
if request.user.has_perm('sentry.can_add_project'):
form_cls = NewProjectAdminForm
initial = {
'owner': request.user.username,
}
else:
form_cls = NewProjectForm
initial = {}
form = form_cls(request.POST or None, initial=initial)
if form.is_valid():
project = form.save(commit=False)
project.team = team
if not project.owner:
project.owner = request.user
project.save()
if project.platform not in (None, 'other'):
return HttpResponseRedirect(reverse('sentry-docs-client', args=[project.team.slug, project.slug, project.platform]))
return HttpResponseRedirect(reverse('sentry-get-started', args=[project.team.slug, project.slug]))
context = csrf(request)
context.update({
'form': form,
'page': 'projects',
'SUBSECTION': 'new_project',
})
return render_with_team_context(team, 'sentry/teams/projects/new.html', context, request)
示例11: dashboard
def dashboard(request, team):
project_list = list(Project.objects.filter(team=team))
if not project_list and can_create_projects(request.user, team=team):
return HttpResponseRedirect(reverse("sentry-new-project", args=[team.slug]))
for project in project_list:
project.team = team
return render_to_response("sentry/dashboard.html", {"team": team, "project_list": project_list}, request)
示例12: 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,
)
示例13: dashboard
def dashboard(request, template='dashboard.html'):
project_list = get_project_list(request.user, key='slug')
has_projects = len(project_list) > 1 or (len(project_list) == 1 and project_list.values()[0].pk != settings.PROJECT)
if not has_projects:
if not request.user.is_authenticated():
request.session['_next'] = request.get_full_path()
return HttpResponseRedirect(get_login_url())
elif can_create_projects(request.user):
return HttpResponseRedirect(reverse('sentry-new-project'))
return render_to_response('sentry/%s' % template, {}, request)
示例14: dashboard
def dashboard(request):
project_list = get_project_list(request.user, key="slug")
has_projects = len(project_list) > 1 or (len(project_list) == 1 and project_list.values()[0].pk != settings.PROJECT)
if not has_projects:
if not request.user.is_authenticated():
request.session["_next"] = request.build_absolute_uri()
return HttpResponseRedirect(get_login_url())
elif can_create_projects(request.user):
return HttpResponseRedirect(reverse("sentry-new-project"))
return render_to_response("sentry/dashboard.html", {}, request)
示例15: dashboard
def dashboard(request, team):
project_list = list(Project.objects.filter(team=team))
if not project_list and can_create_projects(request.user, team=team):
return HttpResponseRedirect(reverse('sentry-new-project', args=[team.slug]))
for project in project_list:
project.team = team
return render_to_response('sentry/dashboard.html', {
'team': team,
'project_list': project_list,
'SECTION': 'events',
}, request)