def GET(self, id): ''' Get all of the data (site data and all site nodes) about a single site. Note that we don't return any Datpoints in this call. Datapoints are only accessible via the Node that contains them. ''' self.sites = model.get_site(id) self.nodes = model.get_nodes_for_site(id) data = [] for site in self.sites: nodes = [] for node in self.nodes: nodes.append({ "id": node.id, "lat": node.lat, "lon": node.lon, "macaddr": node.macaddr, "well_id": node.well_id }) data.append({ # TODO: add other site values here "id": site.id, "name": site.name, "nodes": nodes }) ''' The next set of lines should be pretty self-evident by now - JSONify the data and set the response headers. ''' web.header("Content-Type", "application/json") web.header("Cache-Control", "no-cache") return json.dumps(data[0])
def POST(self): data = self.site_form() if data.validates(): site = model.get_site() if site: model.update_site(site.id, data.d.title, data.d.ga) else: model.add_site(data.d.title, data.d.ga) raise web.seeother('/site')
def GET(self, name, pg=0): page = model.get_page(name) pages = model.get_pages() ga = model.get_site().ga if bool(page): content = self.__getContent(page, pg) pgs = plain.pages(dict(page), pages) return render.page(ga, dict(page), content, pgs) else: raise web.seeother('/home')
def GET(self, id): ''' Get all of the data (site data and all site nodes) about a single site. Note that we don't return any Datpoints in this call. Datapoints are only accessible via the Node that contains them. ''' self.sites = model.get_site(id) self.nodes = model.get_nodes_for_site(id) data = [] for site in self.sites: nodes = [] for node in self.nodes: nodes.append({ "id": node.id, "lat": node.lat, "lon": node.lon, "macaddr": node.macaddr, "node_location": node.node_location }) data.append({ # TODO: add other site values here "id": site.id, "name": site.name, "temp_sp": site.temp_sp, "temp_avg": site.temp_avg, "nodes": nodes }) ''' The next set of lines should be pretty self-evident by now - JSONify the data and set the response headers. ''' web.header("Content-Type", "application/json") web.header("Cache-Control", "no-cache") return json.dumps(data[0])
def GET(self): site = model.get_site() if site: self.site_form.ga.set_value(site.ga) self.site_form.title.set_value(site.title) return render.form(u"Edit Site Properties", self.site_form)