当前位置: 首页>>代码示例>>Python>>正文


Python JsonConfigHelper.moveAfter方法代码示例

本文整理汇总了Python中au.edu.usq.fascinator.common.JsonConfigHelper.moveAfter方法的典型用法代码示例。如果您正苦于以下问题:Python JsonConfigHelper.moveAfter方法的具体用法?Python JsonConfigHelper.moveAfter怎么用?Python JsonConfigHelper.moveAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在au.edu.usq.fascinator.common.JsonConfigHelper的用法示例。


在下文中一共展示了JsonConfigHelper.moveAfter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from au.edu.usq.fascinator.common import JsonConfigHelper [as 别名]
# 或者: from au.edu.usq.fascinator.common.JsonConfigHelper import moveAfter [as 别名]
class ManifestActions:
    def __init__(self):
        print "formData=%s" % formData
        
        result = "{}"
        func = formData.get("func")
        oid = formData.get("oid")
        
        if func != "set-package-title":
            nodeId = formData.get("nodeId")
            nodePath = self.__getNodePath(formData.get("parents"), nodeId)
            originalPath = "manifest//%s" % nodeId
        
        self.__object = Services.getStorage().getObject(oid)
        sourceId = self.__object.getSourceId()
        payload = self.__object.getPayload(sourceId)
        self.__manifest = JsonConfigHelper(payload.open())
        payload.close()
        
        if func == "set-package-title":
            title = formData.get("title")
            self.__manifest.set("title", StringEscapeUtils.escapeHtml(title))
            self.__saveManifest()
        if func == "rename":
            title = formData.get("title")
            self.__manifest.set("%s/title" % nodePath, title)
            self.__saveManifest()
        elif func == "move":
            refNodeId = formData.get("refNodeId")
            refNodePath = self.__getNodePath(formData.get("refParents"),
                                             formData.get("refNodeId"));
            moveType = formData.get("type")
            if moveType == "before":
                self.__manifest.moveBefore(originalPath, refNodePath)
            elif moveType == "after":
                self.__manifest.moveAfter(originalPath, refNodePath)
            elif moveType == "inside":
                self.__manifest.move(originalPath, nodePath)
            self.__saveManifest()
        elif func == "update":
            title = StringEscapeUtils.escapeHtml(formData.get("title"))
            hidden = formData.get("hidden")
            hidden = hidden == "true"
            self.__manifest.set("%s/title" % nodePath, title)
            self.__manifest.set("%s/hidden" % nodePath, str(hidden))
            #if self.__manifest.get("%s/id" % nodePath) is None:
            #    print "blank node!"
            self.__saveManifest()
            result = '{ title: "%s", hidden: "%s" }' % (title, hidden)
        elif func == "delete":
            title = self.__manifest.get("%s/title" % nodePath)
            if title:
                self.__manifest.removePath(nodePath)
                self.__saveManifest()
            else:
                title = "Untitled"
            result = '{ title: "%s" }' % title
        
        self.__object.close()
        writer = response.getPrintWriter("text/plain; charset=UTF-8")
        writer.println(result)
        writer.close()
    
    def __getNodePath(self, parents, nodeId):
        parents = [p for p in parents.split(",") if p != ""]
        nodePath = "manifest/%s" % nodeId
        if len(parents) > 0:
            nodePath = ""
            for parent in parents:
                if nodePath == "":
                    nodePath = "manifest/%s"  % parent
                else:
                    nodePath += "/children/%s" % parent
            nodePath += "/children/%s" % nodeId
        return nodePath
    
    def __saveManifest(self):
        manifestStr = String(self.__manifest.toString())
        self.__object.updatePayload(self.__object.getSourceId(),
                                    ByteArrayInputStream(manifestStr.getBytes("UTF-8")))
开发者ID:kiranba,项目名称:the-fascinator,代码行数:82,代码来源:manifest.py

示例2: __init__

# 需要导入模块: from au.edu.usq.fascinator.common import JsonConfigHelper [as 别名]
# 或者: from au.edu.usq.fascinator.common.JsonConfigHelper import moveAfter [as 别名]
class ManifestData:
    def __init__(self):
        pass

    def __activate__(self, context):
        self.velocityContext = context
        auth = context["page"].authentication
        if auth.is_logged_in():
            self.fd = self.vc("formData").get

            print "formData=%s" % self.vc("formData")
            result = "{}"
            func = self.fd("func")
            oid = self.fd("oid")
    
            if func != "update-package-meta":
                nodeId = self.fd("nodeId")
                nodePath = self.__getNodePath(self.fd("parents"), nodeId)
                originalPath = "manifest//%s" % nodeId
    
            self.__object = Services.getStorage().getObject(oid)
            sourceId = self.__object.getSourceId()
            payload = self.__object.getPayload(sourceId)
            self.__manifest = JsonConfigHelper(payload.open())
            payload.close()
    
            if func == "update-package-meta":
                print "*********  update-package-meta ***************"
                metaList = list(self.vc("formData").getValues("metaList"))
                for metaName in metaList:
                    value = self.fd(metaName)
                    self.__manifest.set(metaName, value)
                #title = formData.get("title")
                #self.__manifest.set("title", StringEscapeUtils.escapeHtml(title))
                self.__saveManifest()
            if func == "rename":
                title = self.fd("title")
                self.__manifest.set("%s/title" % nodePath, title)
                self.__saveManifest()
            elif func == "move":
                refNodeId = self.fd("refNodeId")
                refNodePath = self.__getNodePath(self.fd("refParents"),
                                                 self.fd("refNodeId"));
                moveType = self.fd("type")
                if moveType == "before":
                    self.__manifest.moveBefore(originalPath, refNodePath)
                elif moveType == "after":
                    self.__manifest.moveAfter(originalPath, refNodePath)
                elif moveType == "inside":
                    self.__manifest.move(originalPath, nodePath)
                self.__saveManifest()
            elif func == "update":
                title = StringEscapeUtils.escapeHtml(self.fd("title"))
                hidden = self.fd("hidden")
                hidden = hidden == "true"
                self.__manifest.set("%s/title" % nodePath, title)
                self.__manifest.set("%s/hidden" % nodePath, str(hidden))
                #if self.__manifest.get("%s/id" % nodePath) is None:
                #    print "blank node!"
                self.__saveManifest()
                result = '{ title: "%s", hidden: "%s" }' % (title, hidden)
            elif func == "delete":
                title = self.__manifest.get("%s/title" % nodePath)
                if title:
                    self.__manifest.removePath(nodePath)
                    self.__saveManifest()
                else:
                    title = "Untitled"
                result = '{ title: "%s" }' % title
            
            self.__object.close()
        else:
            result = '{ "status": "error", "message": "Only registered users can access this API" }'
        
        writer = self.vc("response").getPrintWriter("text/plain; charset=UTF-8")
        writer.println(result)
        writer.close()
    
    # Get from velocity context
    def vc(self, index):
        if self.velocityContext[index] is not None:
            return self.velocityContext[index]
        else:
            log.error("ERROR: Requested context entry '" + index + "' doesn't exist")
            return None

    def __getNodePath(self, parents, nodeId):
        parents = [p for p in parents.split(",") if p != ""]
        nodePath = "manifest/%s" % nodeId
        if len(parents) > 0:
            nodePath = ""
            for parent in parents:
                if nodePath == "":
                    nodePath = "manifest/%s"  % parent
                else:
                    nodePath += "/children/%s" % parent
            nodePath += "/children/%s" % nodeId
        return nodePath
    
    def __saveManifest(self):
#.........这里部分代码省略.........
开发者ID:kiranba,项目名称:the-fascinator,代码行数:103,代码来源:manifest.py


注:本文中的au.edu.usq.fascinator.common.JsonConfigHelper.moveAfter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。