Skip to content

Commit

Permalink
Fill contents back when there's error on submitting feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Oct 29, 2024
1 parent 7dd2695 commit b7abfe6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ def check_frequency(self, challenge_id):

return too_frequent, latest_feedback

def return_template(self, challenge_name, too_frequent, latest_feedback):
def return_template(self, challenge_name, too_frequent, latest_feedback, contents=""):
return TemplateResponse(self.request, 'challenge_feedback.html', {
"feedback": Feedback.get(),
"challenge_name": challenge_name,
"too_frequent": too_frequent,
"latest_feedback": latest_feedback,
"contents": contents,
})

def get(self, request, challenge_id):
Expand Down Expand Up @@ -303,7 +304,7 @@ def post(self, request, challenge_id):
contents = request.POST.get("contents")
if len(contents) > 1024:
messages.error(request, "提交内容超过字数限制。")
return self.return_template(challenge_name, too_frequent, latest_feedback)
return self.return_template(challenge_name, too_frequent, latest_feedback, contents)
user = User.get(Context.from_request(request), request.user.pk)
# send to user-defined endpoint
if settings.FEEDBACK_ENDPOINT:
Expand All @@ -324,7 +325,7 @@ 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_feedback)
return self.return_template(challenge_name, too_frequent, latest_feedback, contents)
feedback = UnidirectionalFeedback.objects.create(challenge_id=challenge_id, user=request.user, contents=contents)
feedback.save()

Expand Down

0 comments on commit b7abfe6

Please sign in to comment.