def edit_party(request, party_id): if request.method == "POST": party = get_object_or_404(Party, id=party_id) form = CreatePartyForm(request.POST, instance=party) if form.is_valid(): party = form.save() if "save_send" in request.POST: if party.invite_type != None: if party.invite_type == "email": return redirect("email_invite", party_id=party.id) else: return redirect("sms_invite", party_id=party.id) else: if "sms_invite" in request.POST: return redirect("sms_invite", party_id=party.id) elif "email_invite" in request.POST: return redirect("email_invite", party_id=party.id) else: return redirect("list_party") else: return TemplateResponse(request, "parties/edit_party.html", {"form": form, "party": party}) else: party = get_object_or_404(Party, id=party_id) form = CreatePartyForm(instance=party) return TemplateResponse(request, "parties/edit_party.html", {"form": form, "party": party})
def create_party(request): if request.method == "POST": form = CreatePartyForm(request.POST) if form.is_valid(): party = form.save(commit=False) party.creator = request.user party.save() if "sms_invite" in request.POST: return redirect("sms_invite", party_id=party.id) elif "email_invite" in request.POST: return redirect("email_invite", party_id=party.id) else: return redirect("list_party") else: form = CreatePartyForm() return TemplateResponse(request, "parties/create_party.html", {"form": form})