Esempio n. 1
0
  def update_entity(self):
    data = json.loads(self.request.body)

    for key, value in data.items():
      if isinstance(value, list) and len(value) > 0 and isinstance(value[0], basestring) and value[0][:4] == "key=":
        self.Entity.__setattr__(self.entity, key, [db.Key(k[4:]) for k in value])
      elif isinstance(value, basestring) and value[:4] == "key=":
        self.Entity.__setattr__(self.entity, key, db.Key(value[4:]))
      else:
        self.Entity.__setattr__(self.entity, key, value)
    self.entity.put()

    self.response.out.write(datastore.to_dict(self.entity))
Esempio n. 2
0
  def get(self):
    self.pre_process()

    # Return entitiy
    if self.entity:
      attr = self.request.get('property')
      if attr:
        self.response.out.write(eval("self.entity.%s" % attr))
      else:
        self.response.out.write(datastore.to_dict(self.entity))

    # Return list of entities
    else:
      page = int(self.request.get('page', 0))
      pageSize = int(self.request.get('pageSize', 50))

      if not self.ancestor:
        entities = self.Entity.all()
      else:
        entities = eval("self.ancestor.%s" % self.entity_type)

      output = [datastore.to_dict(entity) for entity in entities.run(offset=page*pageSize, limit=pageSize)]
      self.response.out.write(json.dumps(output))