def get_in_jeeqs(self):
        submission_key = self.request.get('submission_key')

        submission = None

        try:
            submission = ndb.Key(urlsafe=submission_key).get()
        finally:
            if not submission:
                self.error(status_code.StatusCode.forbidden)
                return

        # TODO: We can optimize these kind of calls by never retrieving
        # submission object
        feedbacks = Feedback.query()\
            .filter(Feedback.attempt == submission.key)\
            .filter(Feedback.flagged == False)\
            .order(Feedback.flag_count)\
            .order(-Feedback.date)\
            .fetch(10)

        if feedbacks:
            core.prettify_injeeqs(feedbacks)

        vars = core.add_common_vars({
            'feedbacks': feedbacks,
            'jeeqser': self.jeeqser
        })

        template = core.jinja_environment.get_template('in_jeeqs_list.html')
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #2
0
    def get(self):
        # show this user's previous attempts
        attempts = None

        # get the challenge
        ch_key = self.request.get('ch')
        if not ch_key:
            self.error(StatusCode.forbidden)
            return

        challenge = None

        try:
            challenge = ndb.Key(urlsafe=ch_key).get()
        finally:
            if not challenge:
                self.error(StatusCode.forbidden)
                return

        if (self.jeeqser):
            attempts_q = Attempt.query()\
                .filter(Attempt.author == self.jeeqser.key)\
                .filter(Attempt.challenge == challenge.key)\
                .order(-Attempt.date)

            cursor = self.request.get('cursor') if self.request.get('cursor') \
                else "None"
            if cursor and cursor != "None":
                # a cursor was passed along with the request, we're in
                # the middle of the list of attempts, show "Newer" button
                # to navigate to the newer attempts
                qo = ndb.QueryOptions(start_cursor=ndb.Cursor(urlsafe=cursor))
                has_newer = True
            else:
                # no cursor was passed, we are at the beginning of the list
                # of attempts already and shouldn't display "Newer" button
                qo = ndb.QueryOptions()
                has_newer = False

            attempts, cursor, more = attempts_q.fetch_page(ATTEMPTS_PER_PAGE,
                                                           options=qo)
            if cursor and more:
                cursor = cursor.urlsafe()
            else:
                cursor = ''

        vars = core.add_common_vars({
            'jeeqser': self.jeeqser,
            'attempts': attempts,
            'cursor': cursor,
            'has_newer': has_newer,
            'challenge': challenge,
            'challenge_key': challenge.key,
        })

        template = core.jinja_environment.get_template(
            'recent_attempts_contents.html')
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #3
0
    def get(self):
        vars = core.add_common_vars({
            'jeeqser': self.jeeqser,
            'gravatar_url': self.jeeqser.gravatar_url
            if self.jeeqser else None,
            'login_url': users.create_login_url(self.request.url),
            'logout_url': users.create_logout_url(self.request.url)
        })

        template = core.jinja_environment.get_template('about.html')
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #4
0
    def get(self):
        # get available challenges

        all_challenges = Challenge.query().fetch(100)
        all_challenges.sort(
            cmp=exercise_cmp,
            key=lambda challenge: challenge.exercise_number_persisted)

        jeeqser_challenges = []
        if self.jeeqser:
            jeeqser_challenges = Jeeqser_Challenge\
                .query()\
                .filter(Jeeqser_Challenge.jeeqser == self.jeeqser.key)\
                .fetch(100)

        active_submissions = {}
        for jc in jeeqser_challenges:
            active_submissions[jc.challenge] = jc

        feedbacks = None
        feedbacks_cursor = None

        if self.jeeqser:
            for ch in all_challenges:
                if active_submissions.get(ch.key):
                    jc = active_submissions[ch.key]
                    ch.submitted = True
                    ch.status = jc.status
                    ch.jc = jc

                else:
                    ch.submitted = False

            fph = paging_handler.FeedbacksPagingHandler(self.request)
            feedbacks, feedbacks_cursor, has_newer = \
                fph.get_feedbacks_for_feeqser(self.jeeqser.key)

        all_activities = Activity.query().order(-Activity.date).fetch(10)

        vars = core.add_common_vars({
            'challenges': all_challenges,
            'injeeqs': feedbacks,
            'feedbacks_cursor': feedbacks_cursor,
            'activities': all_activities,
            'jeeqser': self.jeeqser,
            'login_url': users.create_login_url(self.request.url),
            'logout_url': users.create_logout_url(self.request.url)
        })

        template = core.jinja_environment.get_template('home.html')
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #5
0
    def get(self):
        vars = core.add_common_vars(
            {
                "jeeqser": self.jeeqser,
                "gravatar_url": self.jeeqser.gravatar_url if self.jeeqser else None,
                "login_url": users.create_login_url(self.request.url),
                "logout_url": users.create_logout_url(self.request.url),
            }
        )

        template = core.jinja_environment.get_template("about.html")
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #6
0
    def get(self):
        redirect_to = self.request.referer
        challenge = None
        page_vars = {'redirect_to':redirect_to}
        challenge_key = self.request.get('ch')
        if challenge_key:
            challenge = ndb.Key(urlsafe=challenge_key).get()
        if challenge:
            page_vars['challenge'] = challenge

        vars = core.add_common_vars(page_vars)

        template = core.jinja_environment.get_template('admin_challenge.html')
        rendered = template.render(vars)
        self.response.out.write(rendered)
Beispiel #7
0
    def get(self):
        redirect_to = self.request.referer
        all_courses = Course.query().fetch()
        page_vars = {
            'redirect_to':redirect_to,
            'courses': all_courses,
            'jeeqser': self.jeeqser,
            'login_url': users.create_login_url(self.request.url),
            'logout_url': users.create_logout_url(self.request.url)
        }

        vars = core.add_common_vars(page_vars)

        template = core.jinja_environment.get_template('admin_challenge.html')
        rendered = template.render(vars)
        self.response.out.write(rendered)
    def get_activities(self):
        cursor = self.request.get('cursor')
        all_activities = Activity.query().order(-Activity.date)

        if cursor == '':
            activities_for_page, cursor, more = all_activities.fetch_page(10)
            qo = ndb.QueryOptions(start_cursor=ndb.Cursor(urlsafe=cursor.to_websafe_string()))
            activities_for_page, cursor, more = all_activities.fetch_page(10, options=qo)
        else:
            qo = ndb.QueryOptions(start_cursor=ndb.Cursor(urlsafe=cursor))
            activities_for_page, cursor, more = all_activities.fetch_page(10, options=qo)

        vars = core.add_common_vars({'activities': activities_for_page})
        template = core.jinja_environment.get_template('activities_list.html')
        rendered = template.render(vars)
        json_response = json.dumps({'cursor': cursor.to_websafe_string(),
                                    'activities': rendered, 'more': more})
        self.response.write(json_response)
Beispiel #9
0
    def get(self):
        challenge = None
        challenge_key = self.request.get('ch')
        if challenge_key:
            challenge = ndb.Key(urlsafe=challenge_key).get()

        all_courses = Course.query().fetch(1000)
        page_vars = {
            'courses': all_courses,
            'jeeqser': self.jeeqser,
            'login_url': users.create_login_url(self.request.url),
            'logout_url': users.create_logout_url(self.request.url)
        }
        if challenge:
          page_vars['challenge'] = challenge

        vars = core.add_common_vars(page_vars)

        template = core.jinja_environment.get_template('admin_challenge.html')
        rendered = template.render(vars)
        self.response.out.write(rendered)
    def get_feedbacks(self):
        fph = paging_handler.FeedbacksPagingHandler(self.request)
        submission = self.request.get('submission')

        if submission:
            submission = ndb.Key(urlsafe=submission)
            feedbacks, cursor, has_newer = \
                fph.get_feedbacks_for_submission(self.jeeqser.key, submission)
        else:
            feedbacks, cursor, has_newer = \
                fph.get_feedbacks_for_feeqser(self.jeeqser.key)

        vars = core.add_common_vars({
            'jeeqser': self.jeeqser,
            'feedbacks': feedbacks,
            'cursor': cursor,
            'has_newer': has_newer,
            'write_challenge_name': True
        })

        template = core.jinja_environment.get_template('in_jeeqs_list.html')
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #11
0
    def get(self):
        # get available courses
        selected_course = None
        course_query = Course.query()
        courses = course_query.fetch(10)
        course_code = self.request.get("course_code", "6.189")
        course = course_query.filter(Course.code == course_code).get()
        courses[:] = [x for x in courses if x != course]

        # get available challenges
        all_challenges_future = (
            Challenge.query().filter(Challenge.exercise_course_code_persisted == course_code).fetch_async(100)
        )

        jeeqser_challenges_future = None
        if self.jeeqser:
            jeeqser_challenges_future = (
                Jeeqser_Challenge.query()
                .filter(Jeeqser_Challenge.jeeqser == self.jeeqser.key)
                .filter(Jeeqser_Challenge.course_code == course_code)
                .fetch_async(100)
            )

        all_challenges = all_challenges_future.get_result()
        all_challenges.sort(cmp=exercise_cmp, key=lambda challenge: challenge.exercise_number_persisted)

        jeeqser_challenges = []
        if self.jeeqser:
            jeeqser_challenges = jeeqser_challenges_future.get_result()

        active_submissions = {}
        for jc in jeeqser_challenges:
            active_submissions[jc.challenge] = jc

        feedbacks = None
        feedbacks_cursor = None

        if self.jeeqser:
            for ch in all_challenges:
                if active_submissions.get(ch.key):
                    jc = active_submissions[ch.key]
                    ch.submitted = True
                    ch.status = jc.status
                    ch.jc = jc

                else:
                    ch.submitted = False

            fph = paging_handler.FeedbacksPagingHandler(self.request)
            feedbacks, feedbacks_cursor, has_newer = fph.get_feedbacks_for_feeqser(self.jeeqser.key)

            all_activities = Activity.query().order(-Activity.date).fetch(10)
        else:
            all_activities = []

        vars = core.add_common_vars(
            {
                "courses": courses,
                "course": course,
                "challenges": all_challenges,
                "injeeqs": feedbacks,
                "feedbacks_cursor": feedbacks_cursor,
                "activities": all_activities,
                "jeeqser": self.jeeqser,
                "login_url": users.create_login_url(self.request.url),
                "logout_url": users.create_logout_url(self.request.url),
            }
        )

        template = core.jinja_environment.get_template("home.html")
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #12
0
    def get(self):
        # show this user's previous attempts
        attempts = None
        feedbacks = None
        submission = None
        feedbacks_cursor = None
        draft = None

        # get the challenge
        ch_key = self.request.get("ch")
        if not ch_key:
            self.error(StatusCode.forbidden)
            return

        challenge = None

        try:
            challenge = ndb.Key(urlsafe=ch_key).get()
        finally:
            if not challenge:
                self.error(StatusCode.forbidden)
                return

        if not challenge.content and challenge.markdown:
            challenge.content = markdown.markdown(challenge.markdown, ["codehilite", "mathjax"])
            challenge.put()

        attempt = None
        attempt_key = self.request.get("att")
        if attempt_key:
            attempt = submission = ndb.Key(urlsafe=attempt_key).get()

        if self.jeeqser:
            if not submission:
                # fetch user's active submission
                submissions = (
                    Attempt.query()
                    .filter(Attempt.author == self.jeeqser.key)
                    .filter(Attempt.challenge == challenge.key)
                    .filter(Attempt.active == True)
                    .order(-Attempt.date)
                    .fetch(1)
                )

                if submissions:
                    submission = submissions[0]

                else:
                    submission = None

            if submission:
                fph = paging_handler.FeedbacksPagingHandler(self.request)
                feedbacks, feedbacks_cursor, has_newer = fph.get_feedbacks_for_submission(
                    self.jeeqser.key, submission.key
                )

        # Fetch saved draft
        try:
            if self.jeeqser:
                draft = (
                    Draft.query().filter(Draft.author == self.jeeqser.key, Draft.challenge == challenge.key).fetch(1)[0]
                )
        except IndexError:
            draft = None

        vars = core.add_common_vars(
            {
                "server_software": os.environ["SERVER_SOFTWARE"],
                "python_version": sys.version,
                "jeeqser": self.jeeqser,
                "login_url": users.create_login_url(self.request.url),
                "logout_url": users.create_logout_url(self.request.url),
                "challenge": challenge,
                "challenge_key": challenge.key,
                "template_code": challenge.template_code,
                "submission": submission,
                "feedbacks": feedbacks,
                "feedbacks_cursor": feedbacks_cursor,
                "draft": draft,
                "attempt": attempt,
                "user_is_admin": users.is_current_user_admin(),
            }
        )

        template = core.jinja_environment.get_template("solve_a_challenge.html")
        rendered = template.render(vars)
        self.response.write(rendered)
Beispiel #13
0
    def get(self):
        # show this user's previous attempts
        attempts = None
        feedbacks = None
        submission = None
        feedbacks_cursor = None
        draft = None

        # get the challenge
        ch_key = self.request.get('ch')
        if not ch_key:
            self.error(StatusCode.forbidden)
            return

        challenge = None

        try:
            challenge = ndb.Key(urlsafe=ch_key).get()
        finally:
            if not challenge:
                self.error(StatusCode.forbidden)
                return

        if not challenge.content and challenge.markdown:
            challenge.content = markdown.markdown(challenge.markdown,
                                                  ['codehilite', 'mathjax'])
            challenge.put()

        attempt = None
        attempt_key = self.request.get('att')
        if attempt_key:
            attempt = submission = ndb.Key(urlsafe=attempt_key).get()

        if (self.jeeqser):
            if not submission:
                # fetch user's active submission
                submissions = Attempt.query()\
                    .filter(Attempt.author == self.jeeqser.key)\
                    .filter(Attempt.challenge == challenge.key)\
                    .filter(Attempt.active == True)\
                    .order(-Attempt.date)\
                    .fetch(1)

                if submissions:
                    submission = submissions[0]

                else:
                    submission = None

            if submission:
                fph = paging_handler.FeedbacksPagingHandler(self.request)
                feedbacks, feedbacks_cursor, has_newer = \
                    fph.get_feedbacks_for_submission(self.jeeqser.key, submission.key)

        # Fetch saved draft
        try:
            if self.jeeqser:
                draft = Draft.query().filter(
                    Draft.author == self.jeeqser.key,
                    Draft.challenge == challenge.key).fetch(1)[0]
        except IndexError:
            draft = None

        vars = core.add_common_vars({
            'server_software': os.environ['SERVER_SOFTWARE'],
            'python_version': sys.version,
            'jeeqser': self.jeeqser,
            'login_url': users.create_login_url(self.request.url),
            'logout_url': users.create_logout_url(self.request.url),
            'challenge': challenge,
            'challenge_key': challenge.key,
            'template_code': challenge.template_code,
            'submission': submission,
            'feedbacks': feedbacks,
            'feedbacks_cursor': feedbacks_cursor,
            'draft': draft,
            'attempt': attempt,
            'user_is_admin': users.is_current_user_admin(),
        })

        template = core.jinja_environment.get_template(
            'solve_a_challenge.html')
        rendered = template.render(vars)
        self.response.write(rendered)