Annotation of OSAS/OSA_system/OSAS_addfiles.py, revision 1.20
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.20 ! dwinter 7: try:
! 8: from Products.ECHO_content import ECHO_collection
! 9: except:
! 10: print "Ignoring ECHO_collection import...."
! 11:
1.3 dwinter 12: import urllib
1.1 dwinter 13: import OSAS_add
1.9 dwinter 14: import OSAS_show
1.5 dwinter 15: import string
1.1 dwinter 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
1.18 dwinter 21: import archive # check if this is necessary
1.1 dwinter 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"""
1.17 dwinter 42: pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addDocument.zpt').__of__(self)
1.1 dwinter 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"""
1.2 dwinter 86: return OSAS_add.addImages2(self)
87:
1.1 dwinter 88:
89: def manage_AddOSAS_add_DocumentForm(self):
90: """interface for adding the OSAS_add_Metadata"""
1.17 dwinter 91: pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_document.zpt').__of__(self)
1.1 dwinter 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:
1.2 dwinter 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"""
1.17 dwinter 124: pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addText.zpt').__of__(self)
1.2 dwinter 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"""
1.17 dwinter 143: pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_text.zpt').__of__(self)
1.2 dwinter 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)
1.3 dwinter 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:
1.4 dwinter 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):
1.3 dwinter 176:
1.4 dwinter 177: def spaces(depth):
178: tmp=""
179: k=0
180: while k<2*depth:
181: k+=1
182: tmp=tmp+" "+" "
183: return tmp
1.3 dwinter 184:
1.4 dwinter 185: def retLink(object):
1.5 dwinter 186: return "<input type='checkbox' name='collection' value='%s'>%s</input>"% (string.join(object.getPhysicalPath(),"."),object.title)
1.4 dwinter 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)
1.5 dwinter 194:
1.11 dwinter 195: tmp= tmp+retLink(child[1])+"<br>"+self.printChilds(child[1],depth,items,enddepth)
1.4 dwinter 196: else:
197: tmp=tmp+spaces(2*depth)
1.11 dwinter 198: tmp = tmp+retLink(child[1])
1.3 dwinter 199:
1.4 dwinter 200: return tmp
201:
1.10 dwinter 202: def generateTree(self,depth=10):
1.4 dwinter 203: """Erzeugt HTML-Tree der Collection"""
204:
1.3 dwinter 205: exec("items=self.getPhysicalRoot()."+self.collection+".getCollectionTree()")
1.4 dwinter 206: #print items[0][0]
1.3 dwinter 207:
1.10 dwinter 208: childs=self.printChilds(items[0][0],0,items,depth)
1.3 dwinter 209:
1.5 dwinter 210: return childs
1.3 dwinter 211:
1.5 dwinter 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"""
1.6 dwinter 218: try:
219: urllib.urlopen(self.REQUEST['SERVER_URL']+path+"/index.meta")
1.9 dwinter 220:
1.6 dwinter 221: except:
1.14 dwinter 222: return self.REQUEST['SERVER_URL']+path+"/index.meta file has to exist!"
1.3 dwinter 223:
1.10 dwinter 224: links=[(path,'standard storage')]
225:
226: links+=OSAS_show.readContexts(path) # auslesen von contexten für den link
227: #print "LINK",links
1.15 dwinter 228: #return links
1.9 dwinter 229: self.REQUEST.SESSION['links']=links
1.17 dwinter 230: pt=PageTemplateFile('Products/OSA_system/zpt/contextDataMain.zpt').__of__(self)
1.9 dwinter 231: return pt()
1.5 dwinter 232:
233:
1.14 dwinter 234: def addContextData2(self,path,collection,context,science,practice,source_type,period,link,label,description,content_type,responsible,weight,credits=None):
1.5 dwinter 235: """Hinzufuegen der Resource"""
236: splitted=path.split("/")
1.13 dwinter 237: #print "BLU"
1.5 dwinter 238: id=splitted[len(splitted)-1]
239: title=splitted[len(splitted)-1]
1.6 dwinter 240: metalink=self.REQUEST['SERVER_URL']+path+"/index.meta"
1.13 dwinter 241:
1.9 dwinter 242: #link=TOBEDONE"
1.5 dwinter 243: """Hinzufügen der Ressource"""
1.3 dwinter 244:
1.5 dwinter 245:
246: exec("collection_object=self"+collection)
247:
1.16 dwinter 248: ECHO_collection.manage_addECHO_resource(collection_object,id,title,label,description,content_type,responsible,link,metalink,credits,weight,RESPONSE=None)
1.13 dwinter 249: #print "HI5"
250: try:
251: getattr(collection_object,id).ECHO_getResourceMD()
252: except:
253: """nothing"""
1.12 dwinter 254: #return "BLUByy"
1.5 dwinter 255: return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
256:
1.3 dwinter 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"""
1.17 dwinter 264: pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_add_contextData.zpt').__of__(self)
1.3 dwinter 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"""
1.17 dwinter 276: pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_contextData.zpt').__of__(self)
1.3 dwinter 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)
1.2 dwinter 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"""
1.17 dwinter 308: pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_addPresentation.zpt').__of__(self)
1.2 dwinter 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"""
1.17 dwinter 328: pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_presentation.zpt').__of__(self)
1.2 dwinter 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):
1.18 dwinter 342: """Hinzufüge der Combine Text und Image"""
1.2 dwinter 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:
1.15 dwinter 355:
1.2 dwinter 356:
357: security.declarePublic('combineTextImage_config')
358: def combineTextImage_config(self):
359: """Main configuration"""
1.17 dwinter 360: pt=PageTemplateFile('Products/OSA_system/zpt/ChangeOSAS_combineTextImage.zpt').__of__(self)
1.2 dwinter 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"""
1.18 dwinter 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=[]
1.19 dwinter 417: print "HI"
1.18 dwinter 418: try:
1.19 dwinter 419: projects=self.ZopeFind(self.projects,obj_metatypes=['OSAS_project'],obj_ids=obj_ids)#assumes projects folder somewhere in the hierarchie.
420: print "pr"
1.18 dwinter 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:
1.2 dwinter 441:
442: def combineTextImage2(self,path):
443: """Eingabe von Metadateninformationen"""
1.7 dwinter 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:
1.17 dwinter 452: pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImageFinal.zpt').__of__(self)
1.7 dwinter 453:
454: return pt()
455:
1.18 dwinter 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
1.7 dwinter 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()
1.2 dwinter 487:
488: def manage_AddOSAS_combineTextImageForm(self):
489: """interface for adding the OSAS_add_Metadata"""
1.17 dwinter 490: pt=PageTemplateFile('Products/OSA_system/zpt/AddOSAS_combineTextImage.zpt').__of__(self)
1.2 dwinter 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>