def test_JSONhandler(self): disp = json.JSONDispatcher([_JsonTest]) env = GetMockEnviron(disp) req = framework.HTTPRequest(env) response = disp(req, "_JsonTest") self.assert_(isinstance(response, framework.HttpResponse)) self.assertEqual(response.headers["Content-Type"].value, "application/json") content = simplejson.loads(response.content) self.assertEqual(content, 1)
def main(request): resp = framework.ResponseDocument(request, eqedit_constructor) return resp.finalize() def get_equipment_list(filt=None, start=0, end=20, order_by=None): modelclass = models.Equipment if columns is None: q = dbsession.query(modelclass) else: attrlist = [getattr(modelclass, n) for n in columns] q = dbsession.query(*attrlist) # build filter if one is provided as a dictionary if filt is not None: for name, value in filt.items(): attrib = getattr(modelclass, name) q = q.filter(attrib == value) if order_by: q = q.order_by(getattr(modelclass, order_by)) if end is not None: if start is not None: q = q.slice(start, end) else: q = q.limit(end) return q.all() dispatcher = json.JSONDispatcher([get_equipment_list]) dispatcher = auth.need_authentication(webhelpers.setup_dbsession(dispatcher))
"_str_": str(obj), "value": values} def _modelchecker(obj): try: return obj.__class__.__name__ in _tables except AttributeError: return False # Functions exported to javascript via proxy. _exported = [get_tables, get_table_metadata, get_table_metadata_map, get_choices, get_uidata, query, create, updaterow, deleterow, get_row, get_ids, get_rowdisplay, related_add, related_remove] dispatcher = json.JSONDispatcher(_exported) dispatcher.register_encoder("models", _modelchecker, _convert_instance) dispatcher = auth.need_authentication(webhelpers.setup_dbsession(dispatcher)) ##### for server-side markup requests that provide a basic database editor. #### ##### Code below here will eventually disappear. def doc_constructor(request, **kwargs): doc = HTML5.new_document() doc.stylesheets = ["common.css", "ui.css", "db.css"] doc.scripts = ["MochiKit.js", "proxy.js", "ui.js", "sorttable.js", "db.js"] for name, val in kwargs.items(): setattr(doc, name, val) nav = doc.add_section("navigation")
ps.On() return True def Off(name): ps = _GetPowerSupply(name) ps.Off() return True def MeasureCurrent(name): ps = _GetPowerSupply(name) return ps.MeasureCurrent() def _GetPowerSupply(name): return powersupply.PowerSupply(name.encode("ascii")) class WebReport(object): def SetColumns(self, *args): pass def WriteRecord(self, *args): pass _EXPORTED = [SetVoltage, GetVoltage, On, Off, MeasureCurrent] handler = json.JSONDispatcher(_EXPORTED)
NBSP, )) nav.append(NM("P", {"class_": "title"}, kwargs["title"])) nav.append(NM("P", None, NM("A", {"href": "/auth/logout"}, "logout"))) doc.add_section("container", id="content") doc.add_section("container", id="sidebar") doc.add_section("container", id="messages") return doc @auth.need_login @webhelpers.setup_dbsession def config_main(request): resp = framework.ResponseDocument(request, config_page_constructor, title="Config Editor") return resp.finalize() def config_update(xxx): pass _exported = [config_update] dispatcher = auth.need_authentication( webhelpers.setup_dbsession(json.JSONDispatcher(_exported))) if __name__ == "__main__": pass