Esempio n. 1
0
    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)
Esempio n. 2
0
    def get_feedbacks_for_feeqser(self, jeeqserKey):
        qo = ndb.QueryOptions()

        feedbacks_query = Feedback \
            .query() \
            .filter(Feedback.attempt_author == jeeqserKey) \
            .filter(Feedback.flagged == False) \
            .order(Feedback.flag_count) \
            .order(-Feedback.date)

        cursor = "None"
        if self.request.get('cursor'):
            cursor = self.request.get('cursor')

        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

        feedbacks, cursor, more = feedbacks_query.fetch_page(self.feedbacks_per_page, options=qo)
        core.prettify_injeeqs(feedbacks)

        if cursor and more:
            cursor = cursor.urlsafe()
        else:
            cursor = ''

        return feedbacks, cursor, has_newer