annotate MetaData.py @ 5:c1dbf78cc036

more MetaDataFolder
author casties
date Wed, 27 Jul 2011 14:48:56 +0200
parents 8291255b1868
children 00147a1ab4ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
1 from OFS.Folder import Folder
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
2 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
3 from Globals import package_home
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
4 from AccessControl import ClassSecurityInfo
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
5 import os.path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
6 import urllib
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
7 import logging
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
8 import urlparse
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
9
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
10 # TODO: which xml toolkit?
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
11 import amara
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
12 import xml.sax.saxutils
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
13 import xml.dom.minidom
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
14 import xml.etree.ElementTree as ET
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
15
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
16
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
17 # TODO: do we need this?
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
18 #from Products.OSA_system2 import OSAS_helpers
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
19 #from Products.OSA_system2.OSAS_metadata import OSAS_Metadata,OSAS_MetadataMapping
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
20
2
ac8e119b25ec trying to make import from xml work
casties
parents: 1
diff changeset
21 from MetaDataMapping import MetaDataMapping
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
22 from OSAS_metadata import OSAS_Metadata, OSAS_MetadataMapping
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
23
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
24
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
25 from SrvTxtUtils import getHttpData, getText
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
26
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
27
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
28 # TODO: get rid of this
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
29 def getTextFromNode(nodelist):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
30 """gibt text aus nodelist"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
31 rc = ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
32 for node in nodelist:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
33 if node.nodeType == node.TEXT_NODE:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
34 rc = rc + node.data
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
35 return rc
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
36
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
37
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
38 def toString(list):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
39 ret=u""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
40
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
41 for l in list:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
42 ret+=unicode(l)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
43
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
44 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
45
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
46 def dcMetaDataToHash(mdSet):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
47 """Convenience Function for creates a hash from the DCMetadataset
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
48 @param mdSet: String containing DCMetadata informmation
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
49 currently only in the format getDCMetadata of this module"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
50
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
51 NSS = {
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
52 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
53 'dc': 'http://dublincore.org/documents/dcmi-namespace/',
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
54 'owl':"http://www.w3.org/2002/07/owl#",
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
55 'rdfs':"http://www.w3.org/2000/01/rdf-schema#"
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
56 }
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
57 ret={}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
58 import StringIO
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
59 import sys
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
60 buffer= StringIO.StringIO(mdSet)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
61 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
62 md = amara.parse(buffer,prefixes=NSS)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
63 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
64 logging.error("Error: %s (%s)"%(sys.exc_info()[0],sys.exc_info()[1]))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
65
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
66 ret["error"]=mdSet
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
67 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
68
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
69 ret["title"] = toString(md.xml_xpath("//dc:title/text()"))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
70 ret["creator"] =toString(md.xml_xpath("//dc:creator/text()"))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
71 ret["date"] = toString(md.xml_xpath("//dc:date/text()"))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
72
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
73 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
74
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
75
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
76
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
77
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
78
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
79 class MetaData(OSAS_Metadata):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
80 """provides basic methods for managing metadata structures"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
81 meta_type='MetaData'
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
82 security=ClassSecurityInfo()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
83 manage_options = Folder.manage_options+(
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
84 {'label':'Main Config','action':'changeMetaDataForm'},
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
85 {'label':'Import XML Schema','action':'importMetaDataExportXML'},
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
86 #{'label':'Select Fields for Display','action':'indicateDisplayFieldsForm'},
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
87 )
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
88
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
89 def __init__(self,id,shortDescription='',description='',fields=''):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
90 """initialize a new instance"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
91 self.id = id
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
92 self.shortDescription =shortDescription #label fuer link auf add page
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
93 self.description=description #description of the method for link page
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
94 self.fieldList=fields.split(",")[0:]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
95 self.metaDataServerUrl="" # muss mit change metadata gesetzt werden
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
96
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
97
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
98 def correctPath(self,path,remove=None,prefix=None,cut=0):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
99 """convinience method um einen pfad zu veraendern"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
100 if remove is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
101 path=path.replace(remove,'')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
102 if prefix is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
103 path=os.path.join(prefix,path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
104
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
105 if cut>0:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
106 splitted=path.split("/")
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
107 path="/".join(splitted[0:len(splitted)-cut])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
108 return path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
109
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
110 def importMetaDataExportXML(self,importFile=None,RESPONSE=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
111 """imports metadata from the metadataexportxml file"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
112
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
113 if importFile is None:
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
114 pt=PageTemplateFile('zpt/importMetaDataExportXML', globals()).__of__(self)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
115 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
116
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
117 dom=ET.parse(importFile)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
118 node = dom.getroot()
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
119 if node.tag != 'metadataExport':
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
120 node = dom.find("metadataExport")
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
121
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
122 self.createMappingFromDom(node)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
123
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
124 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
125 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
126
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
127
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
128 def createMappingFromDom(self,metadatanode,metadata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
129 """erzeuge ein Mapping aus dem der metadatanode des xmlformats, metadata ist ein metadataobject"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
130
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
131 if metadata is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
132 metadata=self
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
133
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
134 nodes=metadatanode
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
135
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
136 for node in nodes:
2
ac8e119b25ec trying to make import from xml work
casties
parents: 1
diff changeset
137 logging.debug("node: %s"%repr(node))
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
138 if node.tag=="set":
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
139 set=node
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
140 id=set.get('name')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
141 list=[]
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
142 argList={}
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
143 for entry in set:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
144 genericName=entry.get('genericName')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
145 if set.get('name')=='generic':
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
146 # generic mapping doesn't have labels
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
147 tag = genericName
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
148 label = genericName
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
149 else:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
150 tag=entry.get('tag')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
151 label=entry.get('label')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
152
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
153 if not tag:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
154 # ignore empty tags
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
155 continue
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
156
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
157 description=getText(entry)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
158 argList[tag]={'tag':tag,'label':label,'explanation':description,'status':'optional'}
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
159
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
160 logging.debug("createMappingFromDom: new mapping=%s"%repr(argList))
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
161 metadata._setObject(id,MetaDataMapping(id,id,argList))
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
162
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
163 elif node.tag=="metadata":
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
164 mn=node
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
165 name=mn.get('name')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
166 logging.debug("createMappingFromDom: new metadata=%s"%repr(name))
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
167 metadata._setObject(name,MetaData(name,name))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
168 mdObj=getattr(metadata,name)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
169 mdObj.createMappingFromDom(mn)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
170
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
171 def getMDFromPathOrUrl(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
172 parsedurl = urlparse.urlparse(path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
173 if parsedurl[0] != "":
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
174 # has schema (e.g. http)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
175 url=path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
176 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
177 # path only
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
178 if path.endswith("index.meta"):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
179 url =self.metaDataServerUrl%path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
180 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
181 url=os.path.join(self.metaDataServerUrl%path,'index.meta')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
182
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
183 #logging.debug("get Metadata: %s"%url)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
184 md = getHttpData(url)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
185 return md
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
186
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
187 def getDCFormatted(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
188 """get the metadata as dc set"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
189 logging.debug("getDCFormatted(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
190 namespace={ 'mpiwg': "http://www.mpiwg-berlin.mpg.de/ns/mpiwg"}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
191 namespaceUsed=False
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
192
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
193 md = self.getMDFromPathOrUrl(path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
194 logging.debug("MD in XML"+md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
195 im = amara.parse(md, prefixes=namespace)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
196
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
197 typePaths=im.xml_xpath('//bib/@type')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
198 archimedes=False
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
199
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
200 if len(typePaths)<1:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
201 typePaths=im.xml_xpath('//meta/archimedes') # sinderfall fuer veraltete index.meta files vom typ archimedes
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
202 if len(typePaths)>0:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
203 type = "archimedes"
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
204 archimedes=True
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
205 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
206 typePaths=im.xml_xpath('//mpiwg:bib/@type')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
207 if len(typePaths)<1:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
208 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
209 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
210 namespaceUsed=True
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
211
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
212 type=unicode(typePaths[0])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
213 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
214 type=unicode(typePaths[0])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
215 logging.info("got type:"+type)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
216 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
217 mapping=getattr(self.main.meta.bib,type.lower(),None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
218 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
219 logging.error("getMetaDataFromServer no mapping for type: %s"%type)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
220 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
221
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
222 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
223 dcMapping=getattr(self.main.meta.bib,"dc",None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
224 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
225 logging.error("getMetaDataFromServer no dc in meta/bib")
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
226 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
227
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
228 mds=mapping.generateMappingHash() # Hole das Mapping generisches Feld --> Feld im entsprechenden Typ
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
229 dcMds=dcMapping.generateMappingHash()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
230
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
231 mdHash=[]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
232 logging.debug("Value: %s"%repr(mds))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
233
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
234 for key,valueTriple in mds.items():
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
235 value=valueTriple[0]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
236 logging.debug("Value: %s"%repr(value))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
237 logging.debug("Key: %s"%repr(key))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
238 if value!="":
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
239 if not archimedes:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
240 if namespaceUsed:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
241 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
242 v = im.xml_xpath('//mpiwg:bib/mpiwg:%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
243 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
244 logging.error('cannot do: //mpiwg:bib/mpiwg:%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
245 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
246 v = im.xml_xpath('//bib/%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
247 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
248 v = im.xml_xpath('//archimedes/%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
249 if len(v) > 0:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
250 dc=dcMds[key][0]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
251
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
252 if (dc !="") and (value !=""):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
253 logging.debug("%s--> : %s"%(repr(value),dc))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
254 mdHash.append([dc,unicode(v[0])])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
255
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
256 ret="""<bib xmlns:dc="http://dublincore.org/documents/dcmi-namespace/"> """
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
257 ret+="<dc:type>%s</dc:type>"%type
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
258 for md in mdHash:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
259
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
260 ret+="""<dc:%s>%s</dc:%s>"""%(md[0],xml.sax.saxutils.escape(md[1]),md[0])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
261 ret+="</bib>"
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
262 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
263
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
264
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
265 def getBibMapping(self, bibtype):
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
266 """returns MetaDataMapping for bibtype"""
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
267 # try type as id
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
268 mapping = getattr(self.main.meta.bib, bibtype, None)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
269 if mapping is None:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
270 # try manually
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
271 mapFolder = self.main.meta.bib
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
272 for obj in mapFolder.objectValues():
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
273 if obj.meta_type == "MetadataMapping":
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
274 # real type is in title
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
275 mapType = obj.title
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
276 if mapType == bibtype:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
277 # try type as is
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
278 return obj
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
279
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
280 if normalizeBibField(mapType, underscore=True) == normalizeBibField(bibtype, underscore=True):
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
281 # try normalized type without underscore
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
282 return obj
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
283
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
284 return mapping
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
285
1
e4bae49e657b more renovation
casties
parents: 0
diff changeset
286 def getBibFields(self, bibdata):
e4bae49e657b more renovation
casties
parents: 0
diff changeset
287 """returns dict with metadata description for bibdata"""
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
288 bibfields = {}
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
289 bibtype = bibdata['@type']
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
290 # get mapping from main/meta/bib
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
291 mapping = self.getBibMapping(bibtype)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
292 if mapping is None:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
293 logging.error("getBibFields: no mapping for type: %s"%bibtype)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
294 return bibfields
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
295
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
296 # get field descriptions (copy so we can change it)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
297 bibfields = mapping.getFields().copy()
1
e4bae49e657b more renovation
casties
parents: 0
diff changeset
298 # add field list
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
299 bibfields['@fieldList'] = mapping.getFieldList()
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
300
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
301 return bibfields
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
302
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
303 def getBibMappedData(self, bibdata, allFields=False):
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
304 """returns dict with metadata descriptions and data for bibdata"""
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
305 bibfields = self.getBibFields(bibdata)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
306 mappedData = {}
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
307 mappedList = []
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
308 for bk in bibfields.keys():
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
309 # ignore descriptions without data
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
310 if not bibdata.get(bk, None):
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
311 continue
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
312
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
313 # field description (copy so we can change it)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
314 bf = bibfields[bk].copy()
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
315 # add value
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
316 bf['value'] = bibdata[bk]
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
317 mappedData[bk] = bf
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
318 mappedList.append(bk)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
319
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
320 if allFields and len(mappedData) < len(bibdata):
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
321 # add fields that were not in bibfields
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
322 for bk in bibdata.keys():
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
323 if bk in mappedData or not bibdata[bk]:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
324 continue
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
325
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
326 mappedData[bk] = {'tag':bk, 'label':bk, 'value':bibdata[bk]}
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
327 mappedList.append(bk)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
328
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
329 mappedData['@fieldList'] = mappedList
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
330 return mappedData
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
331
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
332 def getFormatted(self, template, path=None, dom=None, bibdata=None, allFields=False):
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
333 """returns string with document data formatted according to template.
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
334 gets data from server or dom or pre-parsed bibdata."""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
335 logging.debug("getFormatted(template=%s)"%(template))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
336
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
337 if dom is None and bibdata is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
338 # get from server
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
339 md = self.getMDFromPathOrUrl(path.replace("/mpiwg/online",""))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
340 #logging.debug("md:"+md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
341 #dom = amara.parse(md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
342 dom = ET.fromstring(md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
343
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
344 # get contents of bib tag
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
345 if bibdata is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
346 bibdata = getBibdataFromDom(dom)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
347
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
348 bibtype = bibdata['@type']
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
349
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
350 # get template
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
351 tp=getattr(self,"%s_%s"%(template, bibtype.lower()), None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
352 if tp is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
353 logging.warning("getFormatted: no template for: %s_%s"%(template, bibtype))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
354 # try generic
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
355 tp=getattr(self,"%s_generic"%(template), None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
356 if tp is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
357 logging.error("getFormatted: no generic template either: %s"%(template))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
358 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
359
1
e4bae49e657b more renovation
casties
parents: 0
diff changeset
360 # put bib field descriptions in mdHash
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
361 bibfields = self.getBibMappedData(bibdata, allFields=allFields)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
362
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
363 return tp(mdmap=bibfields, md=bibdata)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
364
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
365
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
366 def getFormattedMetaData(self, path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
367 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
368 logging.debug("getFormattedMetaData(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
369 return self.getFormatted('metadata_template', path=path, dom=dom, bibdata=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
370
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
371 def getFormattedMetaDataShort(self, path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
372 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
373 logging.debug("getFormattedMetaDataShort(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
374 return self.getFormatted('metadata_template', path=path, dom=dom, bibdata=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
375
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
376 def getFormattedMetaDataExtended(self,path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
377 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
378 logging.debug("getFormattedMetaDataExtended(path=%s)"%path)
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
379 return self.getFormatted('metadata_extended_template', path=path, dom=dom, bibdata=bibdata, allFields=True)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
380
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
381 def getFormattedLabel(self,path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
382 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
383 logging.debug("getFormattedLabel(%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
384 return self.getFormatted('label_template', path=path, dom=dom, bibdata=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
385
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
386 def getFormattedMetaDataShortFromServer(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
387 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
388 logging.debug("getFormattedMetaDataShortFromServer(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
389 return self.getFormatted('metadata_template', path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
390
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
391 def getFormattedMetaDataExtendedFromServer(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
392 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
393 logging.debug("getFormattedMetaDataExtendedFromServer(path=%s)"%path)
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
394 return self.getFormatted('metadata_extended_template', path=path, allFields=True)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
395
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
396 def getFormattedLabelFromServer(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
397 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
398 logging.debug("getFormattedLabelFromServer(%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
399 return self.getFormatted('label_template', path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
400
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
401
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
402 security.declarePublic('changeMetaDataForm')
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
403 def changeMetaDataForm(self):
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
404 """Main configuration"""
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
405 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMetaData.zpt')).__of__(self)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
406 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
407
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
408 security.declarePublic('changeMetaData')
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
409 def changeMetaData(self,shortDescription,description,fields,metaDataServerUrl,RESPONSE=None):
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
410 """Change Metadata"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
411 self.shortDescription=shortDescription
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
412 self.description=description
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
413 self.fieldList=fields.split(",")[0:]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
414 self.metaDataServerUrl=metaDataServerUrl
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
415 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
416 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
417
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
418
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
419 def manage_addMetaDataForm(self):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
420 """interface for adding the OSAS_add_Metadata"""
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
421 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetaDataForm.zpt')).__of__(self)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
422 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
423
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
424 def manage_addMetaData(self,id,shortDescription,description,fields,RESPONSE=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
425 """a metadata objekt"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
426 newObj=MetaData(id,shortDescription,description,fields)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
427 self.Destination()._setObject(id,newObj)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
428 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
429 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
430