def post(self): rooms_to_delete = json.loads(self.request.body) if not rooms_to_delete: self.redirect('/rooms') return locations = [Location.get_by_key_name(room) for room in rooms_to_delete] comforts = [c for c in Comfort.all()] for location in locations: comforts_to_remove = filter(lambda c: c.loc_building == location.building and \ c.loc_floor == location.floor and \ c.loc_room == location.room, comforts) db.delete(comforts_to_remove) db.delete(location) memcache.delete(MC_LOCATIONS_KEY)
def post(self): rooms_to_delete = json.loads(self.request.body) if not rooms_to_delete: self.redirect('/rooms') return locations = [ Location.get_by_key_name(room) for room in rooms_to_delete ] comforts = [c for c in Comfort.all()] for location in locations: comforts_to_remove = filter(lambda c: c.loc_building == location.building and \ c.loc_floor == location.floor and \ c.loc_room == location.room, comforts) db.delete(comforts_to_remove) db.delete(location) memcache.delete(MC_LOCATIONS_KEY)
def comforts_by_location(self, location): """Gets the comfort records for a location. Looks for a location in the format '<building>-<floor>-<room>', '<building>-<floor>', or '<building>' and pulls the specified records from the database. If no location is specified, pulls all records""" if location and not valid.location(location): self.error_code = errors.INVALID_LOCATION_FORMAT return [] if not location: comforts = [comfort for comfort in Comfort.all()] else: location_identifiers = tuple(location.split(DELIMITER)) if len(location_identifiers) == 3: comforts = Comfort.by_room(*location_identifiers) elif len(location_identifiers) == 2: comforts = Comfort.by_floor(*location_identifiers) else: comforts = Comfort.by_building(*location_identifiers) return comforts