Skip to content

Commit

Permalink
ChallengeURLView 处理异常
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartHypercube committed Oct 27, 2023
1 parent d3d24ae commit 3123b92
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib import messages
from django.contrib.admin import site
from django.contrib.auth import logout
from django.http import JsonResponse
from django.http import Http404, JsonResponse
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.views import View
Expand Down Expand Up @@ -213,10 +213,19 @@ def get(self, request):
class ChallengeURLView(View):
def get(self, request, challenge_id):
context = Context.from_request(request)
challenge = Challenge.get(context, challenge_id)
user = User.get(context, request.user.pk)
url = challenge.get_and_log_url_orig().replace('{token}', quote(user.token))
return redirect(url)
try:
User.test_authenticated(context)
user = User.get(context, request.user.pk)
challenge = Challenge.get(context, challenge_id)
url_orig = challenge.get_and_log_url_orig()
if url_orig is None:
raise Http404
url = url_orig.replace('{token}', quote(user.token))
return redirect(url)
except Error as e:
messages.error(request, e.message)
return redirect('hub')


class ScoreView(View):
def get(self, request):
Expand All @@ -227,6 +236,7 @@ def get(self, request):
context = Context.from_request(request)
return TemplateResponse(request, 'score.html')


class UstcProfileView(View):
def check(self):
request = self.request
Expand Down

0 comments on commit 3123b92

Please sign in to comment.