示例#1
0
文件: view.py 项目: comlorda/nive_cms
 def add(self):
     self.ResetFlashMessages()
     typeID = self.GetFormValue("pool_type")
     if not typeID:
         return {
             u"content": u"",
             u"showAddLinks": True,
             u"result": True,
             u"head": u""
         }
     form = ObjectForm(view=self, loadFromType=typeID)
     form.Setup(subset="create", addTypeField=True)
     form.use_ajax = True
     result, data, action = form.Process(redirectSuccess="page_url")
     return {
         u"content": data,
         u"result": result,
         u"cmsview": self,
         u"showAddLinks": False,
         u"head": form.HTMLHead()
     }
示例#2
0
    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()}
示例#3
0
    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())
示例#4
0
    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())