Redirect to previous page after editing a session
This commit is contained in:
parent
31daf2efe0
commit
b794be8301
@ -3,7 +3,7 @@ from typing import Any
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@ -26,7 +26,6 @@ from common.time import (
|
|||||||
from common.utils import truncate
|
from common.utils import truncate
|
||||||
from games.forms import SessionForm
|
from games.forms import SessionForm
|
||||||
from games.models import Game, Session
|
from games.models import Game, Session
|
||||||
from games.views.general import use_custom_redirect
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -215,14 +214,13 @@ def add_session(request: HttpRequest, game_id: int = 0) -> HttpResponse:
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@use_custom_redirect
|
|
||||||
def edit_session(request: HttpRequest, session_id: int) -> HttpResponse:
|
def edit_session(request: HttpRequest, session_id: int) -> HttpResponse:
|
||||||
context = {}
|
context = {}
|
||||||
session = get_object_or_404(Session, id=session_id)
|
session = get_object_or_404(Session, id=session_id)
|
||||||
form = SessionForm(request.POST or None, instance=session)
|
form = SessionForm(request.POST or None, instance=session)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
return redirect("list_sessions")
|
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||||
context["title"] = "Edit Session"
|
context["title"] = "Edit Session"
|
||||||
context["form"] = form
|
context["form"] = form
|
||||||
return render(request, "add.html", context)
|
return render(request, "add.html", context)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user