本文整理汇总了Python中sentry.web.helpers.render_to_response函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_response函数的具体用法?Python render_to_response怎么用?Python render_to_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_to_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recover
def recover(request):
form = RecoverPasswordForm(request.POST or None,
captcha=bool(request.session.get('needs_captcha')))
if form.is_valid():
password_hash, created = LostPasswordHash.objects.get_or_create(
user=form.cleaned_data['user']
)
if not password_hash.is_valid():
password_hash.date_added = timezone.now()
password_hash.set_hash()
if form.is_valid():
password_hash.send_recover_mail()
request.session.pop('needs_captcha', None)
return render_to_response('sentry/account/recover/sent.html', {
'email': password_hash.user.email,
}, request)
elif request.POST and not request.session.get('needs_captcha'):
request.session['needs_captcha'] = 1
form = RecoverPasswordForm(request.POST or None, captcha=True)
form.errors.pop('captcha', None)
context = {
'form': form,
}
return render_to_response('sentry/account/recover/index.html', context, request)
示例2: recover
def recover(request):
form = RecoverPasswordForm(request.POST or None)
if form.is_valid():
password_hash, created = LostPasswordHash.objects.get_or_create(
user=form.cleaned_data['user']
)
if not password_hash.is_valid():
created = True
password_hash.date_added = timezone.now()
password_hash.set_hash()
if not created:
form.errors['__all__'] = ['A password reset was already attempted for this account within the last 24 hours.']
if form.is_valid():
password_hash.send_recover_mail()
return render_to_response('sentry/account/recover/sent.html', {
'email': password_hash.user.email,
}, request)
context = {
'form': form,
}
return render_to_response('sentry/account/recover/index.html', context, request)
示例3: 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)
示例4: 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)
示例5: client_guide
def client_guide(request, project, platform):
if platform not in PLATFORM_LIST:
return HttpResponseRedirect(reverse('sentry'))
key = ProjectKey.objects.get(user=request.user, project=project)
dsn = key.get_dsn()
dsn_public = key.get_dsn(public=True)
template = 'sentry/partial/client_config/%s.html' % (platform,)
context = {
'platform': platform,
'platform_title': platform.title(),
'project': project,
'dsn': dsn,
'dsn_public': dsn_public,
'page': 'client_help'
}
if request.is_ajax():
return render_to_response(template, context, request)
context['template'] = render_to_string(template, context, request)
return render_to_response('sentry/projects/docs/client_config.html', context, request)
示例6: recover
def recover(request):
from sentry.app import ratelimiter
if request.method == 'POST' and ratelimiter.is_limited(
'accounts:recover:{}'.format(request.META['REMOTE_ADDR']),
limit=5, window=60, # 5 per minute should be enough for anyone
):
return HttpResponse(
'You have made too many password recovery attempts. Please try again later.',
content_type='text/plain',
status=429,
)
form = RecoverPasswordForm(request.POST or None)
if form.is_valid():
password_hash = send_password_recovery_mail(request, form.cleaned_data['user'])
return render_to_response('sentry/account/recover/sent.html', {
'email': password_hash.user.email,
}, request)
context = {
'form': form,
}
return render_to_response('sentry/account/recover/index.html', context, request)
示例7: search
def search(request, project):
query = request.GET.get('q')
if not query:
return HttpResponseRedirect(reverse('sentry', args=[project.slug]))
sort = request.GET.get('sort')
if sort not in SEARCH_SORT_OPTIONS:
sort = settings.SEARCH_DEFAULT_SORT_OPTION
sort_label = SEARCH_SORT_OPTIONS[sort]
result = event_re.match(query)
if result:
# Forward to message if it exists
# event_id = result.group(1)
checksum = result.group(2)
event_list = Group.objects.filter(checksum=checksum)
top_matches = event_list[:2]
if len(top_matches) == 0:
return render_to_response('sentry/invalid_message_id.html', {
'project': project,
}, request)
elif len(top_matches) == 1:
return HttpResponseRedirect(top_matches[0].get_absolute_url())
elif uuid_re.match(query):
# Forward to message if it exists
try:
message = Event.objects.get(project=project, event_id=query)
except Event.DoesNotExist:
return render_to_response('sentry/invalid_message_id.html', {
'project': project,
}, request)
else:
return HttpResponseRedirect(message.get_absolute_url())
elif not settings.USE_SEARCH:
event_list = Group.objects.none()
# return render_to_response('sentry/invalid_message_id.html', {
# 'project': project,
# }, request)
else:
documents = list(SearchDocument.objects.search(project, query, sort_by=sort))
groups = Group.objects.in_bulk([d.group_id for d in documents])
event_list = []
for doc in documents:
try:
event_list.append(groups[doc.group_id])
except KeyError:
continue
return render_to_response('sentry/search.html', {
'project': project,
'event_list': event_list,
'query': query,
'sort': sort,
'sort_label': sort_label,
}, request)
示例8: 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,
)
示例9: accept_invite
def accept_invite(request, member_id, token):
try:
pending_member = PendingTeamMember.objects.get(pk=member_id)
except PendingTeamMember.DoesNotExist:
return HttpResponseRedirect(reverse('sentry'))
if pending_member.token != token:
return HttpResponseRedirect(reverse('sentry'))
team = pending_member.team
project_list = list(team.project_set.filter(status=0))
for project in project_list:
project.team = team
context = {
'team': team,
'team_owner': team.get_owner_name(),
'project_list': project_list,
}
if not request.user.is_authenticated():
# Show login or register form
request.session['_next'] = request.get_full_path()
request.session['can_register'] = True
return render_to_response('sentry/teams/members/accept_invite_unauthenticated.html', context, request)
if request.method == 'POST':
form = AcceptInviteForm(request.POST)
else:
form = AcceptInviteForm()
if form.is_valid():
team.member_set.get_or_create(
user=request.user,
defaults={
'type': pending_member.type,
}
)
request.session.pop('can_register', None)
pending_member.delete()
messages.add_message(request, messages.SUCCESS,
_('You have been added to the %r team.') % (team.name.encode('utf-8'),))
return HttpResponseRedirect(reverse('sentry', args=[team.slug]))
context['form'] = form
return render_to_response('sentry/teams/members/accept_invite.html', context, request)
示例10: recover
def recover(request):
form = RecoverPasswordForm(request.POST or None)
if form.is_valid():
password_hash = send_password_recovery_mail(form.cleaned_data['user'])
return render_to_response('sentry/account/recover/sent.html', {
'email': password_hash.user.email,
}, request)
context = {
'form': form,
}
return render_to_response('sentry/account/recover/index.html', context, request)
示例11: 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)
示例12: recover_confirm
def recover_confirm(request, user_id, hash, mode='recover'):
try:
password_hash = LostPasswordHash.objects.get(user=user_id, hash=hash)
if not password_hash.is_valid():
password_hash.delete()
raise LostPasswordHash.DoesNotExist
user = password_hash.user
except LostPasswordHash.DoesNotExist:
tpl = get_template('failure', mode)
return render_to_response(tpl, {}, request)
if request.method == 'POST':
form = ChangePasswordRecoverForm(request.POST)
if form.is_valid():
with transaction.atomic():
user.set_password(form.cleaned_data['password'])
user.refresh_session_nonce(request)
user.save()
# Ugly way of doing this, but Django requires the backend be set
user = authenticate(
username=user.username,
password=form.cleaned_data['password'],
)
# Only log the user in if there is no two-factor on the
# account.
if not Authenticator.objects.user_has_2fa(user):
login_user(request, user)
password_hash.delete()
capture_security_activity(
account=user,
type='password-changed',
actor=request.user,
ip_address=request.META['REMOTE_ADDR'],
send_email=True,
)
return login_redirect(request)
else:
form = ChangePasswordRecoverForm()
tpl = get_template('confirm', mode)
context = {'form': form}
return render_to_response(tpl, context, request)
示例13: recover
def recover(request):
from sentry.app import ratelimiter
extra = {
'ip_address': request.META['REMOTE_ADDR'],
'user_agent': request.META.get('HTTP_USER_AGENT'),
}
if request.method == 'POST' and ratelimiter.is_limited(
u'accounts:recover:{}'.format(extra['ip_address']),
limit=5,
window=60, # 5 per minute should be enough for anyone
):
logger.warning('recover.rate-limited', extra=extra)
return HttpResponse(
'You have made too many password recovery attempts. Please try again later.',
content_type='text/plain',
status=429,
)
prefill = {'user': request.GET.get('email')}
form = RecoverPasswordForm(request.POST or None, initial=prefill)
extra['user_recovered'] = form.data.get('user')
if form.is_valid():
email = form.cleaned_data['user']
if email:
password_hash = LostPasswordHash.for_user(email)
password_hash.send_email(request)
extra['passwordhash_id'] = password_hash.id
extra['user_id'] = password_hash.user_id
logger.info('recover.sent', extra=extra)
tpl = 'sentry/account/recover/sent.html'
context = {'email': email}
return render_to_response(tpl, context, request)
if form._errors:
logger.warning('recover.error', extra=extra)
tpl = 'sentry/account/recover/index.html'
context = {'form': form}
return render_to_response(tpl, context, request)
示例14: recover
def recover(request):
form = RecoverPasswordForm(request.POST or None)
if form.is_valid():
password_hash, created = LostPasswordHash.objects.get_or_create(user=form.cleaned_data["user"])
if not password_hash.is_valid():
password_hash.date_added = timezone.now()
password_hash.set_hash()
if form.is_valid():
password_hash.send_recover_mail()
return render_to_response("sentry/account/recover/sent.html", {"email": password_hash.user.email}, request)
context = {"form": form}
return render_to_response("sentry/account/recover/index.html", context, request)
示例15: search
def search(request, project):
query = request.GET.get('q')
if query:
result = event_re.match(query)
if result:
# Forward to message if it exists
# event_id = result.group(1)
checksum = result.group(2)
event_list = Group.objects.filter(checksum=checksum)
top_matches = event_list[:2]
if len(top_matches) == 0:
return render_to_response('sentry/invalid_message_id.html', {
'project': project,
}, request)
elif len(top_matches) == 1:
return HttpResponseRedirect(top_matches[0].get_absolute_url())
elif uuid_re.match(query):
# Forward to message if it exists
try:
message = Event.objects.get(event_id=query)
except Event.DoesNotExist:
return render_to_response('sentry/invalid_message_id.html', {
'project': project,
}, request)
else:
return HttpResponseRedirect(message.get_absolute_url())
else:
return render_to_response('sentry/invalid_message_id.html', {
'project': project,
}, request)
else:
event_list = Group.objects.none()
sort = request.GET.get('sort')
if sort == 'date':
event_list = event_list.order_by('-last_seen')
elif sort == 'new':
event_list = event_list.order_by('-first_seen')
else:
sort = 'relevance'
return render_to_response('sentry/search.html', {
'project': project,
'event_list': event_list,
'query': query,
'sort': sort,
}, request)