def __set__(self, instance, value):
   if type(value) == appengine_text_type:
     # make sure that the text value is valid
     chatter.unwrap(json.loads(value))
     
     # pass the text value straight through
     text = value
   else:
     # convert the json object to a string
     text = json.dumps(chatter.wrap(value))
   db.TextProperty.__set__(self, instance, text)
Ejemplo n.º 2
0
      def post(self, key=None):
        """Decodes the arguments, calls the underlying method, then
        encodes the result to send back."""
        try:
          if remote.admin and not users.is_current_user_admin():
            raise RemoteException(403, 'Must be admin.')

          # get the request and respons objects
          request = chatter.unwrap(json.loads(self.request.body))
          response = {}

          # simple case for static method calls
          if remote.static:
            xx = model
          elif request['sync_before']:
            request['self'].put()
            xx = request['self']
          else:
            xx = model.get(key)
          response['return_val'] = remote.method(xx, **request['args'])
          if (not remote.static) and request['sync_after']:
            response['self'] = xx

          # write it all out
          self.response.headers['Content-Type'] = 'text/json'
          self.response.out.write(json.dumps(chatter.wrap(response)))
        except RemoteException, exc:
          self.error(exc.error_code)
          self.response.headers['Content-Type'] = 'text/plain'
          traceback.print_exc(file=self.response.out)
 def __get__(self, instance, owner):
   # special case for static call
   if instance == None:
     return self
   # otherwise, load the string and convert it to a JSON object
   text = db.TextProperty.__get__(self, instance, owner)
   return chatter.unwrap(json.loads(text))
Ejemplo n.º 4
0
 def post(self):
   """Creates a new entity."""
   try:
     entity = chatter.unwrap(json.loads(self.request.body))
     assert not entity.is_saved()
     entity.put()
     self.response.headers['Content-Type'] = 'text/json'
     self.response.out.write(json.dumps(chatter.wrap(entity)))
   except RemoteException, exc:
     self.error(exc.error_code)
     self.response.headers['Content-Type'] = 'text/plain'
     traceback.print_exc(file=self.response.out)
Ejemplo n.º 5
0
 def unwrap(self_json):
   """Takes a JSON-encodable object returns an instance of this class."""
   attribs = types.DictType((k, chatter.unwrap(v)) for (k,v) in self_json.iteritems())
   if 'id' in attribs:
     entity = new_class.get(attribs['id'])
     if not entity:
       raise RemoteException(404, 'Cannot find entity with ID %s' % attribs['id'])
     for key, value in attribs.iteritems():
       if key != 'id':
         setattr(entity, key, value)
   else:
     entity = new_class(**attribs)
   return entity