def result_view(self): # Is this a logged-in user? If not, forward them to log-in UserID = session.get("UserID") if not UserID: redirect(url(controller="users", action="login")) # Pull up this results's information ResultID = request.path[request.path.find("result/") + 7 : len(request.path)] # Query the results information Solution = Solver.QueryResultID(UserID, ResultID) # If no solution, post error if not Solution: abort(status_code = 404, detail = "Result ID \"" + ResultID + "\" does not exist.") # Query the challenge # Note to self: can I directly access via foriegn key? Challenge = Challenges.ChallengeQueryID(Solution.ChallengeID) if not Challenge: abort(status_code = 404, detail = "Challenge ID \"" + Solution.ChallengeID + "\" does not exist.") # Find all user solutions to this Challenge... Challenge.solutions = Solutions.SolutionsUserIDChallengeID(UserID, Solution.ChallengeID) Challenge.attempts = len(Challenge.solutions) Challenge.solved = False # Check if we have solved this challenge for solution in Challenge.solutions: if solution.ResultCode == 1: Challenge.solved = True break # Post the owner group of this challenge c.groupname = Challenges.ChallengesGroupQueryGroupID(Challenge.ChallengeGroupID, False).ChallengeGroupName # Post the challenge view content c.challenge = Challenge # Post the parent group directory c.group_id = Challenge.ChallengeGroupID c.group_name = c.groupname # Post the user-level directory data c.challenge_id = Challenge.ChallengeID c.challenge_name = Challenge.Title # Convert the source code into html friendly code # NOTE: We are defaulting everything to just render in Python c.formated_code = h.code_to_html(Solution.SourceCode, "Python") c.formated_samplecode = h.code_to_html(Challenge.SampleCode, "Python") # Render the solution information c.challenge = Challenge c.result = Solution c.body_content = render("/content_resultview.html") return render("/theme.html")
def challenge_view(self): # Pull up this challenge's information ChallengeID = request.path[request.path.find("challenge/") + 10 : len(request.path)] # Is this a valid integer? if not ChallengeID.isdigit(): abort(status_code=404, detail='Challenge ID "' + ChallengeID + '" does not exist.') # Query the challenge Challenge = Challenges.ChallengeQueryID(ChallengeID) if Challenge is None: abort(status_code=404, detail='Challenge ID "' + ChallengeID + '" failed to load.') if not Challenge.IsValid: abort(status_code=500, detail='Challenge ID "' + ChallengeID + '" failed to load: ' + Challenge.ErrorStr) # Find all user solutions to this Challenge... Challenge.solutions = Solutions.SolutionsUserIDChallengeID(session.get("UserID"), ChallengeID) Challenge.attempts = len(Challenge.solutions) Challenge.solved = False # Check if we have solved this challenge for solution in Challenge.solutions: if solution.ResultCode == 1: Challenge.solved = True break # Generate graphics / tables self.__generate_graphics(ChallengeID) # Post the owner group of this challenge c.groupname = Challenges.ChallengesGroupQueryGroupID(Challenge.ChallengeGroupID, False).ChallengeGroupName # Convert the source code into html friendly code # NOTE: We are defaulting everything to just render in Python c.formated_code = h.code_to_html(Challenge.StarterCode, "Python") c.formated_samplecode = h.code_to_html(Challenge.SampleCode, "Python") # Post the challenge view content c.challenge = Challenge # Post the parent group directory c.group_id = Challenge.ChallengeGroupID c.group_name = c.groupname # Post the user-level directory data c.challenge_id = Challenge.ChallengeID c.challenge_name = Challenge.Title # Render regular form c.body_content = render("/content_challengeview.html") return render("/theme.html")
def challenge_view(self): # Pull up this challenge's information ChallengeID = request.path[request.path.find("challenge/") + 10:len(request.path)] # Is this a valid integer? if not ChallengeID.isdigit(): abort(status_code=404, detail="Challenge ID \"" + ChallengeID + "\" does not exist.") # Query the challenge Challenge = Challenges.ChallengeQueryID(ChallengeID) if Challenge is None: abort(status_code=404, detail="Challenge ID \"" + ChallengeID + "\" failed to load.") if not Challenge.IsValid: abort(status_code=500, detail="Challenge ID \"" + ChallengeID + "\" failed to load: " + Challenge.ErrorStr) # Find all user solutions to this Challenge... Challenge.solutions = Solutions.SolutionsUserIDChallengeID( session.get("UserID"), ChallengeID) Challenge.attempts = len(Challenge.solutions) Challenge.solved = False # Check if we have solved this challenge for solution in Challenge.solutions: if solution.ResultCode == 1: Challenge.solved = True break # Generate graphics / tables self.__generate_graphics(ChallengeID) # Post the owner group of this challenge c.groupname = Challenges.ChallengesGroupQueryGroupID( Challenge.ChallengeGroupID, False).ChallengeGroupName # Convert the source code into html friendly code # NOTE: We are defaulting everything to just render in Python c.formated_code = h.code_to_html(Challenge.StarterCode, "Python") c.formated_samplecode = h.code_to_html(Challenge.SampleCode, "Python") # Post the challenge view content c.challenge = Challenge # Post the parent group directory c.group_id = Challenge.ChallengeGroupID c.group_name = c.groupname # Post the user-level directory data c.challenge_id = Challenge.ChallengeID c.challenge_name = Challenge.Title # Render regular form c.body_content = render("/content_challengeview.html") return render("/theme.html")