diff options
author | Magnus Hagander | 2015-08-31 14:44:57 +0000 |
---|---|---|
committer | Magnus Hagander | 2015-08-31 14:44:57 +0000 |
commit | 6aeb763fb1b7b234e05cd3a7988703ebad423e7f (patch) | |
tree | adf8b1d133ac1944931bf0fee1c7ab81382ac7cb /pgcommitfest/commitfest/views.py | |
parent | 85b6326fd7806e19d15bf8198fa4e9f0f16b7c30 (diff) |
Don't crash on redirect when multiple CFs are inprogress or open
This is an incorrect state, but we shouldn't crash anyway. Instead show
an error message and redirect to the root page.
Reported by Bruce Momjian
Diffstat (limited to 'pgcommitfest/commitfest/views.py')
-rw-r--r-- | pgcommitfest/commitfest/views.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index 02567f3..93bd421 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -80,13 +80,20 @@ def activity(request, cfid=None, rss=None): def redir(request, what): if what == 'open': - cf = get_object_or_404(CommitFest, status=CommitFest.STATUS_OPEN) + cfs = list(CommitFest.objects.filter(status=CommitFest.STATUS_OPEN)) elif what == 'inprogress': - cf = get_object_or_404(CommitFest, status=CommitFest.STATUS_INPROGRESS) + cfs = list(CommitFest.objects.filter(status=CommitFest.STATUS_INPROGRESS)) else: raise Http404() - return HttpResponseRedirect("/%s/" % cf.id) + if len(cfs) == 0: + messages.warning(request, "No {0} commitfests exist, redirecting to startpage.".format(what)) + return HttpResponseRedirect("/") + if len(cfs) != 1: + messages.warning(request, "More than one {0} commitfest exists, redirecting to startpage instead.".format(what)) + return HttpResponseRedirect("/") + + return HttpResponseRedirect("/%s/" % cfs[0].id) def commitfest(request, cfid): # Find ourselves |