本文整理汇总了Python中django.http.HttpResponseRedirect方法的典型用法代码示例。如果您正苦于以下问题:Python http.HttpResponseRedirect方法的具体用法?Python http.HttpResponseRedirect怎么用?Python http.HttpResponseRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http
的用法示例。
在下文中一共展示了http.HttpResponseRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: site_login
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def site_login(request):
"""
Logs in current user
:param request:
:return render:
"""
if request.method == "POST":
user = None
user_login = request.POST['login']
user_password = request.POST['password']
print("Login tryout by "+user_login)
if user_login != "" and user_password != "":
user = authenticate(username=user_login, password=user_password)
if user is not None:
login(request, user)
return HttpResponseRedirect(reverse('public_gate:home'))
else:
# User.objects.create_user(user_login, '', user_password).save()
return render(request, 'public_gate/home.html', {"error_message": "Wrong login/password combination"})
return render(request, 'public_gate/home.html', {"error_message": "One or more fields are empty"})
示例2: figures_home
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def figures_home(request):
'''Renders the JavaScript SPA dashboard
TODO: Should we make this a view class?
'''
# We probably want to roll this into a decorator
if not figures.permissions.is_site_admin_user(request):
return HttpResponseRedirect('/')
# Placeholder context vars just to illustrate returning API hosts to the
# client. This one uses a protocol relative url
context = {
'figures_api_url': '//api.example.com',
}
return render(request, 'figures/index.html', context)
#
# Mixins for API views
#
示例3: runindex
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def runindex(request, event=None):
event = viewutil.get_event(event)
if not event.id:
return HttpResponseRedirect(
reverse('tracker:runindex', args=(Event.objects.latest().short,))
)
searchParams = {}
searchParams['event'] = event.id
runs = filters.run_model_query('run', searchParams)
runs = runs.annotate(hasbids=Sum('bids'))
return views_common.tracker_response(
request, 'tracker/runindex.html', {'runs': runs, 'event': event},
)
示例4: prizeindex
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def prizeindex(request, event=None):
event = viewutil.get_event(event)
if not event.id:
return HttpResponseRedirect(
reverse('tracker:prizeindex', args=(Event.objects.latest().short,))
)
searchParams = {}
searchParams['event'] = event.id
prizes = filters.run_model_query('prize', searchParams)
prizes = prizes.select_related('startrun', 'endrun', 'category').prefetch_related(
'prizewinner_set'
)
return views_common.tracker_response(
request, 'tracker/prizeindex.html', {'prizes': prizes, 'event': event},
)
示例5: merge_bids_view
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def merge_bids_view(request, *args, **kwargs):
if request.method == 'POST':
objects = [int(x) for x in request.POST['objects'].split(',')]
form = forms.MergeObjectsForm(
model=models.Bid, objects=objects, data=request.POST
)
if form.is_valid():
viewutil.merge_bids(
form.cleaned_data['root'], form.cleaned_data['objects']
)
logutil.change(
request,
form.cleaned_data['root'],
'Merged bid {0} with {1}'.format(
form.cleaned_data['root'],
','.join([str(d) for d in form.cleaned_data['objects']]),
),
)
return HttpResponseRedirect(reverse('admin:tracker_bid_changelist'))
else:
objects = [int(x) for x in request.GET['objects'].split(',')]
form = forms.MergeObjectsForm(model=models.Bid, objects=objects)
return render(request, 'admin/merge_bids.html', {'form': form})
示例6: merge_donors_view
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def merge_donors_view(request):
if request.method == 'POST':
objects = [int(x) for x in request.POST['objects'].split(',')]
form = forms.MergeObjectsForm(
model=models.Donor, objects=objects, data=request.POST
)
if form.is_valid():
viewutil.merge_donors(
form.cleaned_data['root'], form.cleaned_data['objects']
)
logutil.change(
request,
form.cleaned_data['root'],
'Merged donor {0} with {1}'.format(
form.cleaned_data['root'],
','.join([str(d) for d in form.cleaned_data['objects']]),
),
)
return HttpResponseRedirect(reverse('admin:tracker_donor_changelist'))
else:
objects = [int(x) for x in request.GET['objects'].split(',')]
form = forms.MergeObjectsForm(model=models.Donor, objects=objects)
return render(request, 'admin/merge_donors.html', {'form': form})
示例7: login_required
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def login_required(login_url=None):
"""
Decorator for views that checks that the user is authenticated, redirecting
to login_url page if necessary.
"""
def decorator(view_func):
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
is_login, username, is_staff = is_authenticated(request)
if is_login:
kwargs['username'] = username
kwargs['is_staff'] = is_staff
return view_func(request, *args, **kwargs)
resolved_login_url = (login_url or settings.LOGIN_URL)
return HttpResponseRedirect(resolved_login_url)
return _wrapped_view
return decorator
示例8: add_source
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def add_source(request, evidence_id):
"""Return a view for adding a corroborating/contradicting source, or handle form submission."""
evidence = get_object_or_404(Evidence, pk=evidence_id)
if request.method == 'POST':
form = EvidenceSourceForm(request.POST)
if form.is_valid():
source = form.save(commit=False)
source.evidence = evidence
source.uploader = request.user
source.save()
fetch_source_metadata.delay(source.id)
return HttpResponseRedirect(reverse('openach:evidence_detail', args=(evidence_id,)))
else:
corroborating = form.data['corroborating'] == 'True'
else:
corroborating = request.GET.get('kind') is None or request.GET.get('kind') != 'conflicting'
form = EvidenceSourceForm(initial={'corroborating': corroborating})
context = {
'form': form,
'evidence': evidence,
'corroborating': corroborating
}
return render(request, 'boards/add_source.html', context)
示例9: toggle_source_tag
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def toggle_source_tag(request, evidence_id, source_id):
"""Toggle source tag for the given source and redirect to the evidence detail page for the associated evidence."""
# May want to put in a sanity check here that source_id actually corresponds to evidence_id
# Inefficient to have to do the DB lookup before making a modification. May want to have the client pass in
# whether or not they're adding/removing the tag
if request.method == 'POST':
with transaction.atomic():
source = get_object_or_404(EvidenceSource, pk=source_id)
tag = EvidenceSourceTag.objects.get(tag_name=request.POST['tag'])
user_tag = AnalystSourceTag.objects.filter(source=source, tagger=request.user, tag=tag)
if user_tag.count() > 0:
user_tag.delete()
messages.success(request, _('Removed "{name}" tag from source.').format(name=tag.tag_name))
else:
AnalystSourceTag.objects.create(source=source, tagger=request.user, tag=tag)
messages.success(request, _('Added "{name}" tag to source.').format(name=tag.tag_name))
return HttpResponseRedirect(reverse('openach:evidence_detail', args=(evidence_id,)))
else:
# Redirect to the form where the user can toggle a source tag
return HttpResponseRedirect(reverse('openach:evidence_detail', args=(evidence_id,)))
示例10: edit_permissions
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def edit_permissions(request, board_id):
"""View board permissions form and handle form submission."""
board = get_object_or_404(Board, pk=board_id)
if 'edit_board' not in board.permissions.for_user(request.user):
raise PermissionDenied()
if request.method == 'POST':
form = BoardPermissionForm(request.POST, instance=board.permissions, user=request.user)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('openach:detail', args=(board.id,)))
else:
form = BoardPermissionForm(instance=board.permissions, user=request.user)
context = {
'board': board,
'form': form,
}
return render(request, 'boards/edit_permissions.html', context)
示例11: edit_team
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def edit_team(request, team_id):
"""Return a team edit view, or handle the form submission."""
# TODO: if user turns off invitation-required, let everyone in who had outstanding membership requests
team = get_object_or_404(Team, pk=team_id)
if team.owner_id is None or team.owner_id != request.user.id:
raise SuspiciousOperation(_('User is not the owner of the team'))
if request.method == 'POST':
form = TeamCreateForm(request.POST, instance=team)
if form.is_valid():
form.save()
messages.success(request, _('Updated team information'))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
else:
form = TeamCreateForm(instance=team)
return render(request, 'teams/edit_team.html', context={
'team': team,
'form': form
})
示例12: invite_members
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def invite_members(request, team_id):
"""Return a team edit view, or handle the form submission."""
team = get_object_or_404(Team, pk=team_id)
if team.owner_id is None or team.owner_id != request.user.id:
raise SuspiciousOperation(_('User is not the owner of the team'))
if request.method == 'POST':
form = TeamInviteForm(request.POST, team=team)
if form.is_valid():
to_invite = form.cleaned_data['members']
invites = [TeamRequest(team=team, inviter=request.user, invitee=x) for x in to_invite]
TeamRequest.objects.bulk_create(invites)
for user in to_invite:
notify.send(request.user, recipient=user, actor=request.user, verb='invite', action_object=team, target=user)
messages.success(request, _('Invited {count} members to the team').format(count=len(to_invite)))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
else:
form = TeamInviteForm(team=team)
return render(request, 'teams/invite.html', context={
'team': team,
'form': form
})
示例13: decide_invitation
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def decide_invitation(request, invite_id):
invite = get_object_or_404(TeamRequest, pk=invite_id)
team = invite.team
if team.owner_id is None or team.owner_id != request.user.id:
raise SuspiciousOperation(_('User is not the owner of the team'))
elif 'accept' in request.POST:
invite.team.members.add(invite.invitee)
invite.team.save()
notify.send(request.user, recipient=invite.invitee, actor=request.user, verb='accept', action_object=team, target=invite.invitee)
messages.success(request, _('Added {name} to the team').format(name=invite.invitee.username))
elif 'reject' in request.POST:
notify.send(request.user, recipient=invite.invitee, actor=request.user, verb='reject', action_object=team, target=invite.invitee)
messages.success(request, _('Ignored {name}\'s team membership request').format(name=invite.invitee.username))
else:
return HttpResponseBadRequest(_('POST request must include either "{accept}" or "{reject}"').format(accept='accept', reject='reject'))
invite.delete()
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
示例14: revoke_membership
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def revoke_membership(request, team_id, member_id):
team = get_object_or_404(Team, pk=team_id)
user = get_object_or_404(User, pk=member_id)
if team.owner_id is None or team.owner_id != request.user.id:
raise SuspiciousOperation(_('User is not the owner of the team'))
elif user == team.owner:
raise SuspiciousOperation(_('Cannot remove the owner from the team'))
elif not team.invitation_required:
raise SuspiciousOperation(_('Cannot remove user from teams that don\'t require an invitation'))
team.members.remove(user)
team.save()
notify.send(request.user, recipient=user, actor=request.user, verb='remove', action_object=team, target=user)
messages.success(request, _('Removed {name} from team').format(name=user.username))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
示例15: join_team
# 需要导入模块: from django import http [as 别名]
# 或者: from django.http import HttpResponseRedirect [as 别名]
def join_team(request, team_id):
team = get_object_or_404(Team, pk=team_id)
if team.members.filter(id=request.user.id).exists():
raise SuspiciousOperation(_('User is already a member of the team'))
elif TeamRequest.objects.filter(invitee=request.user, inviter__isnull=False, team=team).exists() or not team.invitation_required:
team.members.add(request.user)
team.save()
TeamRequest.objects.filter(invitee=request.user, team=team).delete()
messages.success(request, _('Joined team {name}').format(name=team.name))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))
elif TeamRequest.objects.filter(invitee=request.user, team=team).exists():
return HttpResponseBadRequest(_('User already has a membership request with the team'))
else:
TeamRequest.objects.create(invitee=request.user, team=team)
if team.owner:
notify.send(request.user, recipient=team.owner, actor=request.user, verb='request_membership', target=team)
messages.success(request, _('Requested invitation to team {name}').format(name=team.name))
return HttpResponseRedirect(reverse('openach:view_team', args=(team.id,)))