def get(self, key): beacon = None if key and key != 'add': try: beacon = Beacon.get_by_id(int(key)) except: beacon = None self.redirect("/beacons") return if beacon: rules = [] for rule in Rule.query(): for sr in rule.rules: if sr.beaconid == key: rules.append(rule) break beaconjson = { "nickname": beacon.nickname, "id": key, "uuid": beacon.uuid, "description": beacon.description, "rules": rules } else: beaconjson = { "nickname": None, "id": None, "uuid": None, "description": None, "rules": None } template = JINJA_ENVIRONMENT.get_template('single_beacon.html') self.response.write(template.render({'beacon': beaconjson}))
def post(self, key): beaconid = self.request.get("id") nickname = self.request.get("nickname") beaconuuid = self.request.get("uuid") description = self.request.get("description") try: keyid = int(beaconid) beacon = Beacon.get_by_id(keyid) except Exception: beacon = None if beacon is None: beacon = Beacon( nickname=nickname, uuid=beaconuuid, description=description ) beacon.put() else: beacon.nickname = nickname beacon.uuid = beaconuuid beacon.description = description beacon.put() self.redirect("/beacons")