annotate MetaData.py @ 26:a19575be96e8

getDRI reshuffled, works on python 2.6. now.
author casties
date Mon, 30 Jul 2012 19:43:23 +0200
parents d036de7fd78d
children a0d273542509
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 logging
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
6
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
7 import xml.etree.ElementTree as ET
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
8
2
ac8e119b25ec trying to make import from xml work
casties
parents: 1
diff changeset
9 from MetaDataMapping import MetaDataMapping
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
10 from SrvTxtUtils import getHttpData, getText
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
11
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
12 def normalizeFieldName(bt, underscore=True):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
13 """returns normalised field type for looking up mappings"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
14 bt = bt.strip().replace(' ', '-').lower()
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
15 if underscore:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
16 bt = bt.replace('_', '-')
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
17
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
18 return bt
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
19
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
20 def putAppend(hash, key, value):
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
21 """puts value in dict hash at key if it doesn't exist or adds value to a list"""
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
22 #logging.debug("putAppend(hash=%s, key=%s, value=%s)"%(hash,key,value))
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
23 if key in hash:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
24 # key exists
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
25 oldval = hash[key]
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
26 if isinstance(oldval, list):
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
27 # is list already - append
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
28 oldval.append(value)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
29 else:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
30 # needs list
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
31 val = [oldval, value]
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
32 hash[key] = val
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
33
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
34 else:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
35 # key doesn't exist
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
36 hash[key] = value
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
37
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
38 #logging.debug("putAppend returns hash=%s"%(hash))
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
39 return hash
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
40
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
41
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
42 class MetaData(Folder):
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
43 """provides basic methods for managing metadata structures"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
44 meta_type='MetaData'
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
45 security=ClassSecurityInfo()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
46 manage_options = Folder.manage_options+(
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
47 {'label':'Main Config','action':'changeMetaDataForm'},
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
48 {'label':'Import XML Schema','action':'importMetaDataExportXML'},
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
49 #{'label':'Select Fields for Display','action':'indicateDisplayFieldsForm'},
0
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
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
52 mappingSelectAttribute = None
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
53 """the name of the attribute that can be used to select a mapping (if applicable)"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
54
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
55 def __init__(self,id,title=None,shortDescription='',description='',fields=''):
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
56 """initialize a new instance"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
57 self.id = id
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
58 # title is tag name
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
59 if title:
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
60 self.title = title
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
61 else:
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
62 # assume id is tag name
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
63 self.title = id
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
64
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
65 self.shortDescription =shortDescription #label fuer link auf add page
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
66 self.description=description #description of the method for link page
13
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
67 if fields:
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
68 self.fieldList=fields.split(",")[0:]
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
69 #self.metaDataServerUrl="" # muss mit change metadata gesetzt werden
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
70
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
71
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
72 def getFieldList(self):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
73 """returns fieldList"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
74 return ','.join(self.fieldList)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
75
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
76 def getTagName(self):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
77 """returns the tag name of this element"""
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
78 if self.title:
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
79 return self.title
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
80 else:
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
81 return self.shortDescription
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
82
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
83 def getXmlPath(self, omitRoot=False):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
84 """returns the xpath to this element"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
85 path = '/%s'%self.getTagName()
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
86 parent = self.aq_parent
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
87 if parent.meta_type == self.meta_type:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
88 # add parent
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
89 path = parent.getXmlPath(omitRoot=omitRoot) + path
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
90 elif omitRoot:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
91 return ''
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
92
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
93 return path
7
e959bc6bf2a7 starting use for other metadata elements
casties
parents: 6
diff changeset
94
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
95 def getSubDom(self, path=None, dom=None, all=False):
14
281d223aa361 attribution works now
casties
parents: 13
diff changeset
96 """returns the subtree (list) of the dom rooted in this element"""
8
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
97 if dom is None:
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
98 # get from server
20
9a1e75e708e1 small bugs
dwinter
parents: 17
diff changeset
99 dom = self.getDomFromPathOrUrl(path)
8
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
100
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
101 # ElementTree doesn't like absolute paths
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
102 # lets assume dom is rooted in the first element
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
103 xpath = '.' + self.getXmlPath(omitRoot=True)
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
104 logging.debug("getSubDom looking for %s in %s"%(xpath, dom))
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
105 if all:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
106 elem = dom.findall(xpath)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
107 else:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
108 elem = dom.find(xpath)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
109
8
4cd862bf37a3 more renovation
casties
parents: 7
diff changeset
110 return elem
7
e959bc6bf2a7 starting use for other metadata elements
casties
parents: 6
diff changeset
111
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
112
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
113 def _getData(self, elem, recursive, normalizeNames=False, all=False, allText=False):
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
114 """helper method for getData()"""
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
115 #logging.debug("_getDataFromDom(dom=%s, recursive=%s)"%(elem,recursive))
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
116 data = {}
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
117 attr = {}
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
118 # put attributes in @attr
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
119 for attname in elem.keys():
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
120 attr[attname] = elem.get(attname)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
121
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
122 if attr:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
123 data['@attr'] = attr
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
124
17
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
125 # put text in @text
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
126 if elem.text:
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
127 data['@text'] = elem.text
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
128
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
129 for e in elem:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
130 # put all child elements in data
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
131 if normalizeNames:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
132 # normalize key names
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
133 key = normalizeFieldName(e.tag)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
134 else:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
135 key = e.tag
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
136
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
137 if recursive > 0:
17
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
138 # more recursive - call _getData on element
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
139 val = self._getData(e, recursive=recursive-1, normalizeNames=normalizeNames, all=all, allText=allText)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
140 else:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
141 val = getText(e, recursive=allText)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
142
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
143 if all:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
144 # add multiple tags as list
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
145 putAppend(data, key, val)
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
146 else:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
147 data[key] = val
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
148
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
149 #logging.debug("_getDataFromDom: returns %s"%repr(data))
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
150 return data
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
151
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
152
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
153 def getData(self, path=None, dom=None, normalizeNames=True, all=False, recursive=0, allText=0):
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
154 """Returns dict with attributes and child elements from corresponding tag.
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
155
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
156 @param path: file or url path to metadata file
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
157 @param dom: dom of metadata
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
158 @param normalizeNames: normalize tag names
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
159 @param all: put contents of tags with the same name in list value
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
160 @param recurse: number of recursions. 0=just children
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
161 @param allText: get text content of all subelements
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
162 @returns: dict with attributes (key=@attr) and child elements (key=tag)
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
163 """
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
164 #logging.debug("getData(path=%s, dom=%s)"%(path,dom))
13
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
165 if path is None and dom is None:
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
166 return None
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
167
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
168 elem = self.getSubDom(path=path, dom=dom, all=all)
17
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
169 if elem is None:
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
170 return None
ba617e755c56 mostly finished attributions and copyright
casties
parents: 16
diff changeset
171
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
172 if all:
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
173 # subdom is list - return list
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
174 data = []
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
175 for e in elem:
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
176 data.append(self._getData(e, recursive=recursive, normalizeNames=normalizeNames, all=all, allText=allText))
14
281d223aa361 attribution works now
casties
parents: 13
diff changeset
177
281d223aa361 attribution works now
casties
parents: 13
diff changeset
178 else:
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
179 # subdom is element
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
180 data = self._getData(elem, recursive=recursive, normalizeNames=normalizeNames, all=all, allText=allText)
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
181
16
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
182 if self.mappingSelectAttribute:
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
183 # put type in @type
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
184 attr = data.get('@attr', None)
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
185 if attr:
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
186 type = attr.get(self.mappingSelectAttribute, None)
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
187 if type is not None:
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
188 data['@type'] = normalizeFieldName(type)
5d41c350dd2b new getdata works now
casties
parents: 15
diff changeset
189
15
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
190 return data
41b90f09a1f2 new getdata
casties
parents: 14
diff changeset
191
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
192
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
193 def getMapping(self, type):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
194 """returns MetaDataMapping for type"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
195 # try type as id
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
196 mapping = getattr(self, type, None)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
197 if mapping is None:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
198 # try manually
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
199 mapFolder = self
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
200 for obj in mapFolder.objectValues():
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
201 if obj.meta_type == "MetadataMapping":
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
202 # real type is in title
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
203 mapType = obj.title
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
204 if mapType == type:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
205 # try type as is
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
206 return obj
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
207
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
208 if normalizeFieldName(mapType, underscore=True) == normalizeFieldName(type, underscore=True):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
209 # try normalized type without underscore
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
210 return obj
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
211
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
212 return mapping
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
213
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
214 def getMapFields(self, data):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
215 """returns dict with metadata description for data"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
216 fields = {}
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
217 type = data.get('@type', None)
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
218 if not type:
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
219 logging.error("getMapFields: no @type!")
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
220 return fields
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
221
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
222 # get mapping from main/meta/bib
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
223 mapping = self.getMapping(type)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
224 if mapping is None:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
225 logging.error("getMapFields: no mapping for type: %s"%type)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
226 return fields
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
227
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
228 # get field descriptions (copy so we can change it)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
229 fields = mapping.getFields().copy()
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
230 # add field list
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
231 fields['@fieldList'] = mapping.getFieldList()
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
232
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
233 return fields
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
234
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
235 def getMappedData(self, data, allFields=False):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
236 """returns dict with metadata descriptions and data for data"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
237 fields = self.getMapFields(data)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
238 fieldList = fields['@fieldList']
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
239 mappedData = {}
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
240 mappedList = []
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
241 for bk in fieldList:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
242 # ignore descriptions without data
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
243 if not data.get(bk, None):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
244 continue
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
245
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
246 # field description (copy so we can change it)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
247 bf = fields[bk].copy()
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
248 # add value
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
249 bf['value'] = data[bk]
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
250 mappedData[bk] = bf
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
251 mappedList.append(bk)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
252
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
253 if allFields and len(mappedData) < len(data):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
254 # add fields that were not in fields
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
255 for bk in data.keys():
20
9a1e75e708e1 small bugs
dwinter
parents: 17
diff changeset
256 if bk in mappedData or not data[bk] or bk[0]=='@':
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
257 continue
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
258
20
9a1e75e708e1 small bugs
dwinter
parents: 17
diff changeset
259
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
260 mappedData[bk] = {'tag':bk, 'label':bk, 'value':data[bk]}
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
261 mappedList.append(bk)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
262
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
263 mappedData['@fieldList'] = mappedList
20
9a1e75e708e1 small bugs
dwinter
parents: 17
diff changeset
264 mappedData['@type'] = data.get('@type',None)
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
265 return mappedData
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
266
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
267 def getDCMappedData(self, data, allFields=False):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
268 """returns dict with DC keys and data form data"""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
269 fields = self.getMapFields(data)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
270 dcData = {}
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
271 for bk in fields.keys():
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
272 # ignore descriptions without data
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
273 if not data.get(bk, None):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
274 continue
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
275
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
276 # field description
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
277 dc = fields[bk].get('dcmap', None)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
278 if dc:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
279 # add value
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
280 if dcData.get('dc',None):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
281 # key exists - append
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
282 dcData[dc] += '/' + data[bk]
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
283 else:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
284 dcData[dc] = data[bk]
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
285
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
286 return dcData
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
287
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
288 def getFormatted(self, template, path=None, dom=None, data=None, allFields=False):
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
289 """returns string with document data formatted according to template.
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
290 gets data from server or dom or pre-parsed data."""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
291 logging.debug("getFormatted(template=%s)"%(template))
24
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
292 logging.debug(self.absolute_url())
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
293 logging.debug(self.__dict__)
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
294
13
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
295 # get contents of tag
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
296 if data is None:
9
eeaad777d3d7 more work for non-bib metadata
casties
parents: 8
diff changeset
297 data = self.getData(path=path, dom=dom)
13
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
298 if data is None:
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
299 # no data
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
300 logging.error("getFormatted: no data for template: %s"%(template))
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
301 return ""
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
302
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
303 type = data.get('@type', '')
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
304
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
305 # get template
24
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
306
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
307 tp=getattr(self,"%s_%s"%(template, normalizeFieldName(type)), None)
24
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
308
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
309 if tp is None:
24
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
310 logging.warning("getFormatted: no template for: %s_%s!"%(template, normalizeFieldName(type)))
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
311 # try generic
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
312 tp=getattr(self,"%s_generic"%(template), None)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
313 if tp is None:
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
314 logging.error("getFormatted: no generic template either: %s"%(template))
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
315 return ""
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
316
14
281d223aa361 attribution works now
casties
parents: 13
diff changeset
317 if type:
281d223aa361 attribution works now
casties
parents: 13
diff changeset
318 # put field descriptions in mdHash
281d223aa361 attribution works now
casties
parents: 13
diff changeset
319 fields = self.getMappedData(data, allFields=allFields)
281d223aa361 attribution works now
casties
parents: 13
diff changeset
320 else:
281d223aa361 attribution works now
casties
parents: 13
diff changeset
321 fields = {}
24
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
322
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
323 logging.debug("XXXX")
d036de7fd78d getDRI added
dwinter
parents: 20
diff changeset
324 logging.debug(tp)
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
325 return tp(mdmap=fields, md=data)
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
326
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
327
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
328 def correctPath(self,path,remove=None,prefix=None,cut=0):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
329 """convinience method um einen pfad zu veraendern"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
330 if remove is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
331 path=path.replace(remove,'')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
332 if prefix is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
333 path=os.path.join(prefix,path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
334
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
335 if cut>0:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
336 splitted=path.split("/")
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
337 path="/".join(splitted[0:len(splitted)-cut])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
338 return path
6
00147a1ab4ac division between MetaDataFolder and Metadata looks good now (to me :-)
casties
parents: 5
diff changeset
339
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
340
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
341 def importMetaDataExportXML(self,importFile=None,RESPONSE=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
342 """imports metadata from the metadataexportxml file"""
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 if importFile is None:
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
345 pt=PageTemplateFile('zpt/importMetaDataExportXML', globals()).__of__(self)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
346 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
347
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
348 dom=ET.parse(importFile)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
349 node = dom.getroot()
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
350 if node.tag != 'metadataExport':
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
351 node = dom.find("metadataExport")
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
352
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
353 self.createMappingFromDom(node)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
354
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
355 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
356 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
357
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
358
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
359 def createMappingFromDom(self,metadatanode,metadata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
360 """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
361
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
362 if metadata is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
363 metadata=self
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
364
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
365 nodes=metadatanode
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
366
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
367 for node in nodes:
2
ac8e119b25ec trying to make import from xml work
casties
parents: 1
diff changeset
368 logging.debug("node: %s"%repr(node))
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
369 if node.tag=="set":
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
370 set=node
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
371 id=set.get('name')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
372 list=[]
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
373 argList={}
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
374 for entry in set:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
375 genericName=entry.get('genericName')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
376 if set.get('name')=='generic':
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
377 # generic mapping doesn't have labels
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
378 tag = genericName
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
379 label = genericName
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
380 else:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
381 tag=entry.get('tag')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
382 label=entry.get('label')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
383
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
384 if not tag:
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
385 # ignore empty tags
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
386 continue
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
387
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
388 description=getText(entry)
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
389 argList[tag]={'tag':tag,'label':label,'explanation':description,'status':'optional'}
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
390
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
391 logging.debug("createMappingFromDom: new mapping=%s"%repr(argList))
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
392 metadata._setObject(id,MetaDataMapping(id,id,argList))
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
393
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
394 elif node.tag=="metadata":
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
395 mn=node
3
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
396 name=mn.get('name')
3dadf0d89261 more renovation
casties
parents: 2
diff changeset
397 logging.debug("createMappingFromDom: new metadata=%s"%repr(name))
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
398 metadata._setObject(name,MetaData(name,name))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
399 mdObj=getattr(metadata,name)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
400 mdObj.createMappingFromDom(mn)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
401
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
402
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
403 security.declarePublic('changeMetaDataForm')
9
eeaad777d3d7 more work for non-bib metadata
casties
parents: 8
diff changeset
404 changeMetaDataForm = PageTemplateFile('zpt/changeMetadata', globals())
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
405
5
c1dbf78cc036 more MetaDataFolder
casties
parents: 4
diff changeset
406 security.declarePublic('changeMetaData')
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
407 def changeMetaData(self,title=None,shortDescription=None,description=None,mappingSelectAttribute=None,fields=None,metaDataServerUrl=None,RESPONSE=None):
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
408 """Change Metadata"""
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
409 self.title = title
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
410 self.shortDescription=shortDescription
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
411 self.description=description
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
412 self.mappingSelectAttribute=mappingSelectAttribute
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
413 if fields:
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
414 self.fieldList=fields.split(",")[0:]
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
415
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
416 self.metaDataServerUrl=metaDataServerUrl
11
a29665fa9c62 more work for non-bib metadata
casties
parents: 9
diff changeset
417
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
418 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
419 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
420
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
421
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
422 def manage_addMetaDataForm(self):
9
eeaad777d3d7 more work for non-bib metadata
casties
parents: 8
diff changeset
423 """interface for adding the Metadata"""
eeaad777d3d7 more work for non-bib metadata
casties
parents: 8
diff changeset
424 pt=PageTemplateFile('zpt/addMetadataForm', globals()).__of__(self)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
425 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
426
13
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
427 def manage_addMetaData(self,id,title=None,shortDescription=None,description=None,fields=None,RESPONSE=None):
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
428 """a metadata objekt"""
13
5f48f956ffa3 more resistant to empty data
casties
parents: 12
diff changeset
429 newObj = MetaData(id,title=title,shortDescription=shortDescription,description=description,fields=fields)
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
430 self.Destination()._setObject(id,newObj)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
431 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
432 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
433