Skip to content

Commit

Permalink
Redirect to challenge when submitted successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Oct 28, 2024
1 parent 0058125 commit 564a25b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.contrib.admin import site
from django.contrib.auth import logout
from django.http import Http404, JsonResponse
from django.urls import reverse
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.views import View
Expand Down Expand Up @@ -247,6 +248,10 @@ def check(self, challenge_id):
except Error as e:
return None

def redirect_with_challenge_hash(self, challenge_name):
url = reverse("hub") + "#" + quote(challenge_name)
return redirect(url)

def check_frequency(self, challenge_id):
request = self.request
matched_feedbacks = UnidirectionalFeedback.objects.filter(challenge_id=challenge_id, user=request.user)
Expand Down Expand Up @@ -294,7 +299,7 @@ def post(self, request, challenge_id):
too_frequent, latest_feedback = self.check_frequency(challenge_id)
if too_frequent:
messages.error(request, "提交反馈太过频繁。")
return redirect('hub')
return self.return_template(challenge_name, too_frequent, latest_feedback)
contents = request.POST.get("contents")
if len(contents) > 1024:
messages.error(request, "提交内容超过字数限制。")
Expand All @@ -319,12 +324,12 @@ def post(self, request, challenge_id):
except (requests.exceptions.RequestException, requests.exceptions.HTTPError) as e:
messages.error(request, "反馈发送失败,请向管理员反馈此问题。")
logger.exception("反馈发送失败")
return self.return_template(challenge_name, too_frequent, latest)
return self.return_template(challenge_name, too_frequent, latest_feedback)
feedback = UnidirectionalFeedback.objects.create(challenge_id=challenge_id, user=request.user, contents=contents)
feedback.save()

messages.success(request, "反馈提交成功。")
return redirect('hub')
return self.redirect_with_challenge_hash(challenge_name)


class ScoreView(View):
Expand Down

0 comments on commit 564a25b

Please sign in to comment.