version 1.1, 2009/05/15 13:13:31
|
version 1.7, 2011/07/21 21:58:50
|
Line 32 from DownloadBasket import DownloadBaske
|
Line 32 from DownloadBasket import DownloadBaske
|
from types import * |
from types import * |
import pickle |
import pickle |
import tempfile |
import tempfile |
|
from cdli_files import CDLIFile |
|
from cdli_files import splitatf,checkFile |
from cdli_helpers import * |
from cdli_helpers import * |
|
|
class BasketContent(SimpleItem): |
class BasketContent(SimpleItem): |
"""classe fuer den Inhalt eines Baskets""" |
"""classe fuer den Inhalt eines Baskets""" |
|
|
Line 80 class BasketContent(SimpleItem):
|
Line 82 class BasketContent(SimpleItem):
|
for x in content: |
for x in content: |
if not((x[0] is None) or (x[1] is None)): |
if not((x[0] is None) or (x[1] is None)): |
|
|
|
try: # old version |
contentList.append((x[1].getId(),x[0].getVersionNumber())) |
contentList.append((x[1].getId(),x[0].getVersionNumber())) |
|
except: |
|
contentList.append(x) |
|
|
|
|
logging.debug("cl: %s"%contentList) |
logging.debug("cl: %s"%contentList) |
self.contentList=contentList[0:] |
self.contentList=contentList[0:] |
|
|
Line 134 class uploadATFfinallyThread(Thread):
|
Line 141 class uploadATFfinallyThread(Thread):
|
|
|
self.result="" |
self.result="" |
#find context within ZODB |
#find context within ZODB |
from Zope import DB |
from Zope2 import DB |
conn = DB.open() |
conn = DB.open() |
root = conn.root() |
root = conn.root() |
app = root['Application'] |
app = root['Application'] |
Line 308 class uploadATFThread(Thread):
|
Line 315 class uploadATFThread(Thread):
|
idTmp=self.idTmp |
idTmp=self.idTmp |
self.result="" |
self.result="" |
#find context within ZODB |
#find context within ZODB |
from Zope import DB |
from Zope2 import DB |
conn = DB.open() |
conn = DB.open() |
root = conn.root() |
root = conn.root() |
app = root['Application'] |
app = root['Application'] |
Line 347 class uploadATFThread(Thread):
|
Line 354 class uploadATFThread(Thread):
|
|
|
#make sure that id is a string and not an integer |
#make sure that id is a string and not an integer |
basketId=str(basketId) |
basketId=str(basketId) |
|
logging.info("basketID:"+basketId) |
#TODO: make this configurable, at the moment, rootFolder for cdli has to be cdliRoot |
#TODO: make this configurable, at the moment, rootFolder for cdli has to be cdliRoot |
ctx2=ctx.cdliRoot |
ctx2=ctx.cdliRoot |
|
|
#get temporary file for staging the downloaded and splitted files |
#get temporary file for staging the downloaded and splitted files |
dir=tempfile.mkdtemp() |
dir=tempfile.mkdtemp() |
|
|
|
logging.info("tmpfFile:"+str(dir)) |
changed=[] # changed files |
changed=[] # changed files |
errors=[] # files with errors |
errors=[] # files with errors |
lockerrors=[] # files with errors |
lockerrors=[] # files with errors |
Line 363 class uploadATFThread(Thread):
|
Line 370 class uploadATFThread(Thread):
|
psNotInCatalog=[] # files not in the catalog |
psNotInCatalog=[] # files not in the catalog |
|
|
#split the uploadedd atf file |
#split the uploadedd atf file |
|
logging.info("start splitting") |
basketNameFromFile, numberOfFiles=splitatf(upload,dir,ext=self) |
basketNameFromFile, numberOfFiles=splitatf(upload,dir,ext=self) |
|
|
#find basketId if not set |
#find basketId if not set |
Line 572 class CDLIBasketContainer(OrderedFolder)
|
Line 580 class CDLIBasketContainer(OrderedFolder)
|
|
|
security.declareProtected('manage','uploadBasket_html') |
security.declareProtected('manage','uploadBasket_html') |
|
|
|
def uploadBasketAsync_html(self,basketId='0'): |
|
"""upload an atf file, html form, jetzt aufruf der nicht asyncronen version mit ticktes""" |
|
|
|
|
|
basketId=str(basketId) |
|
if not basketId=='0': |
|
basketName=getattr(self.basketContainer,basketId).title |
|
else: |
|
basketName="" |
|
|
|
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','uploadBasketAsync_html.zpt')).__of__(self) |
|
return pt(basketId=basketId,basketName=basketName) |
|
|
|
|
|
|
def uploadBasket_html(self,basketId='0'): |
def uploadBasket_html(self,basketId='0'): |
"""upload an atf file, html form""" |
"""upload an atf file, html form""" |
|
|
Line 997 class CDLIBasket(Folder,CatalogAware):
|
Line 1020 class CDLIBasket(Folder,CatalogAware):
|
return versions |
return versions |
|
|
|
|
def updateObjects(self,ids,RESPONSE=None,REQUEST=None): |
def updateObjects(self,ids=[],RESPONSE=None,REQUEST=None): |
"""update ids, ids not in the basket the add""" |
"""update ids, ids not in the basket then add""" |
|
logging.debug("update") |
|
logging.debug(repr(ids)) |
if type(ids) is not ListType: |
if type(ids) is not ListType: |
ids=[ids] |
ids=[ids] |
|
|
Line 1006 class CDLIBasket(Folder,CatalogAware):
|
Line 1031 class CDLIBasket(Folder,CatalogAware):
|
oldContent=lastVersion.content.getContent() |
oldContent=lastVersion.content.getContent() |
newContent=[] |
newContent=[] |
|
|
#first copy the old |
#keine ids dann alle update |
|
if len(ids)==0: |
|
ids=[x[0] for x in oldContent] |
|
|
|
#first copy the id not to be updated |
for obj in oldContent: |
for obj in oldContent: |
|
logging.debug("obj:"+repr(obj)) |
|
try: # old format of the basket |
if obj[1].getId() not in ids: |
if obj[1].getId() not in ids: |
newContent.append(obj) |
newContent.append(obj) |
|
except: |
|
if obj[0] not in ids: |
|
newContent.append(obj) |
#now add the new |
#now add the new |
|
|
for id in ids: |
for id in ids: |
Line 1018 class CDLIBasket(Folder,CatalogAware):
|
Line 1052 class CDLIBasket(Folder,CatalogAware):
|
for found in founds: |
for found in founds: |
if found.getObject() not in oldContent: |
if found.getObject() not in oldContent: |
#TODO: was passiert wenn, man eine Object dazufuegt, das schon da ist aber eine neuere version |
#TODO: was passiert wenn, man eine Object dazufuegt, das schon da ist aber eine neuere version |
newContent.append((found.getObject().getLastVersion(),found.getObject())) |
newContent.append((id,found.getObject().getLastVersion().getVersionNumber())) |
|
|
|
|
content=newContent |
content=newContent |
user=self.getActualUserName() |
user=self.getActualUserName() |
|
logging.debug(newContent) |
ob=manage_addCDLIBasketVersion(self,user,comment="",basketContent=newContent) |
ob=manage_addCDLIBasketVersion(self,user,comment="",basketContent=newContent) |
|
|
obj=self._getOb(ob.getId()) |
obj=self._getOb(ob.getId()) |
|
logging.debug(repr(obj)) |
|
logging.debug("done") |
|
logging.debug(obj.absolute_url()) |
if RESPONSE: |
if RESPONSE: |
|
logging.debug("redirect") |
RESPONSE.redirect(obj.absolute_url()) |
RESPONSE.redirect(obj.absolute_url()) |
|
|
return obj |
return obj |
Line 1120 class CDLIBasket(Folder,CatalogAware):
|
Line 1157 class CDLIBasket(Folder,CatalogAware):
|
|
|
retrieved = self.CDLICache.retrieve(hash) |
retrieved = self.CDLICache.retrieve(hash) |
if retrieved: |
if retrieved: |
|
logging.debug("add Objects: retrieved") |
newContent=Set(map(swap,retrieved)) |
newContent=Set(map(swap,retrieved)) |
else: |
else: |
|
logging.debug("add Objects: new") |
newContent=Set([(self.getFileObjectLastVersion(x),self.getFileObject(x)) for x in ids]) |
newContent=Set([(self.getFileObjectLastVersion(x),self.getFileObject(x)) for x in ids]) |
|
|
|
|
Line 1164 class CDLIBasket(Folder,CatalogAware):
|
Line 1203 class CDLIBasket(Folder,CatalogAware):
|
|
|
return lv.getComment(),lv.getUser(),lv.getTime(),ret |
return lv.getComment(),lv.getUser(),lv.getTime(),ret |
|
|
def changeBasket(self,ids,submit,RESPONSE=None,REQUEST=None): |
def changeBasket(self,submit,ids=[],RESPONSE=None,REQUEST=None): |
"""change a basket""" |
"""change a basket""" |
if submit=="update": |
if submit=="update": |
return self.updateObjects(ids,RESPONSE=RESPONSE,REQUEST=REQUEST) |
self.updateObjects(ids,RESPONSE=RESPONSE,REQUEST=REQUEST) |
elif submit=="delete": |
elif submit=="delete": |
return self.deleteObjects(ids,RESPONSE=RESPONSE,REQUEST=REQUEST) |
self.deleteObjects(ids,RESPONSE=RESPONSE,REQUEST=REQUEST) |
|
|
def deleteObjects(self,ids,RESPONSE=None,REQUEST=None): |
def deleteObjects(self,ids,RESPONSE=None,REQUEST=None): |
"""delete objects""" |
"""delete objects""" |
Line 1529 class CDLIBasketVersion(Implicit,Persist
|
Line 1568 class CDLIBasketVersion(Implicit,Persist
|
|
|
def getObjUrl(self,result): |
def getObjUrl(self,result): |
"""getUrl of the version of the object""" |
"""getUrl of the version of the object""" |
|
logging.debug("getObjUrl:"+result) |
founds=self.CDLICatalog.search({'title':result}) |
founds=self.CDLICatalog.search({'title':result}) |
if len(founds)>0: |
if len(founds)>0: |
return founds[0].getObject().getLastVersion().absolute_url() |
logging.debug("getObjUrl: founds 1") |
|
logging.debug("getObjUrl:"+repr(founds[0].getObject())) |
|
#return founds[0].getObject().getLastVersion().absolute_url() |
|
return founds[0].getObject().absolute_url() |
|
|
else: #assume version number |
else: #assume version number |
|
logging.debug("getObjUrl: founds 2") |
splitted=result.split("_") |
splitted=result.split("_") |
founds=self.CDLICatalog.search({'title':splitted[1]}) |
founds=self.CDLICatalog.search({'title':splitted[1]}) |
return founds[0].getObject().getLastVersion().absolute_url()+'/'+result |
return founds[0].getObject().getLastVersion().absolute_url()+'/'+result |