File:  [Repository] / OSAS / OSA_system / OSAS_addfiles.py
Revision 1.20: download - view: text, annotated - select for diffs - revision graph
Thu Mar 25 09:57:47 2004 UTC (20 years, 3 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
changes bei simon for new digilib ocnfin in OSAS_rootCVS: ----------------------------------------------------------------------

    1: # Methoden und Classen zum Hinzufuegen von Dokumenten
    2: 
    3: 
    4: from OSAS_helpers import readArchimedesXML, getISO, getText
    5: import os
    6: import xml.dom.minidom
    7: try:
    8:     from Products.ECHO_content import ECHO_collection
    9: except:
   10:     print "Ignoring ECHO_collection import...."
   11:     
   12: import urllib
   13: import OSAS_add
   14: import OSAS_show
   15: import string
   16: from OFS.Folder import Folder
   17: from AccessControl import ClassSecurityInfo
   18: from Globals import InitializeClass
   19: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
   20: from Products.PageTemplates.PageTemplate import PageTemplate
   21: import archive # check if this is necessary
   22: 
   23: class OSAS_add_Document(Folder):
   24:     """Hinzufuegen eines Dokumentes zum Storage"""
   25:     security=ClassSecurityInfo()
   26: 
   27:     def __init__(self,id):
   28:         """initialize a new instance"""
   29:         self.id = id
   30:         
   31:         
   32:     meta_type='OSAS_add_Document'    
   33:     manage_options = Folder.manage_options+(
   34:             {'label':'Main Config','action':'add_Document_config'},
   35:             )
   36:         
   37:      
   38:         
   39:     security.declarePublic('add_Document_config')
   40:     def add_Document_config(self):
   41:         """Main configuration"""
   42:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addDocument.zpt').__of__(self)
   43:         return pt()
   44:     
   45:     security.declarePublic('change_OSAS_add_Document')
   46:     def change_OSAS_add_Document(self,RESPONSE=None):
   47:         """Change"""
   48: #        self.RootFolderName=RootFolderName
   49:         if RESPONSE is not None:
   50:             RESPONSE.redirect('manage_main')
   51: 
   52:     security.declarePublic('index_html')
   53:     def index_html(self):
   54:         """stantard aufruf"""
   55:         return OSAS_add.add(self,no_upload=1)
   56: 
   57: 
   58:     security.declarePublic('add2')
   59:     def add2(self):
   60:         """ anlegen naechster schritt"""
   61:         return OSAS_add.add2(self)
   62: 
   63:     def add3(self):
   64:         """Foldername"""
   65:         return OSAS_add.add3(self)
   66: 
   67:     def add4(self):
   68:         """Applet"""
   69:         return OSAS_add.add4(self)
   70: 
   71:     def add5(self):
   72:         """Foldername"""
   73:         return OSAS_add.add5(self)
   74: 
   75:     def add6(self):
   76:         """write new index.meta file"""
   77:         return OSAS_add.add6(self)
   78: 
   79: 
   80:     def addImages(self,path):
   81:         """Hinzufügen eines neuen Imagesfolders"""
   82:         return OSAS_add.addImages(self,path)
   83: 
   84:     def addImages2(self):
   85:         """Upload des neuen Imagefolders"""
   86:         return OSAS_add.addImages2(self)
   87: 
   88:     
   89: def manage_AddOSAS_add_DocumentForm(self):
   90:     """interface for adding the OSAS_add_Metadata"""
   91:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_document.zpt').__of__(self)
   92:     return pt()
   93: 
   94: def manage_AddOSAS_add_Document(self,id,RESPONSE=None):
   95:     """add the OSAS_root"""
   96:     newObj=OSAS_add_Document(id)
   97:     self.Destination()._setObject(id,newObj)
   98:     if RESPONSE is not None:
   99:         RESPONSE.redirect('manage_main')
  100: 
  101:             
  102: InitializeClass(OSAS_add_Document)
  103: 
  104: 
  105: class OSAS_add_Text(Folder):
  106:     """Hinzufuegen eines Text-Dokumentes zum Storage"""
  107:     security=ClassSecurityInfo()
  108: 
  109:     def __init__(self,id):
  110:         """initialize a new instance"""
  111:         self.id = id
  112:         
  113:         
  114:     meta_type='OSAS_add_Text'    
  115:     manage_options = Folder.manage_options+(
  116:             {'label':'Main Config','action':'add_Text_config'},
  117:             )
  118:         
  119:      
  120:         
  121:     security.declarePublic('add_Text_config')
  122:     def add_Text_config(self):
  123:         """Main configuration"""
  124:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addText.zpt').__of__(self)
  125:         return pt()
  126:     
  127:     security.declarePublic('change_OSAS_add_Text')
  128:     def change_OSAS_add_Text(self,RESPONSE=None):
  129:         """Change"""
  130: #        self.RootFolderName=RootFolderName
  131:         if RESPONSE is not None:
  132:             RESPONSE.redirect('manage_main')
  133: 
  134:     def addText(self,path):
  135:         """Add a fulltext"""
  136:         return OSAS_add.addText(self,path)
  137: 
  138:     def addText2(self):
  139:         """Read the file and store it"""
  140:         return OSAS_add.addText2(self)
  141: def manage_AddOSAS_add_TextForm(self):
  142:     """interface for adding the OSAS_add_Metadata"""
  143:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_text.zpt').__of__(self)
  144:     return pt()
  145: 
  146: def manage_AddOSAS_add_Text(self,id,RESPONSE=None):
  147:     """add the OSAS_root"""
  148:     newObj=OSAS_add_Text(id)
  149:     self.Destination()._setObject(id,newObj)
  150:     if RESPONSE is not None:
  151:         RESPONSE.redirect('manage_main')
  152: 
  153:             
  154: InitializeClass(OSAS_add_Text)
  155: 
  156: class OSAS_add_contextData(Folder):
  157:     """Einfuegen eines Documentes in eine Collection"""
  158:     
  159:     security=ClassSecurityInfo()
  160: 
  161:             
  162:     meta_type='OSAS_add_contextData'    
  163: 
  164:     def __init__(self,id,collection):
  165:         self.id=id
  166:         self.collection=collection
  167: 
  168:     def getChilds(self,id,depth,items):
  169:         list=[]
  170:         for object in items:
  171:             if (depth==object[2])&(id==object[0]):
  172:                 list.append(object)
  173:         return list
  174: 
  175:     def printChilds(self,startItem,depth,items,enddepth):
  176: 
  177:         def spaces(depth):
  178:             tmp=""
  179:             k=0
  180:             while k<2*depth:
  181:                 k+=1
  182:                 tmp=tmp+"&nbsp;"+"&nbsp;"
  183:             return tmp
  184: 
  185:         def retLink(object):
  186:             return "<input type='checkbox' name='collection' value='%s'>%s</input>"% (string.join(object.getPhysicalPath(),"."),object.title)
  187:              
  188:         depth+=1
  189:         childs=self.getChilds(startItem,depth,items)
  190:         tmp=""
  191:         for child in childs:
  192:             if depth < enddepth:
  193:                 tmp=tmp+spaces(depth)
  194:                 
  195:                 tmp= tmp+retLink(child[1])+"<br>"+self.printChilds(child[1],depth,items,enddepth)
  196:             else:
  197:                 tmp=tmp+spaces(2*depth)
  198:                 tmp = tmp+retLink(child[1])
  199: 
  200:         return tmp
  201:                     
  202:     def generateTree(self,depth=10):
  203:         """Erzeugt HTML-Tree der Collection"""
  204:     
  205:         exec("items=self.getPhysicalRoot()."+self.collection+".getCollectionTree()")
  206:         #print items[0][0]
  207: 
  208:         childs=self.printChilds(items[0][0],0,items,depth)
  209:         
  210:         return childs
  211: 
  212:     def getPartners(self):
  213:         """Zeige Partnerliste"""
  214:         exec("items=self.getPhysicalRoot()."+self.collection+".partners.getPartners()")
  215:         return items
  216:     def addContextData(self,path):
  217:         """Hinzufügen zu einer Sammlung"""
  218:         try:
  219:             urllib.urlopen(self.REQUEST['SERVER_URL']+path+"/index.meta")
  220:             
  221:         except:
  222:             return self.REQUEST['SERVER_URL']+path+"/index.meta file has to exist!"
  223: 
  224:         links=[(path,'standard storage')]
  225:         
  226:         links+=OSAS_show.readContexts(path) # auslesen von contexten für den link
  227:         #print "LINK",links
  228:         #return links
  229:         self.REQUEST.SESSION['links']=links
  230:         pt=PageTemplateFile('Products/OSA_system/zpt/contextDataMain.zpt').__of__(self)
  231:         return pt()
  232:     
  233:     
  234:     def addContextData2(self,path,collection,context,science,practice,source_type,period,link,label,description,content_type,responsible,weight,credits=None):
  235:         """Hinzufuegen der Resource"""
  236:         splitted=path.split("/")
  237:         #print "BLU"
  238:         id=splitted[len(splitted)-1]
  239:         title=splitted[len(splitted)-1]
  240:         metalink=self.REQUEST['SERVER_URL']+path+"/index.meta"
  241:         
  242:         #link=TOBEDONE"
  243:         """Hinzufügen der Ressource"""
  244: 
  245:         
  246:         exec("collection_object=self"+collection)
  247:         
  248:         ECHO_collection.manage_addECHO_resource(collection_object,id,title,label,description,content_type,responsible,link,metalink,credits,weight,RESPONSE=None)
  249:         #print "HI5"
  250:         try:
  251:             getattr(collection_object,id).ECHO_getResourceMD()
  252:         except:
  253:             """nothing"""
  254:         #return "BLUByy"
  255:         return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
  256:         
  257:     manage_options = Folder.manage_options+(
  258:             {'label':'Main Config','action':'add_contextData_config'},
  259:             )
  260:         
  261:      
  262:     def add_contextData_config(self):
  263:         """Main configuration"""
  264:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_add_contextData.zpt').__of__(self)
  265:         return pt()
  266:     
  267:     
  268:     def change_OSAS_add_contextData(self,collection,RESPONSE=None):
  269:         """Change"""
  270:         self.collection=collection
  271:         if RESPONSE is not None:
  272:             RESPONSE.redirect('manage_main')
  273:             
  274: def manage_AddOSAS_add_contextDataForm(self):
  275:     """interface for adding the OSAS_add_Metadata"""
  276:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_contextData.zpt').__of__(self)
  277:     return pt()
  278: 
  279: def manage_AddOSAS_add_contextData(self,id,collection,RESPONSE=None):
  280:     """add the OSAS_root"""
  281:     newObj=OSAS_add_contextData(id,collection)
  282:     self.Destination()._setObject(id,newObj)
  283:     if RESPONSE is not None:
  284:         RESPONSE.redirect('manage_main')
  285: 
  286:             
  287: InitializeClass(OSAS_add_contextData)
  288: 
  289: class OSAS_add_Presentation(Folder):
  290:     """Hinzufügen der Presentationsinformationen"""
  291:     security=ClassSecurityInfo()
  292: 
  293:     def __init__(self,id):
  294:         """initialize a new instance"""
  295:         self.id = id
  296:         
  297:         
  298:     meta_type='OSAS_add_Presentation'    
  299:     manage_options = Folder.manage_options+(
  300:             {'label':'Main Config','action':'add_Presentation_config'},
  301:             )
  302:         
  303:      
  304:         
  305:     security.declarePublic('add_Presentation_config')
  306:     def add_Presentation_config(self):
  307:         """Main configuration"""
  308:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addPresentation.zpt').__of__(self)
  309:         return pt()
  310:     
  311:     security.declarePublic('change_OSAS_add_Presentation')
  312:     def change_OSAS_add_Presentation(self,RESPONSE=None):
  313:         """Change"""
  314: #        self.RootFolderName=RootFolderName
  315:         if RESPONSE is not None:
  316:             RESPONSE.redirect('manage_main')
  317: 
  318:     def addPresentation(self,path):
  319:         """Hinzufügen der Presenationsinformation"""
  320:         return OSAS_add.addPresentation(self,path)
  321: 
  322:     def addPresentation2(self):
  323:         """Eingabe von Metadateninformationen"""
  324:         return OSAS_add.addPresentation2(self)
  325:     
  326: def manage_AddOSAS_add_PresentationForm(self):
  327:     """interface for adding the OSAS_add_Metadata"""
  328:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_presentation.zpt').__of__(self)
  329:     return pt()
  330: 
  331: def manage_AddOSAS_add_Presentation(self,id,RESPONSE=None):
  332:     """add the OSAS_root"""
  333:     newObj=OSAS_add_Presentation(id)
  334:     self.Destination()._setObject(id,newObj)
  335:     if RESPONSE is not None:
  336:         RESPONSE.redirect('manage_main')
  337: 
  338:             
  339: InitializeClass(OSAS_add_Presentation)
  340: 
  341: class OSAS_combineTextImage(Folder):
  342:     """Hinzufüge der Combine Text und Image"""
  343:     security=ClassSecurityInfo()
  344: 
  345:     def __init__(self,id):
  346:         """initialize a new instance"""
  347:         self.id = id
  348:         
  349:         
  350:     meta_type='OSAS_combineTextImage'    
  351:     manage_options = Folder.manage_options+(
  352:             {'label':'Main Config','action':'combineTextImage_config'},
  353:             )
  354:         
  355: 
  356:         
  357:     security.declarePublic('combineTextImage_config')
  358:     def combineTextImage_config(self):
  359:         """Main configuration"""
  360:         pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_combineTextImage.zpt').__of__(self)
  361:         return pt()
  362:     
  363:     security.declarePublic('change_OSAS_combineTextImage')
  364:     def change_OSAS_combineTextImage(self,RESPONSE=None):
  365:         """Change"""
  366: #        self.RootFolderName=RootFolderName
  367:         if RESPONSE is not None:
  368:             RESPONSE.redirect('manage_main')
  369:             
  370:     security.declarePublic('combineTextImage')
  371:     def combineTextImage(self,path):
  372:         """Hinzufügen der Presenationsinformation"""
  373:         """gibt input formular zur erstellung des texttools meta tag aus"""
  374: 	files = os.listdir(path)
  375: 	
  376: 	texts=[]
  377: 	imagefolders=[]
  378: 	presentationfolders=[]
  379: 
  380: 	splitted=path.split("/")
  381: 	externxml=readArchimedesXML(splitted[len(splitted)-1])
  382: 	
  383: 	for filename in files:
  384: 		#print "FN",filename
  385: 		if archive.isdigilib2(path+"/"+filename):
  386: 			imagefolders.append(filename)
  387: 			
  388: 		if archive.isFullText(path,filename):
  389: 			#print "HI"
  390: 			texts.append(filename)
  391: 		if archive.isPresentation(path,filename):
  392: 			presentationfolders.append(filename)
  393: 	
  394: 	dom=xml.dom.minidom.parse(path+"/index.meta")
  395: 	try:
  396: 		filelanguage=archive.getText(dom.getElementsByTagName('lang')[0].childNodes)
  397: 	except:
  398: 		filelanguage=""
  399:                 
  400: 	self.REQUEST.SESSION['isolist']=getISO()
  401: 	tmp=getISO().keys()
  402: 	tmp.sort()
  403: 	self.REQUEST.SESSION['isolistsort']=tmp
  404: 	self.REQUEST.SESSION['path']=path
  405: 	self.REQUEST.SESSION['texts']=texts
  406: 	self.REQUEST.SESSION['imagefolders']=imagefolders
  407: 	self.REQUEST.SESSION['presentationfolders']=presentationfolders
  408: 	self.REQUEST.SESSION['filelanguage']=filelanguage
  409: 	self.REQUEST.SESSION['externxml']=externxml
  410: 
  411: 	newtemplate=PageTemplateFile('Products/OSA_system/zpt/ImageandText').__of__(self)
  412: 	return newtemplate()
  413: 	
  414:     def getProjects(self,obj_ids=None):
  415:         """Get the Project title for configuration"""
  416:         ret=[]
  417:         print "HI"
  418:         try:
  419:             projects=self.ZopeFind(self.projects,obj_metatypes=['OSAS_project'],obj_ids=obj_ids)#assumes projects folder somewhere in the hierarchie.
  420:             print "pr"
  421:             for project in projects:
  422:                 ret.append((project[1].title,project[0],project[1]))
  423:             print ret
  424:             return ret
  425:         
  426:         except:
  427:             return [('no Projectfolders','')]
  428: 
  429:     def getTextToolsField(self,path,name,default=''):
  430:         """Lese Textoolsfelder aus index.meta im path aus"""
  431:         
  432:         try:
  433:             dom=xml.dom.minidom.parse(path+"/index.meta")
  434:             node=dom.getElementsByTagName('texttool')[0] #getNode
  435:             subnode=node.getElementsByTagName(name)[0]
  436:             print getText(subnode.childNodes)
  437:             return getText(subnode.childNodes)
  438:         except:
  439:             return default
  440:             
  441: 
  442:     def combineTextImage2(self,path):
  443:         """Eingabe von Metadateninformationen"""
  444:         OSAS_add.combineTextImage2(self,path) # Add images
  445:         splitted=path.split("/")
  446:         linkPath=splitted[len(splitted)-1]
  447:         linkViewerEnvironment="http://nausikaa2.mpiwg-berlin.mpg.de:86/cgi-bin/toc/toc.x.cgi?dir=%s&step=thumb" % linkPath
  448:         self.REQUEST.SESSION['linkViewerEnvironment']=linkViewerEnvironment
  449: 
  450:         writeToContext(path,linkViewerEnvironment,"ECHO standard environment")
  451:         
  452:         pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImageFinal.zpt').__of__(self)
  453: 
  454:         return pt()
  455: 
  456:     def isSelectedProject(self,obj,id):
  457:         """is ausgewählt"""
  458:         
  459:         if self.REQUEST['project']==id:
  460:             return 1
  461:         else:
  462:             return None
  463: 
  464: def writeToContext(path,link,description):
  465:     """Created an additional entry to the index.meta file of path"""
  466:     dom=xml.dom.minidom.parse(path+"/index.meta")
  467:     node=dom.getElementsByTagName('resource')[0]
  468: 
  469:     subnode=dom.createElement('context')
  470: 
  471:     linknode=dom.createElement('link')
  472:     namelinknode=dom.createTextNode(link)
  473:     linknode.appendChild(namelinknode)
  474:     subnode.appendChild(linknode)
  475: 
  476:     linknode=dom.createElement('name')
  477:     namelinknode=dom.createTextNode(description)
  478:     linknode.appendChild(namelinknode)
  479:     subnode.appendChild(linknode)
  480: 
  481:     node.appendChild(subnode)
  482:     
  483:     writefile=file(path+"/index.meta","w")
  484:     #print path+"/index.meta"
  485:     writefile.write(dom.toxml().encode('utf-8'))
  486:     writefile.close()
  487: 
  488: def manage_AddOSAS_combineTextImageForm(self):
  489:     """interface for adding the OSAS_add_Metadata"""
  490:     pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImage.zpt').__of__(self)
  491:     return pt()
  492: 
  493: def manage_AddOSAS_combineTextImage(self,id,RESPONSE=None):
  494:     """add the OSAS_root"""
  495:     newObj=OSAS_combineTextImage(id)
  496:     self.Destination()._setObject(id,newObj)
  497:     if RESPONSE is not None:
  498:         RESPONSE.redirect('manage_main')
  499: 
  500:             
  501: InitializeClass(OSAS_combineTextImage)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>