def add(self): name = self.context.app.GetObjectFld("name", "user").copy() name.settings["validator"] = UsernameValidator form = ObjectForm(loadFromType="user", view=self) form.subsets = { "create": {"fields": self.configuration.addfields, "actions": ["create"], "defaultAction": "default"} } form.Setup(subset="create") result, data, action = form.Process(redirectSuccess="obj_url", pool_type="user") return {u"content": data, u"result": result, u"head": form.HTMLHead()}
def add(self): name = self.context.app.GetObjectFld("name", "user").copy() name.settings["validator"] = UsernameValidator form = ObjectForm(loadFromType="user", view=self) form.subsets = { "create": { "fields": self.configuration.addfields, "actions": ["create"], "defaultAction": "default" } } form.Setup(subset="create") result, data, action = form.Process(redirectSuccess="obj_url", pool_type="user") return {u"content": data, u"result": result, u"head": form.HTMLHead()}
def edit(self): pwd = self.context.app.GetObjectFld("password", "user").copy() pwd.settings["update"] = True pwd.required = False form = ObjectForm(loadFromType="user", subset="edit", view=self) def removepasswd(data, obj): try: del data["password"] except: pass form.ListenEvent("loadDataObj", removepasswd) form.subsets = { "edit": {"fields": self.configuration.editfields, "actions": ["edit"], "defaultAction": "defaultEdit"}, } form.Setup(subset="edit") result, data, action = form.Process()#, redirectSuccess="obj_url") return {u"content": data, u"result": result, u"head": form.HTMLHead()}
def edit(self): pwd = self.context.app.GetObjectFld("password", "user").copy() pwd.settings["update"] = True pwd.required = False form = ObjectForm(loadFromType="user", subset="edit", view=self) def removepasswd(data, obj): try: del data["password"] except: pass form.ListenEvent("loadDataObj", removepasswd) form.subsets = { "edit": { "fields": self.configuration.editfields, "actions": ["edit"], "defaultAction": "defaultEdit" }, } form.Setup(subset="edit") result, data, action = form.Process() #, redirectSuccess="obj_url") return {u"content": data, u"result": result, u"head": form.HTMLHead()}
def test_obj2(self, **kw): user = UserO(u"test") root = self.app.GetRoot() obj = root.Create("type1", data1_2, user) self.remove.append(obj.id) v = Viewy() form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.formUrl = "form/url" form.cssID = u"upload" form.css_class = u"niveform" count = self.app.db.GetCountEntries() # edit form.actions = [ Conf(**{"id": "default", "method": "StartObject","name": "Initialize", "hidden":True, "description": "", "css_class":"", "html":"", "tag":""}), Conf(**{"id": "save", "method": "UpdateObj","name": "Save", "hidden":False, "description": "", "css_class":"", "html":"", "tag":""}), Conf(**{"id": "cancel", "method": "Cancel", "name": "Cancel", "hidden":False, "description": "", "css_class":"", "html":"", "tag":""}) ] form.Setup() form.Process() req = {"save$":1} req.update(data1_1) form.request = req form.Process() req = {"cancel$":1} form.request = req form.Process() d = form.LoadObjData() self.assertEqual(count, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.subsets = {u"test": {"fields": [u"ftext",u"funit"], "actions": [u"defaultEdit",u"edit",u"cancel"]}} form.Setup(subset = "test") form.Process() req = {"edit$":1} req.update(data1_2) form.request = req form.Process(values={"fnumber":333}) req = {"cancel$":1} form.request = req form.Process() self.assertEqual(count, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.subsets = {u"test": {"fields": [u"ftext", FieldConf(**{"id": "section1", "name": "Section 1", "datatype": "url"})], "actions": [u"defaultEdit",u"edit",u"cancel"]}} form.subset = "test" form.Setup(subset = "test") form.Process() req = {"edit$":1} req.update(data1_2) form.request = req form.Process() req = {"cancel$":1} form.request = req form.Process() self.assertEqual(count, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.subsets = {u"test": {"fields": [u"ftext", FieldConf(**{"id": "section1", "name": "Section 1", "datatype": "unitlist"})], "actions": [u"defaultEdit",u"edit",u"cancel"]}} try: form.Setup(subset="test3") form.Process() self.assert_(False) except ConfigurationError: pass self.assertEqual(count, self.app.db.GetCountEntries())
def test_obj(self, **kw): root = self.app.GetRoot() v = Viewy() form = ObjectForm(loadFromType="type1", context=root, view=v, request=Request(), app=self.app) form.formUrl = "form/url" form.cssID = u"upload" form.css_class = u"niveform" # create form.actions = [ Conf(**{"id": "default", "method": "StartForm","name": "Initialize", "hidden":True, "description": "", "css_class":"", "html":"", "tag":""}), Conf(**{"id": "create", "method": "CreateObj","name": "Create", "hidden":False, "description": "", "css_class":"", "html":"", "tag":""}), Conf(**{"id": "cancel", "method": "Cancel", "name": "Cancel", "hidden":False, "description": "", "css_class":"", "html":"", "tag":""}) ] form.Setup(addTypeField = True) count = self.app.db.GetCountEntries() result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"default") self.assertEqual(count, self.app.db.GetCountEntries()) req = {"create$":1, "pool_type":"type1"} req.update(data1_1) form.request = req result, data, action=form.Process(values={"fnumber":999}) self.assert_(result) self.assertEqual(action.id,"create") self.assertEqual(count+1, self.app.db.GetCountEntries()) self.remove.append(result.id) req = {"cancel$":1} form.request = req result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"cancel") self.assertEqual(count+1, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=root, view=v, request=Request(), app=self.app) form.subsets = {u"test": {"fields": [u"ftext",u"funit"], "actions": [u"default", u"create",u"cancel"]}} form.Setup(subset = "test", addTypeField = True) result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"default") self.assertEqual(count+1, self.app.db.GetCountEntries()) req = {"create$":1, "pool_type":"type1"} req.update(data1_2) form.request = req result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"create") self.assertEqual(count+2, self.app.db.GetCountEntries()) self.remove.append(result.id) req = {"cancel$":1} form.request = req result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"cancel") self.assertEqual(count+2, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=root, view=v, request=Request(), app=self.app) form.subsets = {u"test": {"fields": [u"ftext", FieldConf(**{"id": "section1", "name": "Section 1", "datatype": "email"})], "actions": [u"default", u"create",u"cancel"]}} form.Setup(subset = "test", addTypeField = True) result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"default") self.assertEqual(count+2, self.app.db.GetCountEntries()) req = {"create$":1, "pool_type":"type1"} req.update(data1_2) form.request = req result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"create") self.assertEqual(count+3, self.app.db.GetCountEntries()) self.remove.append(result.id) req = {"cancel$":1} form.request = req result, data, action=form.Process() self.assert_(result) self.assertEqual(action.id,"cancel") self.assertEqual(count+3, self.app.db.GetCountEntries())
def test_obj2(self, **kw): user = UserO(u"test") root = self.app.GetRoot() obj = root.Create("type1", data1_2, user) self.remove.append(obj.id) v = Viewy() form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.formUrl = "form/url" form.cssID = u"upload" form.css_class = u"niveform" count = self.app.db.GetCountEntries() # edit form.actions = [ Conf( **{ "id": "default", "method": "StartObject", "name": "Initialize", "hidden": True, "description": "", "css_class": "", "html": "", "tag": "" }), Conf( **{ "id": "save", "method": "UpdateObj", "name": "Save", "hidden": False, "description": "", "css_class": "", "html": "", "tag": "" }), Conf( **{ "id": "cancel", "method": "Cancel", "name": "Cancel", "hidden": False, "description": "", "css_class": "", "html": "", "tag": "" }) ] form.Setup() form.Process() req = {"save$": 1} req.update(data1_1) form.request = req form.Process() req = {"cancel$": 1} form.request = req form.Process() d = form.LoadObjData() self.assertEqual(count, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.subsets = { u"test": { "fields": [u"ftext", u"funit"], "actions": [u"defaultEdit", u"edit", u"cancel"] } } form.Setup(subset="test") form.Process() req = {"edit$": 1} req.update(data1_2) form.request = req form.Process(values={"fnumber": 333}) req = {"cancel$": 1} form.request = req form.Process() self.assertEqual(count, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.subsets = { u"test": { "fields": [ u"ftext", FieldConf(**{ "id": "section1", "name": "Section 1", "datatype": "url" }) ], "actions": [u"defaultEdit", u"edit", u"cancel"] } } form.subset = "test" form.Setup(subset="test") form.Process() req = {"edit$": 1} req.update(data1_2) form.request = req form.Process() req = {"cancel$": 1} form.request = req form.Process() self.assertEqual(count, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=obj, view=v, request=Request(), app=self.app) form.subsets = { u"test": { "fields": [ u"ftext", FieldConf( **{ "id": "section1", "name": "Section 1", "datatype": "unitlist" }) ], "actions": [u"defaultEdit", u"edit", u"cancel"] } } try: form.Setup(subset="test3") form.Process() self.assert_(False) except ConfigurationError: pass self.assertEqual(count, self.app.db.GetCountEntries())
def test_obj(self, **kw): root = self.app.GetRoot() v = Viewy() form = ObjectForm(loadFromType="type1", context=root, view=v, request=Request(), app=self.app) form.formUrl = "form/url" form.cssID = u"upload" form.css_class = u"niveform" # create form.actions = [ Conf( **{ "id": "default", "method": "StartForm", "name": "Initialize", "hidden": True, "description": "", "css_class": "", "html": "", "tag": "" }), Conf( **{ "id": "create", "method": "CreateObj", "name": "Create", "hidden": False, "description": "", "css_class": "", "html": "", "tag": "" }), Conf( **{ "id": "cancel", "method": "Cancel", "name": "Cancel", "hidden": False, "description": "", "css_class": "", "html": "", "tag": "" }) ] form.Setup(addTypeField=True) count = self.app.db.GetCountEntries() result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "default") self.assertEqual(count, self.app.db.GetCountEntries()) req = {"create$": 1, "pool_type": "type1"} req.update(data1_1) form.request = req result, data, action = form.Process(values={"fnumber": 999}) self.assert_(result) self.assertEqual(action.id, "create") self.assertEqual(count + 1, self.app.db.GetCountEntries()) self.remove.append(result.id) req = {"cancel$": 1} form.request = req result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "cancel") self.assertEqual(count + 1, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=root, view=v, request=Request(), app=self.app) form.subsets = { u"test": { "fields": [u"ftext", u"funit"], "actions": [u"default", u"create", u"cancel"] } } form.Setup(subset="test", addTypeField=True) result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "default") self.assertEqual(count + 1, self.app.db.GetCountEntries()) req = {"create$": 1, "pool_type": "type1"} req.update(data1_2) form.request = req result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "create") self.assertEqual(count + 2, self.app.db.GetCountEntries()) self.remove.append(result.id) req = {"cancel$": 1} form.request = req result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "cancel") self.assertEqual(count + 2, self.app.db.GetCountEntries()) form = ObjectForm(loadFromType="type1", context=root, view=v, request=Request(), app=self.app) form.subsets = { u"test": { "fields": [ u"ftext", FieldConf(**{ "id": "section1", "name": "Section 1", "datatype": "email" }) ], "actions": [u"default", u"create", u"cancel"] } } form.Setup(subset="test", addTypeField=True) result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "default") self.assertEqual(count + 2, self.app.db.GetCountEntries()) req = {"create$": 1, "pool_type": "type1"} req.update(data1_2) form.request = req result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "create") self.assertEqual(count + 3, self.app.db.GetCountEntries()) self.remove.append(result.id) req = {"cancel$": 1} form.request = req result, data, action = form.Process() self.assert_(result) self.assertEqual(action.id, "cancel") self.assertEqual(count + 3, self.app.db.GetCountEntries())