annotate MetaData.py @ 30:1cb439acd1e1

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