forked from mirrors/bookwyrm
Simpler error states for when model values aren't found
This commit is contained in:
parent
3aebb54feb
commit
08a8f37a0b
1 changed files with 9 additions and 23 deletions
|
@ -256,18 +256,13 @@ def remove_member(request):
|
||||||
@login_required
|
@login_required
|
||||||
def accept_membership(request):
|
def accept_membership(request):
|
||||||
"""accept an invitation to join a group"""
|
"""accept an invitation to join a group"""
|
||||||
|
group = get_object_or_404(models.Group, id=request.POST.get("group"))
|
||||||
group = models.Group.objects.get(id=request.POST["group"])
|
invite = get_object_or_404(
|
||||||
if not group:
|
models.GroupMemberInvitation, group=group, user=request.user
|
||||||
return HttpResponseBadRequest()
|
)
|
||||||
|
|
||||||
invite = models.GroupMemberInvitation.objects.get(group=group, user=request.user)
|
|
||||||
if not invite:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
invite.accept()
|
invite.accept()
|
||||||
|
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -278,19 +273,10 @@ def accept_membership(request):
|
||||||
@login_required
|
@login_required
|
||||||
def reject_membership(request):
|
def reject_membership(request):
|
||||||
"""reject an invitation to join a group"""
|
"""reject an invitation to join a group"""
|
||||||
|
group = get_object_or_404(models.Group, id=request.POST.get("group"))
|
||||||
|
invite = get_object_or_404(
|
||||||
|
models.GroupMemberInvitation, group=group, user=request.user
|
||||||
|
)
|
||||||
|
|
||||||
group = models.Group.objects.get(id=request.POST["group"])
|
invite.reject()
|
||||||
if not group:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
invite = models.GroupMemberInvitation.objects.get(group=group, user=request.user)
|
|
||||||
if not invite:
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
try:
|
|
||||||
invite.reject()
|
|
||||||
|
|
||||||
except IntegrityError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return redirect(request.user.local_path)
|
return redirect(request.user.local_path)
|
||||||
|
|
Loading…
Reference in a new issue