Пример #1
0
  def get(self, prefix=None):
    """ Get JSON data for entity IDs of a model, or all about an entity.

    Depending on the request path, serve as JSON to the response object:
    - for a path of /classname/id, a jobj for that entity
    - for a path of /classname, a list of id-only jobjs for that model
    - or, the results of the method being called (should be R/O!)
    """
    logging.info('GET path=%r, prefix=%r', self.handler.request.path, prefix)
    if self.__get_parser is None:
      self.__get_parser = parsutil.RestUrlParser(self.prefix_to_ignore,
          do_special_method=self.do_get_special_method,
          do_model=self.do_get_model,
          do_model_strid=self.do_get_entity,
          do_model_method=self.do_get_model_method,
          do_model_strid_method=self.do_get_entity_method,
          )
    path = self.handler.request.path

    # hacky/kludgy special-case: serve all model names (TODO: remove this!)
    # (need to have proper %meta special w/methods to get such info!)
    if prefix is not None and path.strip('/') == prefix.strip('/'):
      result = restutil.allModelClassNames()
      logging.info('Hacky case (%r): %r', path, result)
      return self._serve(result)

    result = self.__get_parser.process(path, prefix)
    if result is None or isinstance(result, tuple):
      self.handler.response.set_status(400, 'Invalid URL for GET: %r' % path)
      return self._serve({})
    return self._serve(result)
Пример #2
0
    def get(self, prefix=None):
        """ Get JSON data for entity IDs of a model, or all about an entity.

    Depending on the request path, serve as JSON to the response object:
    - for a path of /classname/id, a jobj for that entity
    - for a path of /classname, a list of id-only jobjs for that model
    - or, the results of the method being called (should be R/O!)
    """
        if not self.is_authorized():
            self.handler.response.set_status(
                403, "You don't have permission to access on this server.")
            return self._serve({})
        logging.info('GET path=%r, prefix=%r', self.handler.request.path,
                     prefix)
        if self.__get_parser is None:
            self.__get_parser = parsutil.RestUrlParser(
                self.prefix_to_ignore,
                do_special_method=self.do_get_special_method,
                do_model=self.do_get_model,
                do_model_strid=self.do_get_entity,
                do_model_method=self.do_get_model_method,
                do_model_strid_method=self.do_get_entity_method,
            )
        path = self.handler.request.path

        # hacky/kludgy special-case: serve all model names (TODO: remove this!)
        # (need to have proper %meta special w/methods to get such info!)
        if prefix is not None and path.strip('/') == prefix.strip('/'):
            result = restutil.allModelClassNames()
            logging.info('Hacky case (%r): %r', path, result)
            return self._serve(result)

        result = self.__get_parser.process(path, prefix)
        if result is None or isinstance(result, tuple):
            self.handler.response.set_status(400,
                                             'Invalid URL for GET: %r' % path)
            return self._serve({})
        return self._serve(result)
Пример #3
0
  def get(self):
    """ Get JSON data for model names, entity IDs of a model, or an entity.

    Depending on the request path, serve as JSON to the response object:
    - for a path of /classname/id, a jobj for that entity
    - for a path of /classname, a list of id-only jobjs for that model
    - for a path of /, a list of all model classnames
    """
    user = users.get_current_user()
    if user is None:
      return self.redirect(users.create_login_url(self.request.uri))

    coon = str(1 + int(self.get_cookie('coon', '0')))
    self.set_cookie('count', coon)
    self.set_cookie('ts', str(int(time.time())))
    failed, model, entity = self._get_model_and_entity(False, False, user)
    if failed: return
    if model is None:
      return self._serve(restutil.allModelClassNames())
    if entity is None:
      return self._serve([jsonutil.id_of(x) for x in model.all()])
    jobj = jsonutil.make_jobj(entity)
    return self._serve(jobj)