def get(self): triggers = Trigger.query() triggerdetails = [] for trigger in triggers: valuepair = {} valuepair.update({ 'id': trigger.key.id(), 'description': trigger.description, 'nickname': trigger.nickname }) groups = Group.query() trigrp = [] for group in groups: if trigger.key.id() in group.triggerids: grpvp = { 'id': group.key.id(), 'nickname': group.nickname } trigrp.append(grpvp) tribea = [] beacons = Beacon.query() for beacon in beacons: for groupid in beacon.groupids: if (trigger.key.id() in Group.get_by_id(groupid).triggerids): beavp = { 'id': beacon.key.id(), 'nickname': beacon.nickname, } tribea.append(beavp) valuepair.update({'groups': trigrp, 'beacons': tribea}) triggerdetails.append(valuepair) final = {'triggers': triggerdetails} template = JINJA_ENVIRONMENT.get_template('manage_triggers.html') self.response.write(template.render(final))
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 get(self): groups = Group.query() groupdetails = [] for group in groups: valuepair = {} valuepair.update( { 'nickname': group.nickname, 'description': group.description, 'groupid': group.key.id() } ) beacons = Beacon.query() grpbea = [] for beacon in beacons: if group.key.id() in beacon.groupids: beavp = {} beavp.update( { 'id': beacon.key.id(), 'nickname': beacon.nickname } ) grpbea.append(beavp) grptri = [] for grtri in group.triggerids: trigger = Trigger.get_by_id(grtri) trivp = {} trivp.update({'id': grtri, 'nickname': trigger.nickname}) grptri.append(trivp) valuepair.update({'beacons': grpbea, 'triggers': grptri}) groupdetails.append(valuepair) final = {'groups': groupdetails} template = JINJA_ENVIRONMENT.get_template('manage_groups.html') self.response.write(template.render(final))
def get(self): beacons = Beacon.query() beacondetails = [] for beacon in beacons: valuepair = {'beaconid': beacon.key.id()} valuepair.update({'nickname': beacon.nickname}) valuepair.update({'uuid': beacon.uuid}) valuepair.update({'description': beacon.description}) beacondetails.append(valuepair) final = {} final.update({'beacons': beacondetails}) template = JINJA_ENVIRONMENT.get_template('manage_beacons.html') self.response.write(template.render(final))
def get(self, event_slug): event = Event.query(Event.name == event_slug).fetch() event = event[0] ctx = {} if not event: ctx.update({ 'status': AJAX_ERROR, }) response_dict = json.dumps(ctx) self.response.write(response_dict) return event_building = event.building # get all groups of beacons in the building. groups = Group.query(Group.building == event_building).fetch() # Map all the beacons according to the groups they belong groupids = map(lambda d: (d.key.id(), d.nickname), groups) groupid_dict = dict((x, y) for x, y in groupids) beacons = Beacon.query(Beacon.groupids.IN(groupid_dict.keys())).fetch() groups_dict = {} # Beacons store ids, hence such a complex proces. # Key Property would have solved the issue but nevertheless f**k it. for beacon in beacons: groups_of_beacon = beacon.groupids for id in groups_of_beacon: if not groups_dict.get(groupid_dict[id]): groups_dict.update({ groupid_dict[id]: [beacon.to_dict()] }) else: beacons_in_group = groups_dict[groupid_dict[id]] beacons_in_group.append(beacon.to_dict()) groups_dict[groupid_dict[id]] = beacons_in_group event = event.to_dict() building = event.pop('building') event_building = get_building_str(building) event_time = event.pop('time') event_time = event_time.strftime("%d/%m/%Y %H:%M:%S") event['time'] = event_time, event['building'] = event_building ctx.update({ 'status': AJAX_OK, 'groups_of_beacons': groups_dict, 'event': event, }) json_response = json.dumps(ctx) self.response.headers['Content-Type'] = 'application/json' return self.response.out.write(json_response)
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")
def get(self, event_slug): event = Event.query(Event.name == event_slug).fetch() event = event[0] ctx = {} if not event: ctx.update({ 'status': AJAX_ERROR, }) response_dict = json.dumps(ctx) self.response.write(response_dict) return event_building = event.building # get all groups of beacons in the building. groups = Group.query(Group.building == event_building).fetch() # Map all the beacons according to the groups they belong groupids = map(lambda d: (d.key.id(), d.nickname), groups) groupid_dict = dict((x, y) for x, y in groupids) beacons = Beacon.query(Beacon.groupids.IN(groupid_dict.keys())).fetch() groups_dict = {} # Beacons store ids, hence such a complex proces. # Key Property would have solved the issue but nevertheless f**k it. for beacon in beacons: groups_of_beacon = beacon.groupids for id in groups_of_beacon: if not groups_dict.get(groupid_dict[id]): groups_dict.update({groupid_dict[id]: [beacon.to_dict()]}) else: beacons_in_group = groups_dict[groupid_dict[id]] beacons_in_group.append(beacon.to_dict()) groups_dict[groupid_dict[id]] = beacons_in_group event = event.to_dict() building = event.pop('building') event_building = get_building_str(building) event_time = event.pop('time') event_time = event_time.strftime("%d/%m/%Y %H:%M:%S") event['time'] = event_time, event['building'] = event_building ctx.update({ 'status': AJAX_OK, 'groups_of_beacons': groups_dict, 'event': event, }) json_response = json.dumps(ctx) self.response.headers['Content-Type'] = 'application/json' return self.response.out.write(json_response)
def get(self): actions = Action.query() data = [] for action in actions: rules = Rule.query().filter(Rule.actionid == action.key) beacons = [] for rule in rules: for simplerule in rule.rules: beacons.append(Beacon.query(key=simplerule.beaconid)) data.append({ 'id': action.key.id(), 'nickname': action.nickname, 'type': action.type, 'payload': action.payload, 'description': action.description, 'rules': rules, 'beacons': beacons }) template = JINJA_ENVIRONMENT.get_template('manage_actions.html') self.response.write(template.render({'actions': data}))
def get(self): beacons = [] for beacon in Beacon.query(): beacons.append({ "id": beacon.uuid, "nickname": beacon.nickname, "description": beacon.description }) actions = [] for action in Action.query(): actions.append({ "nickname": action.nickname, "description": action.description, "payload": action.payload, "type": action.type, "id": action.key.id() }) rules = [] jsons = JSONDump.query() for js in jsons: rules = json.loads(js.jsondata) data = {"beacons": beacons, "actions": actions, "rules": rules['data']} self.response.write(json.dumps(data))