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