def delete(self): from google.appengine.ext import ndb from demo.person import Person urlsafe = self.request.path.rsplit('/', 1)[-1] if not urlsafe: return key = ndb.Key(urlsafe=urlsafe) if key.kind() != Person._get_kind(): self.error(500) return key.delete() logging.info("Deleted person with key: %s", urlsafe)
def get(self): from demo.person import Person user_query = self.request.get('query') limit = int(self.request.get('limit', 10)) query = Person.query() if user_query: search = user_query.strip().lower() query = query.filter(Person.n_ >= search) query = query.filter(Person.n_ < search + u"\uFFFD") if limit > 0: query = query.fetch(limit) out = [entity.to_dict() for entity in query] self.response.out.write(json.dumps(out))
def process(self): from voluptuous import Schema from demo.person import Person from demo.person import person_schema person = json.loads(self.request.body) schema = Schema(person_schema, extra=True) try: schema(person) except: logging.exception('validation failed') logging.info(person) person_entity = Person.from_dict(person) person_entity.put() out = person_entity.to_dict() self.response.out.write(json.dumps(out))
枪 类名:Gun 属性:bulletBox 行为:shoot 弹夹 类名:BulletBox 属性:bulletCount 行为: ''' from demo.person import Person from demo.gun import Gun from demo.bulletBox import BulletBox # 弹夹 bulletBox = BulletBox(5) # 枪 gun = Gun(bulletBox) # 人 p = Person(gun) p.fire() p.fire() p.fire() p.fire() p.fillBullet() p.fillBullet() p.fire()