Exemplo n.º 1
0
def updateCollectionFromJson(jsonCollectionStr, htmlGen, dbInst):
    r = json.loads(jsonCollectionStr)
    for k in r:
        data = r[k]
        for i in data:
            c = collectionManager.getCollection(i, dbInst)
            if k == "add":
                op = c.append
            if k == "del":
                op = c.remove
            if k == "update":
                c.removeAll()
                op = c.append

            if type(data[i]) == list:
                for idInCol in data[i]:
                    objFullPath = stringTools.jsIdDecoding(idInCol)
                    objUfsUrl = objTools.getUfsUrl(objFullPath)
                    htmlGen.write(u"%s:" % k + objUfsUrl + u"<br>")
                    # continue
                    op(objUfsUrl)
            else:
                idInCol = data[i]
                objFullPath = stringTools.jsIdDecoding(idInCol)
                objUfsUrl = objTools.getUfsUrl(objFullPath)
                htmlGen.write(u"%s:" % k + objUfsUrl + u"<br>")
                # continue
                op(objUfsUrl)
Exemplo n.º 2
0
def jqueryListOnCollection():
    #Get request param: collectionId, start, cnt
    param = webUtils.paramWithDefault({u"collectionId":u"D:/tmp",u"start":0,u"cnt":100})
    #Get collection from system, collection system contains cached collections and filesystem collections.
    #h.write("<!--")
    #print "hello"
    if not objTools.isUuid(param["collectionId"]):
        #param["collectionId"] = collectionListItems.jsIdEncoding(param["collectionId"])
        param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"])
    #h.write(unicode(str(int(param["start"])))+unicode(str(int(param["cnt"]))))
    co = collectionManager.getCollection(param["collectionId"], dbSys.dbSysSmart())
    containerCo = container.collectionContainer(co, dbSys.dbSysSmart()).getRange(int(param["start"]), int(param["cnt"]))
    #Output
    #h.write(str(co))
    #res = ""
    #h.write("-->")
    if True:#try:
        res = collectionListItem(containerCo)
    else:#except:
        pass
    h = libs.html.response.html()
    #print "hello"
    #h.write("good")
    h.genPartialHtmlHead()
    h.write(res)
    #h.write(l.s)
    #print res
    h.end()
Exemplo n.º 3
0
def jqueryListOnCollection(req):
    #Get request param: collectionId, start, cnt
    param = webUtils.paramWithDefault({u"collectionId":u"C:/",u"start":0,u"cnt":40}, req.getQueryInfo())
    #Get collection from system, collection system contains cached collections and filesystem collections.
    #h.write("<!--")
    #print "hello"
    print param
    if not objTools.isUuid(param["collectionId"]):
        #param["collectionId"] = collectionListItems.jsIdEncoding(param["collectionId"])
        param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"])
    #h.write(unicode(str(int(param["start"])))+unicode(str(int(param["cnt"]))))
    co = collectionManager.getCollection(param["collectionId"], req.getDbSys()).getRange(int(param["start"]), int(param["cnt"]))

    #Output
    #h.write(str(co))
    #res = ""
    #h.write("-->")
    if True:#try:
        resList = collectionListItem(co, req)
    else:#except:
        pass
    #h = libs.html.response.html()
    #print "hello"
    #h.write("good")
    req.resp.genJsonHead()
    req.resp.write(json.dumps(resList, indent = 4))
    #h.write(l.s)
    #print res
    req.resp.end()
Exemplo n.º 4
0
def jqueryListOnCollection(req):
    #Get request param: collectionId, start, cnt
    param = webUtils.paramWithDefault({u"collectionId":u"-1"}, req.getQueryInfo())
    #Get collection from system, collection system contains cached collections and filesystem collections.
    if not objTools.isUuid(param["collectionId"]):
        #It is not uuid://xxxx-xxx-xxx-xxx-xxxx-xxxx
        param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"])
    #Output
    req.resp.genJsonHead()
    if param["collectionId"] == "-1":
        p = ufs.ufsTreeUuidItem()
    #res = path
    else:
        #p = desktopApp.lib.localTreeItem.localTreeItem(path.decode('utf8'))
        if objTools.isUfsUrl(param["collectionId"]):#try:
            p = ufsTreeItem.getUfsTreeItem(param["collectionId"], req)
            #print "after getufstreeitem"
            #res += str(p.listNamedChildren())
        else:#except ValueError:
            #No schema/protocol string. Normal dir
            p = jsTreeItemWithCollectionBackend.jsTreeItemWithCollectionBackend(param["collectionId"], None, req.getDbSys())
    #Get the checked elements in the tree
    try:
        co = collectionManager.getCollection(u"uuid://3b84d155-cc5c-428e-8009-12d5fdc68b2a", req.getDbSys()).getRange(0, None)
    except KeyError:
        co = []
    #print "before containerListJson"
    data = jsTreeNamedItemFunc.containerListJson(p, checkedItems=co)

    #print data
    if data == u"":
        raise "no item, raise exception to prevent loop query"
    req.resp.write(data)
    req.resp.end()
Exemplo n.º 5
0
def jqueryListOnCollection(req):
    #Get request param: collectionId, start, cnt
    param = webUtils.paramWithDefault({u"collectionId":u"-1", u"tree":u"n", u"start":0, u"cnt":40}, req.getQueryInfo())
    #print param

    if param["collectionId"] == "-1":
        ####################################
        # It is the root element of the tree
        ####################################
        collectionItemList = ufs.ufsRootItem()
    elif not objTools.isUuid(param["collectionId"]):
        #############################################
        #It is not uuid://xxxx-xxx-xxx-xxx-xxxx-xxxx
        #############################################
        param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"])
        if not objTools.isUfsUrl(param["collectionId"]):
            param["collectionId"] = u"file:///"+param["collectionId"]
        #Change URL to file:///D:/tmp etc.
        collectionItemList = ufsCollection.getUfsCollection(param["collectionId"], req)
    req.resp.genJsonHead()
    #print collectionItemList.listNamedChildren(0, 40, False)
    ##############################################
    # Get checked item for tree
    ##############################################
    try:
        checkedItemList = collectionManager.getCollection(gCheckedCollectionId, req.getDbSys()).getRange(0, None)
    except KeyError:
        checkedItemList = []
    #print "before containerListJson"
    # Check if we are generating the tree.
    if param["tree"] == u"n":
        #print "false"
        isTree = False
        start = int(param["start"])
        cnt = int(param["cnt"])
    else:
        isTree = True
        start = 0
        cnt = None
    #print start, cnt
    #print >>sys.stderr, "-------------", start, cnt
    #data = "1"
    ####################################################
    # Generate JSON string for collection
    ####################################################
    data = collection2Json.containerListJson(collectionItemList, start, cnt, isTree, req, checkedItemList)
    
    #print data
    if data == u"":
        raise "no item, raise exception to prevent loop query"
    req.resp.write(data)
    req.resp.end()
Exemplo n.º 6
0
def jqueryListOnCollection(req):
    #Get request param: collectionId, start, cnt
    param = webUtils.paramWithDefault({u"collectionId":u"-1"}, req.getQueryInfo())
    #Get collection from system, collection system contains cached collections and filesystem collections.
    if not objTools.isUuid(param["collectionId"]):
        #It is not uuid://xxxx-xxx-xxx-xxx-xxxx-xxxx
        param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"])
    #Output
    if gDebugFlag:
        h = libs.html.response.html()
        h.genHead('Collections')
    res = u""
    res += u'<!--'
    if param["collectionId"] == "-1":
        p = ufs.ufsTreeUuidItem()
    #res = path
    else:
        #p = desktopApp.lib.localTreeItem.localTreeItem(path.decode('utf8'))
        if objTools.isUfsUrl(param["collectionId"]):#try:
            #h.write(realUrl)
            h.setEncoding("utf8")
            p = ufsTreeItem.getUfsTreeItem(param["collectionId"], req)
            #res += str(p.listNamedChildren())
        else:#except ValueError:
            #No schema/protocol string. Normal dir
            p = jsTreeItemWithCollectionBackend.jsTreeItemWithCollectionBackend(param["collectionId"], None, req.getDbSys())
    #Get the checked elements in the tree
    try:
        co = collectionManager.getCollection(u"uuid://3b84d155-cc5c-428e-8009-12d5fdc68b2a", req.getDbSys()).getRange(0, None)
    except KeyError:
        co = []
    data = jsTreeNamedItemFunc.containerList(p, checkedItems=co)
    res +=u'-->'
    #print res,d
    if data == u"":
        raise "no item, raise exception to prevent loop query"
    res += data
    if gDebugFlag:
        h.write(res)
        h.genEnd()
    else:
        print res.encode('gbk')