Beispiel #1
0
 def _get_page_data(self, page_number):
     log = catch_and_log.CatchAndLog()
     schema = self._get_schema()
     data, _ = CharacterDataSource.fetch_values(self.app_context,
                                                self.data_source_context,
                                                schema, log, page_number)
     return data
Beispiel #2
0
 def _fetch_all_question_answers(self):
     source_class = RawAnswersDataSource
     values = []
     chunk_size = source_class.get_default_chunk_size()
     context_class = source_class.get_context_class()
     source_context = context_class.build_blank_default({}, chunk_size)
     catch_and_log_ = catch_and_log.CatchAndLog()
     sought_page_number = 0
     with catch_and_log_.propagate_exceptions('Loading gradebook data'):
         schema = source_class.get_schema(self._app_context, catch_and_log,
                                          source_context)
         while True:
             data, actual_page_number = source_class.fetch_values(
                 self._app_context, source_context, schema, catch_and_log_,
                 sought_page_number)
             if actual_page_number != sought_page_number:
                 break
             values.extend(data)
             if len(data) < source_context.chunk_size:
                 break
             sought_page_number += 1
     values.sort(key=lambda x: x['user_email'])
     return values
Beispiel #3
0
 def setUp(self):
     appengine_config.PRODUCTION_MODE = False
     self._catch_and_log = catch_and_log.CatchAndLog()
     self._expected = []
Beispiel #4
0
 def _get_schema(self):
     log = catch_and_log.CatchAndLog()
     schema = CharacterDataSource.get_schema(self.app_context, log,
                                             self.data_source_context)
     return schema
    def get(self):
        """Returns a JSON response with a page of data and meta-information.

        The object contains the following fields:
        data:  Data objects from the object.
        log:  Entries made with a base_types.Log object.  These contain:
          timestamp:  Stringified version of the GMT time of the event
          level:  one of 'severe', 'warning', or 'info'
          message:  A string describing the event.
        schema:  A JSON schema describing the names and types of objects
          in the 'data' payload.
        params:  A dictionary containing an echo of the context parameters
          passed in.  These are specific to the sub-type of REST data source.
        source_context:  Any context that the REST data source wishes to
          retain across multiple calls to the same REST object.  It is
          not strictly required to re-send this into subsequent requests
          (as a parameter named 'source_context'), but doing so will provide
          significant performance improvements.  Note that if you are sending
          a 'source_context' parameter, it is not necessary to re-specify
          the set of parameters defining your query each time; these are
          retained in the context.  If you pass parameters which do not
          exactly match those in the source_context, the source_context
          is not used, and a new version with your new parameters is returned.
        """

        if (not roles.Roles.is_super_admin()
                and not roles.Roles.is_course_admin(self.app_context)):
            self.response.set_status(403)
            self.response.write('Forbidden')
            return

        catch_and_log_ = catch_and_log.CatchAndLog()
        data_source_class = self.get_data_source_class()
        context_class = data_source_class.get_context_class()
        page_number = int(self.request.get('page_number') or '0')

        output = {}
        source_context = None
        schema = None
        jobz = None
        with catch_and_log_.consume_exceptions('Building parameters'):
            source_context = self._get_source_context(
                data_source_class.get_default_chunk_size(), catch_and_log_)
        with catch_and_log_.consume_exceptions('Getting data schema'):
            schema = data_source_class.get_schema(self.app_context,
                                                  catch_and_log_,
                                                  source_context)
            output['schema'] = schema
        with catch_and_log_.consume_exceptions('Loading required job output'):
            jobz = data_sources_utils.get_required_jobs(
                data_source_class, self.app_context, catch_and_log_)
        if source_context and schema and jobz is not None:
            with catch_and_log_.consume_exceptions('Fetching results data'):
                data, page_number = data_source_class.fetch_values(
                    self.app_context, source_context, schema, catch_and_log_,
                    page_number, *jobz)
                output['data'] = data
                output['page_number'] = page_number
            with catch_and_log_.consume_exceptions('Encoding context'):
                output['source_context'] = self._encode_context(source_context)
                output['params'] = context_class.get_public_params_for_display(
                    source_context)
        output['log'] = catch_and_log_.get()
        output['source'] = data_source_class.get_name()

        self.response.headers['Content-Type'] = (
            'application/javascript; charset=utf-8')
        self.response.headers['X-Content-Type-Options'] = 'nosniff'
        self.response.headers['Content-Disposition'] = 'attachment'
        self.response.write(transforms.JSON_XSSI_PREFIX +
                            transforms.dumps(output))