def details(request, obj_id, name, allow_feedback=False): """Render the Quests 'detail' page.""" # lookup quest if not re.match(r'\d+', obj_id): raise ValueError( f'Invalid obj_id found. ID is not a number: {obj_id}') try: quest = Quest.objects.get(pk=obj_id) if not quest.is_unlocked_for(request.user): unlock_how = f"Unlock this quest by registering for {quest.unlocked_by_hackathon.name} Hackathon" if quest.unlocked_by_hackathon else f"Unlock by beating the '{quest.self.unlocked_by_quest}' Quest" messages.info( request, f'This quest is locked. Try again after you have unlocked it. ({unlock_how})' ) return redirect('/quests') except: raise Http404 # handle user feedback if allow_feedback and request.user.is_authenticated and request.POST.get( 'feedback'): comment = request.POST.get('feedback') vote = int(request.POST.get('polarity')) if vote not in [-1, 1]: vote = 0 from quests.models import QuestFeedback QuestFeedback.objects.create( profile=request.user.profile, quest=quest, comment=comment, vote=vote, ) if comment: send_user_feedback(quest, comment, request.user) return JsonResponse({'status': 'ok'}) if quest.style.lower() == 'quiz': return quiz_style(request, quest) elif quest.style == 'Example for Demo': return example(request, quest) else: raise Exception(f'Not supported quest style: {quest.style}')
def details(request, obj_id, name): """Render the Quests 'detail' page.""" if not re.match(r'\d+', obj_id): raise ValueError( f'Invalid obj_id found. ID is not a number: {obj_id}') try: quest = Quest.objects.get(pk=obj_id) if not quest.is_unlocked_for(request.user): messages.info( request, 'This quest is locked. Try again after you have unlocked it') return redirect('/quests') except: raise Http404 if quest.style.lower() == 'quiz': return quiz_style(request, quest) elif quest.style == 'Example for Demo': return example(request, quest) else: raise Exception(f'Not supported quest style: {quest.style}')