Mercurial > hg > MPIWGWeb
annotate MPIWGProjects.py @ 110:b554becd8226
Incomplete - # 74: More Link auf den pers?nlichne Homepages
https://it-dev.mpiwg-berlin.mpg.de/tracs/webpage/ticket/74
author | dwinter |
---|---|
date | Tue, 28 May 2013 09:47:43 +0200 |
parents | 782477730916 |
children | 1acfcaaa5ca3 |
rev | line source |
---|---|
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1 """This contains the class MPIWG Projects |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
2 for organizing and maintaining the different project pages |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
3 |
39 | 4 $author dwinter 26.06.2008 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
5 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
6 """ |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
7 from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
8 from OFS.Image import Image |
22 | 9 from App.ImageFile import ImageFile |
10 from OFS.SimpleItem import SimpleItem | |
11 from OFS.Folder import Folder | |
12 from AccessControl import ClassSecurityInfo | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
13 from Globals import package_home |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
14 import urllib |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
15 import re |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
16 import os |
22 | 17 import sys |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
18 import logging |
22 | 19 import time |
80 | 20 import unicodedata |
22 | 21 |
49 | 22 import xml.etree.ElementTree as ET |
23 | |
65 | 24 from SrvTxtUtils import getInt, unicodify, utf8ify, serialize, refreshingImageFileIndexHtml, shortenString |
33 | 25 from Products.ZDBInterface.ZDBInterfaceFolder import ZDBInterfaceFolder |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
26 |
80 | 27 import xmlhelper # Methoden zur Verwaltung der projekt xml |
27 | 28 from HashTree import HashTree |
80 | 29 import MPIWGHelper |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
30 |
39 | 31 # TODO: better names for the fields |
35 | 32 fieldLabels = {'WEB_title':'WEB_Title', |
33 | 33 'xdata_01':'Responsible Scientists', |
34 'xdata_02':'Department', | |
35 'xdata_03':'Historical Persons', | |
36 'xdata_04':'Time period', | |
37 'xdata_05':'Sorting number', | |
38 'xdata_06':'Keywords', | |
39 'xdata_07':'Short title', | |
40 'xdata_08':'Other involved scholars' , | |
41 'xdata_09':'Disciplines', | |
42 'xdata_10':'Themes', | |
43 'xdata_11':'Object Digitallibrary', | |
44 'xdata_12':'Cooperation partners', | |
45 'xdata_13':'Funding institutions', | |
46 'WEB_project_header':'WEB_project_header', | |
47 'WEB_project_description':'WEB_project_description', | |
48 'WEB_related_pub':'WEB_related_pub'} | |
49 | |
39 | 50 definedFields = fieldLabels.keys() # TODO: should this be sorted? |
51 | |
81 | 52 editableFields = ('xdata_07', 'xdata_01', 'xdata_05', 'xdata_08', 'xdata_12', 'xdata_13') |
33 | 53 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
54 # die folgenden Klassen sind jetzt in einzelne Files ausgelagert aus Kompatibilitaetsgruenden, bleiben die Klassen hier noch drin. |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
55 # Sonst funktionieren die alten Webseiten nicht mehr. |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
56 |
80 | 57 import MPIWGRoot |
58 import MPIWGLink | |
59 import MPIWGTemplate | |
60 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
61 class MPIWGRoot(MPIWGRoot.MPIWGRoot): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
62 """depricated""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
63 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
64 class MPIWGLink(MPIWGLink.MPIWGLink): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
65 """depricated""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
66 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
67 class MPIWGTemplate(MPIWGTemplate.MPIWGTemplate): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
68 """depricated""" |
80 | 69 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
70 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
71 class MPIWGProject_publication(Folder): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
72 """publications object fuer project""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
73 |
35 | 74 meta_type = "MPIWGProject_publication" |
61 | 75 |
76 text = None | |
77 link = None | |
78 bookId = None | |
79 | |
65 | 80 # templates |
81 | 81 edit = PageTemplateFile('zpt/project/related_publication/edit_basic', globals()) |
61 | 82 |
83 | |
81 | 84 redirect = MPIWGHelper.redirect |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
85 |
61 | 86 |
87 def hasLinkToBookPage(self): | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
88 """teste ob eingebener link zu einer MPIWG Book page geht""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
89 logging.debug("MPIWGProject_publication - begin hasLinkToBookPage") |
61 | 90 if not self.link: |
35 | 91 return False # es gibt keinen link |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
92 |
61 | 93 paths = self.link.split('/') |
94 if len(paths) > 2: | |
95 # book page should be in folder books | |
96 bookid = None | |
97 try: | |
98 idx = paths.index('books') | |
99 bookid = paths[idx + 1] | |
100 book = self.en.books[bookid] | |
101 self.bookId = bookid | |
102 return True | |
103 | |
104 except: | |
105 logging.debug("hasLinkToBookPage: not a book page link=%s"%self.link) | |
106 | |
107 self.bookId = None | |
108 return False | |
109 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
110 |
61 | 111 def getBookId(self): |
112 """Return the book page id.""" | |
113 return self.bookId | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
114 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
115 |
80 | 116 getUrl = MPIWGHelper.getUrl |
117 | |
118 | |
61 | 119 def editPublication(self, text=None, description=None, link=None, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
120 """edit a publication""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
121 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
122 if (not text) and (not description): |
81 | 123 pt = self.edit |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
124 return pt() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
125 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
126 if text: |
61 | 127 self.text = text |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
128 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
129 if description: |
35 | 130 self.description = description |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
131 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
132 if link: |
61 | 133 self.link = link |
134 self.hasLinkToBookPage() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
135 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
136 if RESPONSE: |
35 | 137 self.redirect(RESPONSE, "../managePublications") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
138 |
39 | 139 |
81 | 140 class MPIWGProject_relatedProject(SimpleItem): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
141 """publications object fuer project""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
142 |
35 | 143 meta_type = "MPIWGProject_relatedProject" |
60 | 144 |
61 | 145 objid = None |
146 projectLabel = None | |
147 | |
80 | 148 # templates |
81 | 149 edit = PageTemplateFile('zpt/project/related_project/edit_basic', globals()) |
61 | 150 |
81 | 151 |
152 redirect = MPIWGHelper.redirect | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
153 |
60 | 154 |
61 | 155 def getProjectId(self): |
156 """Return the related project id.""" | |
157 return self.objid | |
158 | |
159 | |
160 def getProject(self): | |
161 """Return the related project object.""" | |
162 return getattr(self.projects, self.objid, None) | |
163 | |
164 | |
60 | 165 def getProjectTitle(self): |
166 """Return the title of the related project.""" | |
167 return getattr(self, 'projectWEB_title', None) | |
61 | 168 |
60 | 169 |
61 | 170 def getProjectLabel(self): |
171 """Return the label of the related project.""" | |
172 label = getattr(self, 'projectLabel', None) | |
173 if not label: | |
174 proj = self.getProject() | |
175 if proj is not None: | |
176 label = proj.getLabel() | |
177 | |
178 self.projectLabel = label | |
179 | |
180 return label | |
181 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
182 |
80 | 183 getUrl = MPIWGHelper.getUrl |
184 | |
185 | |
35 | 186 def editRelatedProject(self, link=None, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
187 """edit a publication""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
188 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
189 if (not link): |
63 | 190 pt = self.editDescription |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
191 return pt() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
192 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
193 # hole die id des projektes |
35 | 194 splitted = link.split("/") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
195 |
35 | 196 # teste ob es das project gibt |
197 if len(splitted) < 1: | |
198 self.redirect(RESPONSE, 'errorRelatedProjects?link=' + link) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
199 |
35 | 200 objid = splitted[-1] |
201 object = getattr(self.projects, objid, None) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
202 |
61 | 203 if object is None: |
35 | 204 self.redirect(RESPONSE, 'errorRelatedProjects?link=' + link) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
205 |
35 | 206 self.orginallink = link[0:] |
207 self.objid = objid[0:] | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
208 |
52 | 209 self.projectWEB_title = object.getProjectTitle() |
61 | 210 self.projectLabel = object.getLabel() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
211 |
35 | 212 self.enabled = True; |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
213 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
214 if RESPONSE: |
35 | 215 self.redirect(RESPONSE, "../manageRelatedProjects") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
216 |
39 | 217 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
218 class MPIWGProject_image(Image): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
219 """Images for Projects""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
220 |
35 | 221 meta_type = "MPIWGProject_image" |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
222 |
65 | 223 # templates |
96
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
224 oldShowImage = PageTemplateFile('zpt/project/image/projectImageView', globals()) |
65 | 225 editForm = PageTemplateFile('zpt/project/image/edit_basic', globals()) |
226 | |
80 | 227 getUrl = MPIWGHelper.getUrl |
228 | |
96
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
229 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
230 def getCaption(self): |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
231 """Return the image caption.""" |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
232 return getattr(self, 'caption', None) |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
233 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
234 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
235 def getLink(self): |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
236 """Return the image link.""" |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
237 return getattr(self, 'link', None) |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
238 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
239 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
240 def editImage(self, file=None, caption=None, link=None, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
241 """edit the Image""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
242 if (not file) and (not caption): |
65 | 243 pt = self.editForm |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
244 return pt() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
245 |
96
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
246 if file and (not file.filename.strip() == ""): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
247 self.manage_upload(file) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
248 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
249 if caption: |
96
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
250 if isinstance(caption, list): |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
251 caption = caption[0] |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
252 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
253 self.caption = caption |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
254 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
255 if link: |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
256 self.link = link |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
257 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
258 if RESPONSE: |
35 | 259 self.redirect(RESPONSE, "../manageImages") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
260 |
24 | 261 |
81 | 262 class MPIWGProject_InfoBlock(SimpleItem): |
263 """publications object fuer project""" | |
264 | |
265 meta_type = "MPIWGProject_InfoBlock" | |
266 | |
267 # templates | |
268 edit = PageTemplateFile('zpt/project/infoblock/edit_items', globals()) | |
269 | |
270 | |
271 redirect = MPIWGHelper.redirect | |
272 | |
273 | |
274 def __init__(self, id, title=None): | |
275 """Create info block.""" | |
276 self.id = id | |
277 self.title = title | |
278 self.place = 0 | |
279 self.items = [] | |
280 | |
281 | |
282 def getTitle(self): | |
283 """Return the title.""" | |
284 return self.title | |
285 | |
286 | |
287 def getItems(self): | |
288 """Return the list of items.""" | |
289 return self.items | |
290 | |
291 | |
292 def setItems(self, items): | |
293 """Set the list of items.""" | |
294 self.items = items | |
295 self._p_changed = True | |
296 | |
297 | |
298 def addItem(self, item=None, text=None, link=None, RESPONSE=None): | |
299 """Add an item to the InfoBox""" | |
300 if item is None: | |
301 item = {'text': text, 'link': link} | |
302 | |
303 self.items.append(item) | |
304 self._p_changed = True | |
305 if RESPONSE is not None: | |
306 self.redirect(RESPONSE, 'edit') | |
307 | |
308 | |
309 def deleteItem(self, idx, RESPONSE=None): | |
310 """Delete an item from the info block.""" | |
311 try: | |
312 del self.items[int(idx)] | |
313 self._p_changed = True | |
314 except: | |
315 logging.error("InfoBlock deleteItem: error deleting item %s!"%idx) | |
316 | |
317 if RESPONSE is not None: | |
318 self.redirect(RESPONSE, 'edit') | |
319 | |
320 | |
321 def moveItem(self, idx, op, RESPONSE=None): | |
322 """Move items up or down the list.""" | |
323 try: | |
324 idx = int(idx) | |
325 if op == 'up': | |
326 if idx > 0: | |
327 self.items[idx-1], self.items[idx] = self.items[idx], self.items[idx-1] | |
328 elif op == 'down': | |
329 if idx < len(self.items)-1: | |
330 self.items[idx], self.items[idx+1] = self.items[idx+1], self.items[idx] | |
331 | |
332 self._p_changed = True | |
333 except: | |
334 logging.error("InfoBlock moveItem: error moving item at %s!"%idx) | |
335 | |
336 if RESPONSE is not None: | |
337 self.redirect(RESPONSE, 'edit') | |
338 | |
339 | |
340 def editItems(self, REQUEST, RESPONSE=None): | |
341 """Change items from request form.""" | |
342 form = REQUEST.form | |
343 for k in form: | |
344 t, n = k.split('_') | |
345 if t in ['text', 'link']: | |
346 try: | |
347 logging.debug("editItems: change[%s].%s = %s"%(n,t,repr(form[k]))) | |
348 self.items[int(n)][t] = form[k] | |
349 except: | |
350 logging.error("InfoBlock editItems: error changing item %s!"%k) | |
351 | |
352 self._p_changed = True | |
353 if RESPONSE is not None: | |
354 self.redirect(RESPONSE, 'edit') | |
355 | |
356 | |
357 | |
65 | 358 class MPIWGProject(Folder): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
359 """Class for Projects""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
360 |
33 | 361 security = ClassSecurityInfo() |
362 meta_type = 'MPIWGProject' | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
363 |
35 | 364 manage_options = Folder.manage_options + ( |
365 {'label':'Load New File', 'action':'loadNewFileForm'}, | |
63 | 366 {'label':'Edit', 'action':'editDescription'}, |
22 | 367 ) |
35 | 368 # {'label':'Edit ProjectInfo','action':'editMPIWGProjectForm'}, |
369 # {'label':'Edit BasisInfo','action':'editMPIWGBasisForm'}, | |
370 # {'label':'Edit Publications','action':'editMPIWGRelatedPublicationsForm'}, | |
371 # {'label':'Edit Themes & Disciplines','action':'editMPIWGDisciplinesThemesForm'}, | |
372 # {'label':'Versionmanager','action':'versionManageForm'}, | |
22 | 373 |
33 | 374 # |
375 # templates | |
376 # | |
90 | 377 project_html = PageTemplateFile('zpt/project/project_index_html', globals()) |
50 | 378 # edit templates |
22 | 379 edit_css = ImageFile('css/edit.css', globals()) |
380 # make css refreshable for development | |
381 edit_css.index_html = refreshingImageFileIndexHtml | |
61 | 382 # user-accessible editing templates |
90 | 383 edit_template = PageTemplateFile('zpt/project/edit_template', globals()) |
63 | 384 security.declareProtected('View management screens', 'editBasic') |
385 editBasic = PageTemplateFile('zpt/project/edit_basic', globals()) | |
90 | 386 security.declareProtected('View management screens', 'editDescription') |
63 | 387 editDescription = PageTemplateFile('zpt/project/edit_description', globals()) |
90 | 388 security.declareProtected('View management screens', 'editRelatedProjectsForm') |
60 | 389 editRelatedProjectsForm = PageTemplateFile('zpt/project/edit_related_projects', globals()) |
61 | 390 editRelatedProjectsError = PageTemplateFile('zpt/project/edit_related_projects_error', globals()) |
95 | 391 security.declareProtected('View management screens', 'editImagesForm') |
392 editImagesForm = PageTemplateFile('zpt/project/edit_images', globals()) | |
90 | 393 security.declareProtected('View management screens', 'editPublicationsForm') |
60 | 394 editPublicationsForm = PageTemplateFile('zpt/project/edit_publications', globals()) |
90 | 395 security.declareProtected('View management screens', 'editInfoBlocksForm') |
81 | 396 editInfoBlocksForm = PageTemplateFile('zpt/project/edit_infoblocks', globals()) |
90 | 397 security.declareProtected('View management screens', 'editAdditionalPublicationsForm') |
61 | 398 editAdditionalPublicationsForm = PageTemplateFile('zpt/project/pubman/change_publications', globals()) |
90 | 399 security.declareProtected('View management screens', 'editAddAdditionalPublications') |
62 | 400 editAddAdditionalPublications = PageTemplateFile('zpt/project/pubman/add_publications', globals()) |
63 | 401 security.declareProtected('View management screens', 'edit') |
402 edit = editDescription | |
50 | 403 # management templates |
90 | 404 security.declareProtected('View management screens', 'loadNewFileForm') |
50 | 405 loadNewFileForm = PageTemplateFile('zpt/project/manage_newfile', globals()) |
406 description_only_html = PageTemplateFile('zpt/project/description_only_html', globals()) | |
61 | 407 # additional pages |
74
e424b68244c8
better template for additional project publications.
casties
parents:
65
diff
changeset
|
408 additional_publications_html = PageTemplateFile('zpt/project/pubman/show_publications', globals()) |
22 | 409 |
410 | |
411 def __init__(self, id, argv=None): | |
412 """initiere classe""" | |
35 | 413 self.creationTime = time.strftime("%Y%m%d%H%M%S", time.localtime())[0:] |
414 self.id = id | |
415 self.title = id | |
416 self.isActiveFlag = True # Flag is true is the project is still active, False if accomplished | |
417 self.responsibleScientistsList = [] # enthaelt die Lister der verantwortlichen Wissenschaftler in der Form (NAME, KEY), key ist "" flass Wissenschaftler nicht an unserem Haus | |
97 | 418 self.projectThumb = None |
22 | 419 |
420 if argv: | |
421 for arg in definedFields: | |
422 try: | |
35 | 423 setattr(self, arg, argv[arg]) |
22 | 424 except: |
35 | 425 setattr(self, arg, "") |
22 | 426 else: |
427 for arg in definedFields: | |
35 | 428 setattr(self, arg, '') |
22 | 429 |
430 | |
35 | 431 def index_html(self): |
432 """default html representation""" | |
433 # TODO: do we need to do date-stuff? | |
434 # get template | |
74
e424b68244c8
better template for additional project publications.
casties
parents:
65
diff
changeset
|
435 pt = self.project_html |
35 | 436 # render template |
437 return pt() | |
438 | |
81 | 439 |
440 redirect = MPIWGHelper.redirect | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
441 |
27 | 442 |
60 | 443 def getDefinedFields(self): |
444 """show all defined fields.""" | |
445 return definedFields | |
446 | |
447 | |
448 def getFieldLabels(self): | |
449 """Return the field labels dict.""" | |
450 return fieldLabels | |
451 | |
452 | |
453 def getEditableFields(self): | |
454 """giveListofDatafields""" | |
455 return editableFields | |
456 | |
457 | |
27 | 458 def getNumber(self): |
459 """returns sorting number""" | |
33 | 460 n = getattr(self, 'xdata_05', None) |
461 if isinstance(n, list): | |
462 # compat with old lists | |
463 return n[0] | |
464 else: | |
465 return n | |
27 | 466 |
35 | 467 |
80 | 468 def getProjectTitle(self, forSorting=False): |
35 | 469 """returns the project title""" |
470 t = getattr(self, 'WEB_title', None) | |
471 if isinstance(t, list): | |
472 # compat with old lists | |
80 | 473 t = t[0] |
474 | |
475 if forSorting and t is not None: | |
476 # remove stopwords and signs for sorting | |
477 if t.lower().startswith('a '): | |
478 t = t[2:] | |
479 elif isinstance(t, unicode) and unicodedata.category(t[0])[0] != 'L': | |
480 t = t[1:] | |
481 | |
482 return t | |
35 | 483 |
39 | 484 |
485 def getLabel(self): | |
486 """returns label (or title) of this project""" | |
487 l = getattr(self, 'xdata_07', None) | |
488 if isinstance(l, list): | |
489 # compat with old lists | |
490 l = l[0] | |
491 | |
492 if l: | |
493 return l | |
494 else: | |
495 return self.getProjectTitle() | |
496 | |
497 | |
35 | 498 def getResponsibleScientists(self): |
499 """returns the responsible scientists as string""" | |
500 t = getattr(self, 'xdata_01', None) | |
501 if isinstance(t, list): | |
502 # compat with old lists | |
503 return t[0] | |
504 else: | |
505 return t | |
506 | |
507 | |
508 def getResponsibleScientistsList(self): | |
509 """returns a list with the responsible scientists as dicts with name, key, and shortname""" | |
97 | 510 return getattr(self, 'responsibleScientistsList', []) |
35 | 511 |
512 | |
513 def setResponsibleScientistsList(self, nameDict): | |
514 """sets the responsibleScientistsList from nameDict. | |
515 List will be ordered like the responsible scientists field.""" | |
516 names = self.getResponsibleScientists() | |
517 if names.find(";") > -1: # rate Trenner ist ; | |
518 nameList = names.split(";") | |
519 else: | |
520 nameList = names.split(",") | |
521 | |
522 scientistsList = [] | |
523 for name in nameList: | |
524 name = unicodify(name.strip()) | |
525 logging.debug("setResponsibleScientistsList: name=%s"%repr(name)) | |
526 if name in nameDict: | |
527 # found in data | |
528 data = nameDict[name] | |
529 scientistsList.append({'name': name, 'key': data['key'], 'username': data['username']}) | |
530 else: | |
531 scientistsList.append({'name': name}) | |
532 | |
533 logging.debug("setResponsibleScientistsList: nameDict=%s new list=%s"%(repr(nameDict),repr(scientistsList))) | |
534 self.responsibleScientistsList = scientistsList | |
535 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
536 |
39 | 537 def getInvolvedScholars(self): |
538 """returns the other involved scholars""" | |
539 t = getattr(self, 'xdata_08', None) | |
540 if isinstance(t, list): | |
541 # compat with old lists | |
542 return t[0] | |
543 else: | |
544 return t | |
545 | |
546 | |
547 def getCooperationPartners(self): | |
548 """returns the cooperation partners""" | |
549 t = getattr(self, 'xdata_12', None) | |
550 if isinstance(t, list): | |
551 # compat with old lists | |
552 return t[0] | |
553 else: | |
554 return t | |
555 | |
61 | 556 |
96
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
557 def getMPIWGProject(self): |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
558 """Return this project for acquisition.""" |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
559 return self |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
560 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
561 |
61 | 562 def getMPIWGProjectUrl(self): |
563 """Return this project for acquisition.""" | |
564 return self.absolute_url() | |
565 | |
39 | 566 |
80 | 567 getUrl = MPIWGHelper.getUrl |
27 | 568 |
569 | |
65 | 570 def getThumbUrl(self, default=None): |
24 | 571 """returns the URL of the project thumbnail image""" |
97 | 572 thumb = getattr(self, 'projectThumb', None) |
36 | 573 if thumb is None: |
52 | 574 # get thumb from list (thumb is last image) |
36 | 575 imgs = self.getImageList() |
576 if len(imgs) > 0: | |
52 | 577 thumb = imgs[-1] |
36 | 578 self.projectThumb = thumb |
579 | |
580 if thumb is None: | |
52 | 581 return default |
36 | 582 |
583 return thumb.absolute_url() | |
584 | |
24 | 585 |
39 | 586 def getDepartment(self): |
587 """returns the department of this project""" | |
588 num = self.getNumber() | |
589 pp = num.find('.') | |
590 if pp > 0: | |
591 num = num[:pp] | |
592 | |
80 | 593 return self.en.getMPIWGRoot().getDepartment(projectNumber=num) |
39 | 594 |
595 | |
596 def getDepartmentId(self): | |
597 """returns the id of the department of this project""" | |
598 dep = self.getDepartment() | |
599 if dep is not None: | |
600 return dep.getId() | |
601 | |
602 return None | |
603 | |
604 | |
102 | 605 def getDescription(self, filter=None, length=0): |
39 | 606 """returns the project description""" |
49 | 607 text = getattr(self, 'WEB_project_description', None) |
608 if isinstance(text, list): | |
39 | 609 # compat with old lists |
49 | 610 text = text[0] |
611 | |
102 | 612 if filter == 'plaintext': |
613 # filter out any tags, keep only text | |
614 try: | |
615 xmltext = utf8ify("<div>%s</div>"%text) | |
616 dom = ET.fromstring(xmltext) | |
617 plaintext = "" | |
618 for elem in dom.iter(): | |
619 if elem.tag == 'style': | |
620 # ignore tag | |
621 continue | |
622 | |
623 if elem.text: | |
624 plaintext += elem.text | |
625 if elem.tail: | |
626 plaintext += elem.tail | |
627 | |
628 if length > 0 and len(plaintext) > length: | |
629 break | |
630 | |
631 text = plaintext | |
632 except Exception, e: | |
633 logging.warn("getDesciption: error parsing description! Returning everything. %s"%e) | |
634 | |
635 if length > 0 and len(text) > length: | |
636 # try to not break words | |
637 if text[length] not in [' ', '.', '?', '!']: | |
638 # search the last blank | |
639 length = text.rfind(' ', 0, length) | |
640 | |
641 return text[:length] + '...' | |
642 | |
49 | 643 return text |
644 | |
39 | 645 |
646 def getSuperProjects(self): | |
647 """returns a list of ancestor projects to the root""" | |
648 tree = self.getProjectTree() | |
649 return tree.getAncestorsOf(self.getNumber()) | |
650 | |
651 | |
652 def getSubProjects(self, active=1): | |
653 """returns a list of child projects""" | |
654 tree = self.getProjectTree() | |
655 return [p for p in tree.getChildrenOf(self.getNumber()) if p.checkActive(active)] | |
656 | |
657 | |
658 def getRelatedDigitalSources(self): | |
659 """returns the related digital sources""" | |
660 t = getattr(self, 'xdata_11', None) | |
661 if isinstance(t, list): | |
662 # compat with old lists | |
663 return t[0] | |
664 else: | |
665 return t | |
43 | 666 |
39 | 667 |
668 def getFundingInstitutions(self): | |
669 """returns the funding institutions""" | |
670 t = getattr(self, 'xdata_13', None) | |
671 if isinstance(t, list): | |
672 # compat with old lists | |
673 return t[0] | |
674 else: | |
675 return t | |
676 | |
24 | 677 |
63 | 678 def _moveObjectPlace(self, objectList, objectId, direction): |
60 | 679 """Move object with objectId from objectList in direction |
680 by changing its place attribute.""" | |
681 if not objectId or not direction: | |
682 return | |
683 | |
684 for idx in range(len(objectList)): | |
685 object = objectList[idx] | |
61 | 686 if object.getId() == objectId: |
60 | 687 if direction == 'up': |
688 if idx > 0: | |
689 # move up | |
690 objectList[idx -1].place += 1 | |
691 objectList[idx].place -= 1 | |
692 | |
693 elif direction == 'down': | |
694 if idx < len(objectList) - 1: | |
695 # move down | |
696 objectList[idx + 1].place -= 1 | |
697 objectList[idx].place += 1 | |
698 | |
699 return | |
700 | |
63 | 701 |
702 def getImageList(self): | |
703 """returns the sorted list of images for this project""" | |
704 items = self.objectValues(spec='MPIWGProject_image') | |
705 # sort by place | |
706 return sorted(items, key=lambda x:int(getattr(x, 'place', 0))) | |
707 | |
708 | |
709 def addImage(self, fileHd, caption, RESPONSE=None, filename=None): | |
710 """add an MPIWG_Project_image""" | |
711 | |
712 if not filename: | |
713 filename = fileHd.filename | |
714 | |
715 if not fileHd: | |
716 fileHd = file(os.path.join(package_home(globals()), 'blank.gif')) | |
717 | |
718 newImage = MPIWGProject_image(filename, filename, fileHd) | |
719 | |
720 self._setObject(filename, newImage) | |
721 obj = getattr(self, filename) | |
722 obj.caption = caption[:] | |
723 obj.enabled = True; | |
724 obj.place = self._getLastImageNumber() + 1 | |
725 obj.id = filename | |
726 | |
727 # invalidate thumbnail | |
728 self.projectThumb = None | |
729 | |
730 if RESPONSE is not None: | |
731 self.redirect(RESPONSE, 'manageImages') | |
732 | |
733 | |
734 def _getLastImageNumber(self): | |
735 items = self.getImageList() | |
736 if not items: | |
737 return 0 | |
738 else: | |
739 return getattr(items[-1], 'place', 0) | |
740 | |
741 | |
61 | 742 def manageImages(self, name=None, op=None): |
60 | 743 """manage images""" |
63 | 744 self._moveObjectPlace(self.getImageList(), name, op) |
60 | 745 |
51 | 746 # invalidate thumbnail |
747 self.projectThumb = None | |
60 | 748 |
749 pt = self.editImagesForm | |
50 | 750 return pt() |
751 | |
60 | 752 |
63 | 753 def deleteImage(self, id, RESPONSE=None): |
754 """delete Image id""" | |
755 try: | |
756 self.manage_delObjects([id]) | |
757 except: | |
758 logging.error("ERROR MPIWG: %s %s" % sys.exc_info()[0:2]) | |
759 | |
760 # invalidate thumbnail | |
761 self.projectThumb = None | |
762 | |
763 if RESPONSE: | |
764 self.redirect(RESPONSE, 'manageImages') | |
50 | 765 |
63 | 766 |
767 def getPublicationList(self): | |
768 """returns the list of related publications""" | |
769 items = self.objectValues(spec='MPIWGProject_publication') | |
770 # sort by place | |
771 items.sort(key=lambda x:int(getattr(x, 'place', 0))) | |
772 return items | |
773 | |
50 | 774 |
64 | 775 def addPublication(self, text=None, link=None, RESPONSE=None): |
50 | 776 """add an MPIWG_Publication""" |
64 | 777 if text or link: |
778 number = self._getLastPublicationNumber() + 1 | |
50 | 779 name = "publication_" + str(number) |
64 | 780 while hasattr(self, name): |
781 number += 1 | |
782 name = "publication_" + str(number) | |
783 | |
784 newPublication = MPIWGProject_publication(name) | |
50 | 785 |
64 | 786 self._setObject(name, newPublication) |
787 obj = getattr(self, name) | |
788 obj.text = text | |
789 obj.link = link | |
790 obj.enabled = True; | |
791 obj.place = self._getLastPublicationNumber() + 1 | |
792 obj.id = name | |
793 # hasLinkToBookPage updates bookid if available | |
794 if obj.hasLinkToBookPage() and not text: | |
795 # take title from book page | |
796 try: | |
797 book = self.en.books[obj.bookId] | |
798 obj.text = book.getInfo('title') | |
799 except: | |
800 pass | |
50 | 801 |
802 if RESPONSE is not None: | |
803 self.redirect(RESPONSE, 'managePublications') | |
804 | |
60 | 805 |
63 | 806 def _getLastPublicationNumber(self): |
807 items = self.getPublicationList() | |
808 if not items: | |
809 return 0 | |
810 else: | |
811 return getattr(items[-1], 'place', 0) | |
812 | |
813 | |
814 def managePublications(self, name=None, op=None): | |
815 """manage publications""" | |
816 self._moveObjectPlace(self.getPublicationList(), name, op) | |
817 | |
818 pt = self.editPublicationsForm | |
819 return pt() | |
50 | 820 |
63 | 821 |
822 def deletePublication(self, id, RESPONSE=None): | |
823 """delete Publication id""" | |
824 self.manage_delObjects([id]) | |
825 if RESPONSE: | |
826 self.redirect(RESPONSE, 'managePublications') | |
827 | |
828 | |
829 def getRelatedProjectList(self): | |
830 """returns the list of related projects""" | |
831 items = self.objectValues(spec='MPIWGProject_relatedProject') | |
832 # sort by place | |
833 items.sort(key=lambda x:int(getattr(x, 'place', 0))) | |
834 return items | |
835 | |
60 | 836 |
50 | 837 def addRelatedProject(self, link, RESPONSE=None): |
60 | 838 """add a MPIWGProject_relatedProject""" |
63 | 839 number = self._getLastRelatedProjectNumber() + 1 |
61 | 840 name = "related_project_" + str(number) |
50 | 841 while hasattr(self, name): |
842 number += 1 | |
61 | 843 name = "related_project_" + str(number) |
50 | 844 |
845 # hole die id des projektes | |
846 splitted = link.split("/") | |
847 | |
848 # teste ob es das project gibt | |
849 if len(splitted) < 1: | |
850 self.redirect(RESPONSE, 'errorRelatedProjects?link=' + link) | |
851 | |
852 objid = splitted[-1] | |
853 object = getattr(self.projects, objid, None) | |
854 | |
855 if object == None: | |
856 self.redirect(RESPONSE, 'errorRelatedProjects?link=' + link) | |
857 return | |
858 | |
859 newPublication = MPIWGProject_relatedProject(name) | |
860 | |
861 self._setObject(name, newPublication) | |
862 obj = getattr(self, name) | |
863 obj.orginallink = link[0:] | |
864 obj.objid = objid[0:] | |
865 logging.debug("add relobj:objid" + repr(obj.objid)) | |
60 | 866 obj.projectWEB_title = object.getProjectTitle() |
50 | 867 logging.debug("add relobj:webtitle" + repr(obj.projectWEB_title)) |
868 obj.enabled = True; | |
63 | 869 obj.place = self._getLastRelatedProjectNumber() + 1 |
50 | 870 obj.id = name |
871 if RESPONSE is not None: | |
872 self.redirect(RESPONSE, 'manageRelatedProjects') | |
873 | |
874 | |
63 | 875 def _getLastRelatedProjectNumber(self): |
61 | 876 items = self.getRelatedProjectList() |
877 if not items: | |
50 | 878 return 0 |
879 else: | |
61 | 880 return getattr(items[-1], 'place', 0) |
60 | 881 |
50 | 882 |
63 | 883 def manageRelatedProjects(self, name=None, op=None): |
884 """manage related projects""" | |
885 self._moveObjectPlace(self.getRelatedProjectList(), name, op) | |
886 | |
887 pt = self.editRelatedProjectsForm | |
888 return pt() | |
889 | |
890 | |
891 def deleteRelatedProject(self, id, RESPONSE=None): | |
892 """delete Publication id""" | |
893 self.manage_delObjects([id]) | |
894 if RESPONSE: | |
895 self.redirect(RESPONSE, 'manageRelatedProjects') | |
896 | |
60 | 897 |
63 | 898 def errorRelatedProjects(self, link): |
899 """error creating a related project""" | |
900 pt = self.editRelatedProjectsError | |
901 return pt(link=link) | |
902 | |
903 | |
81 | 904 def getInfoBlockList(self): |
905 """returns the list of related projects""" | |
906 items = self.objectValues(spec='MPIWGProject_InfoBlock') | |
907 # sort by place | |
908 items.sort(key=lambda x:int(getattr(x, 'place', 0))) | |
909 return items | |
910 | |
911 | |
912 def addInfoBlock(self, block_title=None, item_text=None, item_link=None, RESPONSE=None): | |
913 """add a MPIWGProject_InfoBlock""" | |
914 if block_title: | |
915 number = self._getLastInfoBlockNumber() + 1 | |
916 name = "infoblock_" + str(number) | |
917 while hasattr(self, name): | |
918 number += 1 | |
919 name = "infoblock_" + str(number) | |
920 | |
921 newBlock = MPIWGProject_InfoBlock(name, block_title) | |
922 # add block to project | |
923 self._setObject(name, newBlock) | |
924 obj = getattr(self, name) | |
925 obj.place = self._getLastInfoBlockNumber() + 1 | |
926 if item_text: | |
927 obj.addItem(text=item_text, link=item_link) | |
928 | |
929 if RESPONSE is not None: | |
930 self.redirect(RESPONSE, 'manageInfoBlocks') | |
931 | |
932 | |
933 def _getLastInfoBlockNumber(self): | |
934 items = self.getInfoBlockList() | |
935 if not items: | |
936 return 0 | |
937 else: | |
938 return getattr(items[-1], 'place', 0) | |
939 | |
940 | |
941 def manageInfoBlocks(self, name=None, op=None): | |
942 """manage related projects""" | |
943 self._moveObjectPlace(self.getInfoBlockList(), name, op) | |
944 | |
945 pt = self.editInfoBlocksForm | |
946 return pt() | |
947 | |
948 | |
949 def deleteInfoBlock(self, id, RESPONSE=None): | |
950 """delete Publication id""" | |
951 self.manage_delObjects([id]) | |
952 if RESPONSE: | |
953 self.redirect(RESPONSE, 'manageInfoBlocks') | |
954 | |
955 | |
63 | 956 def getAdditionalPublicationList(self): |
957 """hole publications aus der datenbank""" | |
958 query="select * from pubmanbiblio_projects where lower(key_main) = lower(%s) order by priority DESC" | |
959 return self.executeZSQL(query,[self.getId()]) | |
960 | |
961 | |
962 def hasAdditionalPublications(self): | |
963 """test if extended publication list exists""" | |
964 query="select count(*) from pubmanbiblio_projects where lower(key_main) = lower(%s)" | |
965 res= self.executeZSQL(query,[self.getId()]) | |
966 if res[0].count > 0: | |
967 return True | |
968 else: | |
969 return False | |
50 | 970 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
971 |
63 | 972 def addAdditionalPublicationsFromPubman(self,REQUEST): |
973 """addPublications from pubman""" | |
974 data=REQUEST.form | |
975 if data.get("method",None) is None: | |
976 pt = self.editAddAdditionalPublications | |
977 return pt() | |
978 | |
979 if data.get("method") == "search": | |
980 entries= self.mpiwgPubman.search(data) | |
981 pt = self.editAddAdditionalPublications | |
982 return pt(values=entries) | |
983 | |
984 if data.get("method") == "add": | |
985 return self.addEntriesToAdditionalPublicationList(data) | |
986 #pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff/pubman','add_publications.zpt')).__of__(self) | |
987 | |
988 | |
989 def addEntriesToAdditionalPublicationList(self,data): | |
990 """fuege eintrage aus data zur publications liste. | |
991 | |
992 @param data Map mit escidocID --> value | |
993 value muss "add" sein damit hinzugefuegt wird""" | |
994 for key in data.keys(): | |
995 if key.startswith('escidoc:'): | |
996 query="INSERT INTO pubmanbiblio_projects (key_main,escidocId) values (%s,%s)" | |
997 if data.get(key)=="add": | |
998 self.executeZSQL(query,[self.getId(),key]) | |
999 | |
1000 if hasattr(self,'REQUEST'): | |
1001 return self.REQUEST.response.redirect("changeAdditionalPublications") | |
1002 | |
1003 | |
1004 def changeAdditionalPublications(self,REQUEST): | |
1005 """change published publications""" | |
1006 data=REQUEST.form | |
1007 if data.get("method","change"): | |
1008 for key in data.keys(): | |
1009 splitted=key.split("__") #format escidoc_id__p fuer priority, nur escidocid | |
1010 value=data[key] | |
1011 if len(splitted)==1: | |
1012 self.deleteFromAdditionalPublicationList(key); | |
44 | 1013 |
63 | 1014 elif(splitted[1]) == "p": |
1015 self.setAdditionalPublicationPriority(splitted[0],value); | |
1016 | |
1017 pt = self.editAdditionalPublicationsForm | |
1018 return pt() | |
1019 | |
1020 | |
1021 def deleteFromAdditionalPublicationList(self,escidocid): | |
1022 """Loessche publication with escidoc id from publication list""" | |
1023 query ="DELETE FROM pubmanbiblio_projects WHERE escidocid=%s and key_main=%s" | |
1024 self.executeZSQL(query,[escidocid,self.getId()]); | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1025 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1026 |
63 | 1027 def setAdditionalPublicationPriority(self,escidocid,value): |
1028 query="update pubmanbiblio_projects set priority=%s where escidocid=%s and key_main=%s" | |
1029 try: | |
1030 value = int(value) | |
1031 self.executeZSQL(query,[value,escidocid,self.getId()]); | |
1032 except: | |
1033 logging.error("couldn't change:") | |
1034 logging.error(escidocid) | |
1035 logging.error(value) | |
44 | 1036 |
50 | 1037 |
35 | 1038 def getActualVersion(self, date=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1039 """actuelle version""" |
35 | 1040 def sortProjectsByTime(x, y): |
1041 return cmp(x[1].archiveTime, y[1].archiveTime) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1042 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1043 if not date: |
44 | 1044 if self.isCurrentVersion(): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1045 return self |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1046 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1047 return None |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1048 |
35 | 1049 # suche ob aeltere versionen vorhanden sind |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1050 |
35 | 1051 finds = self.ZopeFind(self, obj_metatypes=['MPIWGProject']) |
1052 if not finds: # wenn nicht dann teste ob die aktuelle version schon existiert hat. | |
1053 ad = getattr(self, 'creationTime', '20050101000000') | |
1054 if int(date) > int(ad): | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1055 return self |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1056 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1057 return None |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1058 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1059 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1060 finds.sort(sortProjectsByTime) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1061 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1062 for find in finds: |
35 | 1063 # gehe durch die alten Projekte und finde das entprechende |
1064 if (int(find[1].archiveTime) > int(date)) and (int(date) > int(getattr(find[1], 'creationTime', '20050101000000'))): | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1065 return find[1] |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1066 |
35 | 1067 # kein passendes gefunden, dann teste ob das aktuelle in frage kommt |
1068 ad = getattr(self, 'creationTime', '20050101000000') | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1069 |
35 | 1070 if int(date) > int(ad): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1071 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1072 return self |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1073 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1074 return None |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1075 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1076 |
44 | 1077 def isCurrentVersion(self): |
1078 """Return if project is the current version.""" | |
1079 currentTime = time.localtime() | |
1080 # print getattr(self,'archiveTime',currentTime) | |
1081 return (getattr(self, 'archiveTime', currentTime) >= currentTime) | |
1082 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1083 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1084 def copyObjectToArchive(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1085 """kopiere aktuelles objekt ins archiv""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1086 logging.info("copytoarchive 1") |
35 | 1087 cb = self.aq_parent.manage_copyObjects(self.getId()) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1088 logging.info("copytoarchive 2") |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1089 self.manage_pasteObjects(cb) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1090 logging.info("copytoarchive 3") |
35 | 1091 actualTime = time.localtime() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1092 |
35 | 1093 self.manage_renameObject(self.getId(), self.getId() + "_" + time.strftime("%Y%m%d%H%M%S", actualTime)) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1094 logging.info("copytoarchive 4") |
35 | 1095 obj = getattr(self, self.getId() + "_" + time.strftime("%Y%m%d%H%M%S", actualTime)) |
1096 obj.setArchiveTime(time.strftime("%Y%m%d%H%M%S", actualTime)) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1097 logging.info("copytoarchive 5") |
35 | 1098 ids = [x[0] for x in self.ZopeFind(obj, obj_metatypes=['MPIWGProject'])] |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1099 logging.info("copytoarchive 6") |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1100 obj.manage_delObjects(ids) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1101 logging.info("copytoarchive 7") |
60 | 1102 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1103 |
35 | 1104 def setArchiveTime(self, time): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1105 """set Archive Time""" |
35 | 1106 self.archiveTime = time[0:] |
60 | 1107 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1108 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1109 def delArchiveTime(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1110 """delete archive time""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1111 del self.archiveTime |
60 | 1112 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1113 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1114 def isActiveProject(self): |
39 | 1115 """check if the project is still active, default is true.""" |
35 | 1116 return getattr(self, 'isActiveFlag', True) |
60 | 1117 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1118 |
27 | 1119 def checkActive(self, active): |
1120 """returns if the project state matches the active state. | |
1121 active = 0 : all projects | |
1122 active = 1 : active projects | |
1123 active = 2 : inactive projects | |
1124 """ | |
35 | 1125 act = getattr(self, 'isActiveFlag', True) |
27 | 1126 return (active == 1 and act) or (active == 0) or (active == 2 and not act) |
60 | 1127 |
27 | 1128 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1129 def isArchivedProject(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1130 """check if the project is archived""" |
108
782477730916
CLOSED - # 57: Research/ Research Units: Karussell f?r die Projekte in einem Department
casties
parents:
105
diff
changeset
|
1131 completed = getattr(self, 'completedAt', '') |
35 | 1132 # completed leer |
1133 if completed == "" : | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1134 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1135 if completed == 0: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1136 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1137 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1138 return True |
60 | 1139 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1140 |
27 | 1141 def checkArchived(self, archived): |
1142 """returns if the project state matches the archived state. | |
1143 archived = 0 : all projects | |
1144 archived = 1 : current projects | |
1145 archived = 2 : archived projects | |
1146 """ | |
1147 arch = self.isArchivedProject() | |
1148 return (archived == 1 and not arch) or (archived == 0) or (archived == 2 and arch) | |
60 | 1149 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1150 |
35 | 1151 def setActiveFlag(self, status=True): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1152 """set the active flag""" |
35 | 1153 self.isActiveFlag = status |
60 | 1154 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1155 |
35 | 1156 def setCompletedAt(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1157 """set the date of completion, date should be in the form DD.MM.YYYY or MM.YYYY or YYYY""" |
35 | 1158 # logging.info("DATE:"+repr(date)) |
1159 transformedDate = self.transformDate(date); | |
1160 # logging.info("transformed"+repr(transformedDate)) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1161 if transformedDate is not None: |
35 | 1162 setattr(self, "completedAt", transformedDate) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1163 return True; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1164 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1165 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1166 |
35 | 1167 def setStartedAt(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1168 """set the date of start, date should be in the form DD.MM.YYYY or MM.YYYY or YYYY""" |
35 | 1169 # logging.info("DATE:"+repr(date)) |
1170 transformedDate = self.transformDate(date); | |
1171 # logging.info("transformed"+repr(transformedDate)) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1172 if transformedDate is not None: |
35 | 1173 setattr(self, "startedAt", transformedDate) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1174 return True; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1175 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1176 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1177 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1178 def getCompletedAt(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1179 """gibt das transformierte Datum zurueck, an dem das Projekt beendet wurde.""" |
35 | 1180 date = getattr(self, 'completedAt', '') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1181 if date: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1182 return self.reTransformDate(date); |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1183 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1184 return "" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1185 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1186 def getStartedAt(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1187 """gibt das transformierte Datum zurueck, an dem Projekt begonnen wurde.""" |
35 | 1188 date = getattr(self, 'startedAt', '') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1189 if date: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1190 return self.reTransformDate(date); |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1191 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1192 return ''; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1193 |
35 | 1194 def reTransformDate(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1195 """transformiert , transformdate zurueck""" |
35 | 1196 year = int(date / 10000) |
1197 month = int((date - year * 10000) / 100) | |
1198 day = int((date - year * 10000 - month * 100)) | |
1199 if (day == 0) and (month == 0): | |
1200 return """%s""" % year; | |
1201 if day == 0 : | |
1202 return """%s.%s""" % (month, year); | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1203 |
35 | 1204 return """%s.%s.%s""" % (day, month, year); |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1205 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1206 |
35 | 1207 def transformDate(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1208 """transformiert ein Datum von DD.MM.YYYY, MM.YYYY,YYYY nach YYYYMMDD, alle nicht angebenen Werte |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1209 werden auf 0 gesetzt, es wird null zurueckgegeben falls das Datum ungueltig ist""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1210 |
35 | 1211 if (date == None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1212 return None; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1213 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1214 |
35 | 1215 if (date.lstrip().rstrip() == "") : |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1216 return ""; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1217 |
35 | 1218 splitted = date.split(".") |
1219 length = len(splitted) | |
1220 year = 0 | |
1221 month = 0 | |
1222 day = 0 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1223 if length > 3: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1224 return ""; |
35 | 1225 if length == 3: |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1226 day = int(splitted[0]) |
35 | 1227 if length > 1: |
1228 month = int(splitted[length - 2]) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1229 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1230 if length > 0: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1231 try: |
35 | 1232 year = int(splitted[length - 1]) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1233 except: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1234 pass |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1235 |
35 | 1236 # # logging.info("month:"+(month)) |
1237 if not (0 <= month < 13): | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1238 return None; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1239 |
35 | 1240 if not(0 <= day < 32): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1241 return None; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1242 |
35 | 1243 if (year > 0) and (year < 1900): # jahr nicht vierstellig eingegeben |
1244 year = 2000 + year; | |
1245 return year * 10000 + month * 100 + day | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1246 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1247 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1248 |
35 | 1249 def checkDate(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1250 """teste ob zum Zeitpunkt date eine andere version existierte""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1251 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1252 |
35 | 1253 def sortProjectsByTime(x, y): |
1254 return cmp(x[1].archiveTime, y[1].archiveTime) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1255 |
35 | 1256 # suche ob aeltere versionen vorhanden sind |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1257 |
35 | 1258 finds = self.ZopeFind(self, obj_metatypes=['MPIWGProject']) |
1259 if not finds: # wenn nicht dann teste ob die aktuelle version schon existiert hat. | |
1260 ad = getattr(self, 'creationTime', '20050101000000') | |
1261 if int(date) > int(ad): | |
1262 return self.REQUEST['URL1'] + "/" + self.getId() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1263 else: |
35 | 1264 return self.REQUEST['URL1'] + "/no_project" |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1265 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1266 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1267 finds.sort(sortProjectsByTime) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1268 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1269 for find in finds: |
35 | 1270 # gehe durch die alten Projekte und finde das entprechende |
1271 if (int(find[1].archiveTime) > int(date)) and (int(date) > int(getattr(find[1], 'creationTime', '20050101000000'))): | |
1272 return self.REQUEST['URL1'] + "/" + find[1].getId() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1273 |
35 | 1274 # kein passendes gefunden, dann teste ob das aktuelle in frage kommt |
1275 ad = getattr(self, 'creationTime', '20050101000000') | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1276 |
60 | 1277 if int(date) > int(ad): |
35 | 1278 return self.REQUEST['URL1'] + "/" + self.getId() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1279 else: |
35 | 1280 return self.REQUEST['URL1'] + "/no_project" |
60 | 1281 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1282 |
97 | 1283 def saveFromPreview(self, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1284 """save content aus preview""" |
35 | 1285 self.WEB_project_description = self.previewTemplate.WEB_project_description[0:] |
97 | 1286 #self.REQUEST.RESPONSE.redirect("./index.html") |
1287 if RESPONSE is not None: | |
1288 return self.editDescription() | |
63 | 1289 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1290 |
97 | 1291 def saveEditedContent(self, kupu=None, preview=None, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1292 """save Edited content""" |
35 | 1293 # logging.debug("saveEditedContent kupu=%s preview=%s"%(kupu,preview)) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1294 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1295 if preview: |
35 | 1296 kupu = preview |
97 | 1297 |
35 | 1298 # find content of body tags |
1299 start = kupu.find("<body>") | |
1300 end = kupu.find("</body>") | |
1301 newcontent = kupu[start + 6:end] | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1302 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1303 if preview: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1304 return self.preview(newcontent) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1305 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1306 self.copyObjectToArchive() |
35 | 1307 self.WEB_project_description = newcontent[0:] |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1308 |
97 | 1309 #self.REQUEST.RESPONSE.redirect("./index.html") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1310 |
97 | 1311 if RESPONSE is not None: |
1312 return self.editDescription() | |
1313 | |
60 | 1314 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1315 def getBreadcrumbs(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1316 """return list of breadcrumbs from here to the root""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1317 crumbs = [] |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1318 # skip direct parent Folder /projects/ |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1319 parent = self.aq_parent.aq_parent |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1320 # get parents breadcrumbs |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1321 if hasattr(parent, 'getBreadcrumbs'): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1322 crumbs = parent.getBreadcrumbs() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1323 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1324 # try to get acquisition URL from parent |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1325 if hasattr(parent, 'absolute_url'): |
35 | 1326 baseUrl = "%s/%s/" % (parent.absolute_url(), 'projects') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1327 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1328 baseUrl = "/en/research/projects/" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1329 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1330 # add in the internal project hierarchy |
52 | 1331 tree = self.getProjectTree() |
1332 ap = tree.getAncestorsOf(self.getNumber()) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1333 # start with grandparents |
52 | 1334 for p in ap: |
1335 label = shortenString(p.getLabel(), 13) | |
1336 crumbs.append((label, p.getUrl(baseUrl=baseUrl), p)) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1337 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1338 # add this project |
52 | 1339 crumbs.append((self.getLabel(), self.getUrl(baseUrl=baseUrl), self)) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1340 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1341 return crumbs |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1342 |
52 | 1343 # TODO: is this used? |
35 | 1344 def preview(self, description): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1345 """preview""" |
35 | 1346 # logging.debug("preview description=%s"%description) |
1347 tmpPro = getattr(self, "previewTemplate", None) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1348 if not tmpPro: |
35 | 1349 tmpPro = MPIWGProject("previewTemplate") |
1350 self._setObject("previewTemplate", tmpPro) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1351 for field in definedFields: |
35 | 1352 setattr(tmpPro, field, getattr(self, field)) |
1353 tmpPro.WEB_project_description = description[0:] | |
1354 tmpPro.invisible = True | |
97 | 1355 pt = PageTemplateFile('zpt/project/edit_preview_frame', globals()).__of__(self) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1356 return pt() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1357 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1358 |
35 | 1359 def isResponsibleScientist(self, key): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1360 """teste ob eine Person in der Liste der respl. scientists auftaucht""" |
35 | 1361 for resp in self.getResponsibleScientistsList(): |
60 | 1362 logging.debug("resp=%s key=%s"%(repr(resp),repr(key))) |
63 | 1363 # TODO: we need to get ASCII keys!! |
80 | 1364 if utf8ify(resp.get('key', '')).lower() == utf8ify(key).lower(): |
35 | 1365 return True |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1366 |
35 | 1367 return False |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1368 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1369 |
35 | 1370 def identifyNames(self, nameList): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1371 """Bekommt eine Komma oder Semikolon getrennte Liste mit Name der Form Vorname MittelName(n) Nachname |
33 | 1372 und ordnet diese dann Mitarbeiter IDs zu. |
1373 | |
1374 Returns a dict with full names as keys and a row of person objects from the database as values. | |
1375 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1376 @param nameList |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1377 """ |
35 | 1378 if nameList.find(";") > -1: # rate Trenner ist ; |
1379 names = nameList.split(";") | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1380 else: |
35 | 1381 names = nameList.split(",") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1382 |
35 | 1383 # #nameList=nameList.replace(";",",") # falls ; als Trenner ersetze |
1384 returnNamesDict = {} | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1385 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1386 for name in names: |
35 | 1387 name = name.strip() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1388 nameSplitted = name.split(" ") |
35 | 1389 if len(nameSplitted) > 1: # vor und nachname angegeben) |
1390 lastname = nameSplitted[-1] | |
1391 firstname = nameSplitted[0] | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1392 else: |
35 | 1393 firstname = "" |
1394 lastname = nameSplitted[0] | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1395 |
35 | 1396 # finde Mitarbeiter mit den entsprechenden Name |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1397 |
35 | 1398 # firstname=self.myCapitalize(firstname).encode('utf-8') |
1399 # lastname=self.myCapitalize(lastname).encode('utf-8') | |
1400 logging.debug("Search: %s %s %s" % (name, repr(firstname), repr(lastname))) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1401 try: |
35 | 1402 # cataloggedNames=self.MembersCatalog(firstName=firstname,lastName=lastname) |
33 | 1403 # TODO: I think this does not work without firstname |
1404 # try to find names in members db by searching for sub-words | |
1405 cataloggedNames = self.executeZSQL("select * from personal_www where first_name ~* ('\m'||%s||'\M') and last_name ~* ('\m'||%s||'\M')", (firstname, lastname)) | |
1406 if len(cataloggedNames) == 0: | |
1407 # PostgreSQL has a bug with \m and words ending in non-ASCII :-( | |
1408 cataloggedNames = self.executeZSQL("select * from personal_www where %s in (select regexp_split_to_table(lower(first_name), '\s+')) and %s in (select regexp_split_to_table(lower(last_name), '\s+'))", (firstname.lower(), lastname.lower())) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1409 except: |
35 | 1410 cataloggedNames = [] |
1411 logging.error("ERROR: identifyNames %s %s" % sys.exc_info()[0:2]) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1412 |
35 | 1413 if len(cataloggedNames) > 0: |
1414 returnNamesDict[name] = cataloggedNames | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1415 else: |
35 | 1416 returnNamesDict[name] = [] |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1417 |
50 | 1418 logging.debug("identified names: %s" % repr(returnNamesDict)) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1419 return returnNamesDict |
33 | 1420 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1421 |
49 | 1422 def editMPIWGProject(self, fromEdit=None, createNewVersion=True, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1423 """edit the project and archive the old version""" |
49 | 1424 logging.debug("editMPIWGProject(fromEdit=%s, createNewVersion=%s)"%(fromEdit,createNewVersion)) |
1425 if createNewVersion: | |
1426 self.copyObjectToArchive() # archive the object | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1427 |
35 | 1428 formdata = self.REQUEST.form |
1429 | |
1430 # set all definedFields | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1431 for x in definedFields: |
35 | 1432 if formdata.has_key(x): |
50 | 1433 setattr(self, x, unicodify(formdata[x])) |
99 | 1434 if x == 'xdata_05': |
1435 # changing project number invalidates project tree | |
1436 self.resetProjectTree() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1437 |
35 | 1438 completedAt = formdata.get('completedAt') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1439 if not self.setCompletedAt(completedAt): |
35 | 1440 RESPONSE.redirect('./editMPIWGBasisEditor?error=dateWrong') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1441 |
35 | 1442 startedAt = formdata.get('startedAt') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1443 if not self.setStartedAt(startedAt): |
35 | 1444 RESPONSE.redirect('./editMPIWGBasisEditor?error=dateWrong') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1445 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1446 if self.REQUEST.has_key('active'): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1447 self.setActiveFlag(True) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1448 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1449 self.setActiveFlag(False) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1450 |
35 | 1451 # make dict of responsible scientists |
1452 checkedScientists = {} | |
1453 names = {} | |
1454 keys = {} | |
43 | 1455 for key in formdata: |
35 | 1456 # gehe durch das Formular |
1457 keyParts = key.split("_") | |
1458 if keyParts[0] == "responsibleScientist": | |
1459 # wenn es ein Feld der Form reponsibleScientist_nr_KEY gibt | |
1460 nr = keyParts[2] | |
1461 if keyParts[1] == "name": | |
50 | 1462 names[nr] = unicodify(formdata[key]) |
35 | 1463 elif keyParts[1] == "key": |
1464 keys[nr] = formdata[key] | |
1465 | |
43 | 1466 for nr in names: |
35 | 1467 name = names[nr] |
1468 key = keys.get(nr, None) | |
1469 username = None | |
1470 if key: | |
1471 # get username from db | |
80 | 1472 member = self.en.getMPIWGRoot().getStaffFolder().getMember(key=key) |
40 | 1473 if member is not None: |
1474 username = member.getUsername() | |
35 | 1475 |
1476 # schreibe keys und namen in die Liste | |
1477 checkedScientists[names[nr]] = {'name' : name, 'key' : key, 'username' : username} | |
1478 | |
44 | 1479 # update responsibleScientistsList |
35 | 1480 self.setResponsibleScientistsList(checkedScientists) |
39 | 1481 self.updateProjectMembers() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1482 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1483 if fromEdit and (RESPONSE is not None): |
35 | 1484 return self.editBasic() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1485 |
60 | 1486 if RESPONSE is not None: |
1487 RESPONSE.redirect('manage_main') | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1488 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1489 |
60 | 1490 def getContent(self, field, filter=None): |
1491 """Inhalt des Feldes""" | |
1492 val = getattr(self, field, '') | |
1493 if isinstance(val, list): | |
1494 val = val[0] | |
1495 | |
1496 return val | |
1497 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1498 |
35 | 1499 def loadNewFile(self, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1500 """einlesen des neuen files""" |
35 | 1501 fileupload = self.REQUEST['fileupload'] |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1502 if fileupload: |
35 | 1503 file_name = fileupload.filename |
1504 filedata = fileupload.read() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1505 |
35 | 1506 argv = xmlhelper.proj2hash(filedata) |
1507 # print argv.keys() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1508 for arg in definedFields: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1509 |
35 | 1510 # print arg,argv[arg],getattr(self,arg) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1511 try: |
35 | 1512 temp = argv[arg][0:] |
1513 # old=getattr(self,arg) | |
1514 setattr(self, arg, temp) | |
1515 # print old,getattr(self,arg) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1516 except: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1517 """nothing""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1518 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1519 if RESPONSE is not None: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1520 RESPONSE.redirect('manage_main') |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1521 |
60 | 1522 |
35 | 1523 def tagTheProject(self, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1524 """TAG""" |
35 | 1525 id = self.getId(); |
1526 tmpl = getattr(self.thesaurus, "main.html") | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1527 if RESPONSE: |
35 | 1528 RESPONSE.redirect("./thesaurus/main.html?project=" + id) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1529 return |
36 | 1530 |
1531 | |
81 | 1532 def moveObjectDigitallibraryToInfoBlock(self): |
1533 """Move text from 'Object Digitallibrary' to InfoBlock.""" | |
1534 text = self.getRelatedDigitalSources() | |
1535 if text: | |
1536 logging.debug("Moving 'Object Digitallibrary' to InfoBlock: %s"%repr(text)) | |
1537 self.addInfoBlock(block_title='Related digital sources', item_text=text, item_link=None) | |
1538 delattr(self, 'xdata_11') | |
1539 | |
1540 | |
50 | 1541 def hasRelatedPublicationsOldVersion(self): |
52 | 1542 """teste ob es related publications gibt""" |
50 | 1543 ret = True; |
61 | 1544 if (getattr(self, 'WEB_related_pub', '') == ''): |
50 | 1545 ret = False; # nichts im alten feld |
1546 logging.debug("webrel:" + repr(ret)) | |
1547 if (getattr(self, 'WEB_related_pub_copied', False)): | |
1548 ret = False; # alte daten sind schon kopiert worden | |
1549 | |
1550 logging.debug("webrel_copied:" + repr(ret)) | |
1551 publications = self.ZopeFind(self, obj_metatypes=['MPIWGProject_publication']); | |
1552 | |
1553 if(len(publications) > 0): | |
1554 ret = False; # es gibt publicationen in der neuen liste | |
60 | 1555 |
50 | 1556 logging.debug("len(publ)" + repr(ret)) |
1557 | |
1558 return ret; | |
1559 | |
1560 | |
52 | 1561 def copyPublicationsToList(self, RESPONSE=None): |
1562 """copy publications in to list""" | |
60 | 1563 publicationTxt = getattr(self, 'WEB_related_pub', '') |
1564 if isinstance(publicationTxt, list): | |
1565 publicationTxt = publicationTxt[0] | |
52 | 1566 |
1567 pubSplits = publicationTxt.split("<p>") | |
1568 | |
1569 for pubSplit in pubSplits: | |
1570 pubSplit = pubSplit.replace("</p>", "") | |
1571 self.addPublication(pubSplit) | |
1572 | |
1573 setattr(self, "WEB_related_pub_copied", True); | |
1574 | |
1575 if RESPONSE: | |
1576 self.redirect(RESPONSE, 'managePublications') | |
1577 | |
1578 | |
50 | 1579 def hasInlineImage(self): |
1580 """Return the number of inline images in the description.""" | |
1581 text = self.getDescription() | |
1582 cnt = text.count('<p class="picture">') | |
1583 return cnt | |
1584 | |
1585 | |
1586 def copyImageToMargin(self, RESPONSE=None): | |
1587 """copy inline images to marginal images""" | |
1588 # getImages from WEB_project_description | |
1589 description = self.getDescription() | |
1590 | |
1591 text2 = description | |
1592 splitted = text2.split("""<p class="picture">""") | |
1593 | |
1594 imageURLs = [] | |
1595 imageCaptions = [] | |
1596 for split in splitted[1:]: | |
1597 tmp = split.split("</p>") | |
1598 # return repr(splitted[1]) | |
1599 | |
1600 try: | |
1601 imageURLs.append(tmp[0].split("\"")[1].encode('utf-8')) | |
1602 except: | |
1603 | |
1604 try: | |
1605 imageURLs.append(tmp[0].split("src=")[1].split(" ")[0].encode('utf-8')) | |
1606 except: | |
1607 imageURLs.append("") | |
1608 | |
1609 split2 = "</p>".join(tmp[1:]) | |
1610 splitted = split2.split("""<p class="picturetitle">""") | |
1611 if len(splitted) > 1: | |
1612 tmp = splitted[1].split("</p>") | |
1613 imageCaptions.append(tmp[0].encode('utf-8')) | |
1614 | |
1615 else: | |
1616 # keine caption | |
1617 imageCaptions.append("") | |
1618 | |
1619 # eintragen: | |
1620 for imageURL in imageURLs: | |
1621 if not imageURL: | |
1622 # no URL - no image | |
1623 continue | |
1624 | |
1625 filename = imageURL.split("/")[-1] | |
1626 # lege neues images object an, mit leerem bild | |
1627 | |
1628 if filename in self: | |
1629 # existiert das bild schon, dann neuen filenamen | |
1630 filename = "project_image_" + filename | |
1631 if filename in self: | |
1632 # exists too - assume its already converted | |
1633 logging.warn("copyImageToMargin: image %s exists - skipping!"%filename) | |
1634 continue | |
1635 | |
1636 self.addImage(None, imageCaptions[imageURLs.index(imageURL)], filename=filename) | |
1637 # hole die bilddaten aus der url | |
1638 url = self.absolute_url() + "/" + imageURL | |
1639 # url=self.absolute_url()+"/"+filename | |
1640 | |
1641 try: # relative url | |
1642 data = urllib.urlopen(url).read() | |
1643 except: | |
1644 try: # absolute | |
1645 data = urllib.urlopen(self.imageURL).read() | |
1646 except: | |
1647 logging.error("copyImageToMargin: can't open: %s" % url) | |
1648 | |
1649 obj = getattr(self, filename) | |
1650 obj.update_data(data) | |
1651 | |
1652 # clean description | |
1653 logging.debug("copyImageToMargin: description:%s"%repr(description)) | |
1654 dom = ET.fromstring(utf8ify("<html>%s</html>"%description)) | |
1655 for e in dom.findall(".//p[@class='picture']"): | |
1656 # remove contents | |
1657 e.clear() | |
1658 # remove tag | |
1659 e.tag = None | |
1660 | |
1661 for e in dom.findall(".//p[@class='picturetitle']"): | |
1662 # remove contents | |
1663 e.clear() | |
1664 # remove tag | |
1665 e.tag = None | |
1666 | |
1667 # remove html tag | |
1668 dom.tag = None | |
1669 # set as new description | |
1670 description = unicodify(serialize(dom)) | |
1671 logging.debug("copyImageToMargin: new description:%s"%repr(description)) | |
1672 setattr(self, 'WEB_project_description', description) | |
1673 | |
1674 if RESPONSE: | |
1675 self.redirect(RESPONSE, 'manageImages') | |
1676 | |
1677 | |
36 | 1678 def updateProjectMembers(self, updateResponsibleScientistsList=False): |
60 | 1679 """Update project-member table.""" |
1680 # projects are identified by id | |
1681 pid = self.getId() | |
1682 | |
36 | 1683 # clear projects_members table |
60 | 1684 self.executeZSQL("delete from projects_members where project_id = %s", [pid]) |
36 | 1685 |
60 | 1686 for m in self.getResponsibleScientistsList(): |
42 | 1687 memberKey = m.get('key', None) |
36 | 1688 if not memberKey or not isinstance(memberKey, basestring): |
1689 logging.error("updateProjectMembers: not a valid member key: %s" % repr(memberKey)) | |
1690 continue | |
1691 | |
60 | 1692 # fill projects_members table |
1693 self.executeZSQL("insert into projects_members (project_id, member_key) values (%s, %s)", (pid, memberKey)) | |
56 | 1694 |
1695 | |
60 | 1696 |
56 | 1697 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1698 def manage_addMPIWGProjectForm(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1699 """form for adding the project""" |
35 | 1700 pt = PageTemplateFile(os.path.join(package_home(globals()), 'zpt', 'addMPIWGProjectForm.zpt')).__of__(self) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1701 return pt() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1702 |
35 | 1703 def manage_addMPIWGProject(self, id, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1704 """method to add a project""" |
35 | 1705 # print argv |
1706 fileupload = self.REQUEST.get('fileupload', None) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1707 if fileupload: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1708 |
35 | 1709 file_name = fileupload.filename |
1710 filedata = fileupload.read() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1711 |
35 | 1712 argv = xmlhelper.proj2hash(filedata) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1713 |
35 | 1714 # print argv |
1715 newObj = MPIWGProject(id, argv) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1716 else: |
35 | 1717 newObj = MPIWGProject(id) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1718 |
35 | 1719 self._setObject(id, newObj) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1720 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1721 if RESPONSE is not None: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1722 RESPONSE.redirect('manage_main') |
27 | 1723 |
1724 | |
33 | 1725 class MPIWGProjectFolder(ZDBInterfaceFolder): |
27 | 1726 """Folder of project objects""" |
1727 | |
35 | 1728 meta_type = "MPIWGProjectFolder" |
1729 security = ClassSecurityInfo() | |
1730 | |
27 | 1731 # cached HashTree with project hierarchy |
1732 _v_projectTree = None | |
53 | 1733 |
34 | 1734 def getProjectTree(self): |
43 | 1735 """Return the project hierarchy tree (and cache it). |
34 | 1736 |
43 | 1737 Returns HashTree instance.""" |
27 | 1738 tree = self._v_projectTree |
1739 if tree is None: | |
43 | 1740 tree = HashTree(keySeparator='.', keyFn=getInt) |
27 | 1741 for p in self.objectValues(spec='MPIWGProject'): |
51 | 1742 # add all projects |
27 | 1743 tree.add(p.getNumber(), p) |
1744 | |
1745 self._v_projectTree = tree | |
35 | 1746 # logging.debug("getProjectTree: tree=%s"%(tree.root.getSubtreeAsText())) |
27 | 1747 |
1748 return tree | |
1749 | |
1750 | |
105
246d87d33f25
CLOSED - # 79: sortierung der liste der projekte pro abteilung
casties
parents:
102
diff
changeset
|
1751 def getProjectsAsList(self, start=None, active=1, archived=1, depthFirst=True): |
43 | 1752 """Return flattened list of projects, starting from start. |
33 | 1753 |
27 | 1754 active = 0 : all projects |
1755 active = 1 : active projects | |
1756 active = 2 : inactive projects | |
1757 archived = 0 : all projects | |
1758 archived = 1 : current projects | |
1759 archived = 2 : archived projects | |
1760 """ | |
35 | 1761 # logging.debug("getProjectsAsList(start=%s,active=%s,archived=%s)"%(repr(start),active,archived)) |
34 | 1762 tree = self.getProjectTree() |
27 | 1763 node = tree.getNode(start) |
1764 if node is None: | |
1765 return [] | |
1766 | |
105
246d87d33f25
CLOSED - # 79: sortierung der liste der projekte pro abteilung
casties
parents:
102
diff
changeset
|
1767 pl = node.getSubtreeAsList(depthFirst=depthFirst) |
35 | 1768 # logging.debug("getProjectsAsList: node=(%s,%s) pl=%s"%(node.key,node.value,pl)) |
27 | 1769 # return filtered list |
1770 return [p for p in pl if (p.checkActive(active) and p.checkArchived(archived))] | |
33 | 1771 |
39 | 1772 |
1773 def getProject(self, projectNumber=None): | |
43 | 1774 """Return the matching project""" |
39 | 1775 tree = self.getProjectTree() |
1776 if projectNumber is not None: | |
1777 return tree.get(projectNumber) | |
1778 | |
1779 return None | |
1780 | |
33 | 1781 |
1782 def getProjectsOfMember(self, key, active=1, archived=1): | |
43 | 1783 """Return a list of all projects of a member. |
33 | 1784 |
1785 @param key: member's key | |
1786 active = 0 : all projects | |
1787 active = 1 : active projects | |
1788 active = 2 : inactive projects | |
1789 archived = 0 : all projects | |
1790 archived = 1 : current projects | |
1791 archived = 2 : archived projects | |
1792 """ | |
1793 projects = [] | |
1794 # search project numbers | |
1795 res = self.executeZSQL("select * from projects_members where lower(member_key) = %s", [key.lower()]) | |
77 | 1796 # find projects in folder |
33 | 1797 for r in res: |
77 | 1798 p = self.get(r.project_id, None) |
43 | 1799 # check if active |
33 | 1800 if p is not None and p.checkActive(active) and p.checkArchived(archived): |
1801 projects.append(p) | |
77 | 1802 |
1803 # sort by project number | |
79 | 1804 projects.sort(key=lambda p:[getInt(n) for n in p.getNumber().split('.')]) |
77 | 1805 return projects |
1806 | |
1807 | |
79 | 1808 def getMembersWithProjects(self, onlyActive=True): |
77 | 1809 """Return a list of all members that have projects. |
1810 | |
79 | 1811 @param onlyActive: only active members |
1812 | |
1813 Returns a list of member objects. | |
77 | 1814 """ |
79 | 1815 members = [] |
1816 sf = self.en.getStaffFolder() | |
78 | 1817 res = self.executeZSQL("select distinct member_key from projects_members") |
79 | 1818 if onlyActive: |
1819 for r in res: | |
1820 m = sf.getMember(key=r.member_key) | |
1821 if m is not None and m.isActive(): | |
1822 members.append(m) | |
1823 | |
1824 else: | |
1825 # not only active | |
1826 members = [sf.getMember(key=r.member_key) for r in res] | |
1827 | |
1828 return members | |
27 | 1829 |
1830 | |
99 | 1831 def resetProjectTree(self): |
1832 """Reset the project tree.""" | |
1833 self._v_projectTree = None | |
1834 | |
1835 | |
51 | 1836 security.declareProtected('View management screens', 'changeProjectTree') |
1837 def changeProjectTree(self, RESPONSE=None): | |
1838 """change the complete tree""" | |
1839 form=self.REQUEST.form | |
1840 onlyArchived=int(form.get("onlyArchived",0)) | |
1841 onlyActive=int(form.get("onlyActive",0)) | |
1842 dep=form.get("dep",None) | |
1843 | |
1844 fields = self.getProjectsAsList(start=dep, archived=onlyArchived, active=onlyActive) | |
1845 | |
1846 logging.info("GOT TREE!----------------------------------------------------") | |
1847 for field in form.keys(): | |
1848 | |
1849 splitted=field.split('_') | |
1850 if (len(splitted)>1) and (splitted[1]=="runningNumber"): | |
1851 #feld hat die Form Nummer_name und runnignNumber | |
1852 nr=int(splitted[0]) # nummer des Datensatzes | |
1853 project = fields[nr] | |
1854 | |
1855 # | |
1856 # change active | |
1857 # | |
1858 if form.has_key('%s_active'%nr): # active flag is set | |
1859 project.setActiveFlag(True) | |
1860 else: | |
1861 project.setActiveFlag(False) | |
1862 | |
1863 # | |
1864 # nummer hat sich geaendert | |
1865 # | |
1866 entryChanged = False; | |
1867 pronum = project.getNumber() | |
1868 formnum = form['%s_number'%nr] | |
1869 | |
1870 if not (pronum == formnum): | |
1871 logging.debug("Changed!Number+++++++++++++++++++++++++++++++++") | |
1872 logging.debug(repr(fields[nr].xdata_05)+" ---> "+ repr(form[str(nr)+'_number'])) | |
1873 entryChanged = True | |
1874 | |
1875 # | |
1876 # completed hat sich geaendert | |
1877 # | |
1878 td = project.transformDate # hole die funktion zum transformieren des datums | |
1879 formstarted = form[str(nr)+'_started'] | |
1880 formcompleted = form[str(nr)+'_completed'] | |
1881 | |
1882 if not (td(project.getCompletedAt()) == td(formcompleted)): | |
1883 logging.info(repr(td(project.getCompletedAt()))+" ---> "+ repr(td(form[str(nr)+'_completed']))) | |
1884 logging.info("Changed!Completed+++++++++++++++++++++++++++++++++") | |
1885 entryChanged = True | |
1886 | |
1887 if not (td(project.getStartedAt()) == td(formstarted)): | |
1888 logging.info(repr(td(project.getStartedAt()))+" ---> "+ repr(td(form[str(nr)+'_started']))) | |
1889 logging.info("Changed!Started+++++++++++++++++++++++++++++++++") | |
1890 entryChanged = True | |
1891 | |
1892 if entryChanged: | |
1893 logging.info("Changed!+++++++++++++++++++++++++++++++++") | |
1894 project.copyObjectToArchive() | |
1895 project.xdata_05 = formnum | |
1896 project.setCompletedAt(formcompleted) | |
1897 project.setStartedAt(formstarted) | |
1898 # reset tree | |
1899 self._v_projectTree = None | |
1900 | |
1901 if RESPONSE is not None: | |
1902 RESPONSE.redirect(self.en.MPIWGrootURL()+'/admin/showTree') | |
1903 | |
52 | 1904 |
35 | 1905 security.declareProtected('View management screens', 'updateAllProjectMembers') |
33 | 1906 def updateAllProjectMembers(self, updateResponsibleScientistsList=False): |
43 | 1907 """Re-create responsibleScientistsLists and projects_members table from all current projects.""" |
33 | 1908 # empty table |
1909 self.executeZSQL('truncate table projects_members') | |
1910 cnt = 0 | |
1911 # go through all projects | |
1912 for p in self.objectValues(spec='MPIWGProject'): | |
1913 cnt += 1 | |
1914 memberlist = [] | |
35 | 1915 logging.debug("updateAllProjectMembers: updating project %s" % p) |
36 | 1916 p.updateProjectMembers(updateResponsibleScientistsList=updateResponsibleScientistsList) |
33 | 1917 |
35 | 1918 return "updated %s projects!" % cnt |
33 | 1919 |
40 | 1920 |
39 | 1921 security.declareProtected('View management screens', 'updateAllProjects') |
50 | 1922 def updateAllProjects(self, updateResponsibleScientistsList=False, RESPONSE=None): |
43 | 1923 """Patch all current projects for legacy problems.""" |
39 | 1924 cnt = 0 |
50 | 1925 fulllog = "" |
39 | 1926 # go through all projects |
44 | 1927 for (id, project) in self.ZopeFind(self, obj_metatypes=['MPIWGProject'], search_sub=1): |
50 | 1928 log = "" |
39 | 1929 cnt += 1 |
1930 # | |
1931 # hasRelatedPublicationsOldVersion | |
1932 # | |
1933 if project.hasRelatedPublicationsOldVersion(): | |
49 | 1934 log += "%s: update relatedPublicationsOldVersion!\n"%project.getId() |
39 | 1935 logging.debug("updateAllProjects(%s): update relatedPublicationsOldVersion!"%project.getId()) |
1936 project.copyPublicationsToList() | |
1937 | |
1938 # | |
60 | 1939 # create responsibleScientistsList automatically |
39 | 1940 # |
60 | 1941 if updateResponsibleScientistsList: |
39 | 1942 newScientists = {} |
65 | 1943 names = project.identifyNames(project.getResponsibleScientists()) |
60 | 1944 for name in names: |
1945 logging.debug("updateAllProjectMembers: name=%s" % repr(name)) | |
1946 members = names[name] | |
1947 if len(members) > 0: | |
1948 # take the first matching name | |
1949 newScientists[name] = {'name': name, 'key' : members[0].key, 'username' : re.sub('@mpiwg-berlin\.mpg\.de', '', members[0].e_mail)} | |
39 | 1950 |
1951 project.setResponsibleScientistsList(newScientists) | |
60 | 1952 |
1953 else: | |
1954 # | |
1955 # old format responsibleScientistsList | |
1956 # | |
1957 memberlist = project.getResponsibleScientistsList() | |
1958 if len(memberlist) > 0 and isinstance(memberlist[0], tuple): | |
1959 log += "%s: updating memberlist!\n"%project.getId() | |
1960 logging.debug("updateAllProjects(%s): updating memberlist" % project.getId()) | |
1961 newScientists = {} | |
1962 for m in memberlist: | |
1963 name = m[0] | |
1964 key = m[1] | |
1965 username = None | |
1966 if key: | |
1967 if isinstance(key, list): | |
1968 key = key[0] | |
1969 | |
1970 # get username from db | |
80 | 1971 member = self.en.getMPIWGRoot().getStaffFolder().getMember(key=key) |
60 | 1972 if member is not None: |
1973 username = member.getUsername() | |
1974 | |
1975 newScientists[name] = {'name': name, 'key' : key, 'username' : username} | |
1976 | |
1977 # set new list | |
1978 project.setResponsibleScientistsList(newScientists) | |
39 | 1979 |
1980 # | |
49 | 1981 # old inline images |
1982 # | |
1983 if project.hasInlineImage(): | |
1984 log += "%s: has inlineImage!\n"%project.getId() | |
1985 logging.debug("updateAllProjects(%s): has inlineImage!"%project.getId()) | |
1986 try: | |
1987 project.copyImageToMargin() | |
1988 except Exception, e: | |
1989 log += "%s: ERROR in copyImageToMargin!\n"%project.getId() | |
1990 logging.debug("updateAllProjects(%s): ERROR in copyImageToMargin: %s"%(project.getId(), e)) | |
1991 | |
1992 | |
1993 # | |
39 | 1994 # remove old attributes |
1995 # | |
1996 if hasattr(project, 'definedFields'): | |
49 | 1997 log += "%s: has definedFields!\n"%project.getId() |
39 | 1998 logging.debug("updateAllProjects(%s): has definedFields!"%project.getId()) |
1999 delattr(project, 'definedFields') | |
61 | 2000 |
45 | 2001 # |
61 | 2002 # update related publications |
45 | 2003 # |
61 | 2004 for pub in project.getPublicationList(): |
62 | 2005 if not pub.text: |
2006 msg = "%s: publication has no text: %s!\n"%(project.getId(), pub) | |
2007 log += msg | |
2008 logging.warn(msg) | |
2009 if not pub.link: | |
2010 msg = "%s: publication has no link either! Deleting: %s!\n"%(project.getId(), pub) | |
2011 log += msg | |
2012 logging.error(msg) | |
2013 project.deletePublication(pub.getId()) | |
2014 | |
2015 else: | |
2016 # hasLinkToBookPage updates the bookId | |
2017 pub.hasLinkToBookPage() | |
61 | 2018 |
81 | 2019 |
2020 # | |
2021 # update RelatedDigitalSources | |
2022 # | |
2023 project.moveObjectDigitallibraryToInfoBlock() | |
2024 | |
50 | 2025 # |
2026 # unicodify | |
2027 # | |
2028 for field in ('WEB_title', 'xdata_01', 'xdata_07', 'xdata_08', 'xdata_11', 'xdata_12', 'xdata_13', | |
2029 'WEB_project_description', 'WEB_related_pub'): | |
2030 text = getattr(project, field, None) | |
2031 if isinstance(text, str): | |
2032 log += "%s: has non-unicode field %s\n"%(project.getId(), field) | |
2033 logging.debug("updateAllProjects(%s): has has non-unicode field %s\n"%(project.getId(), field)) | |
2034 setattr(project, field, unicodify(text)) | |
2035 | |
2036 fulllog += log | |
2037 if RESPONSE is not None: | |
2038 RESPONSE.write(log) | |
62 | 2039 |
50 | 2040 log += "\n DONE! updated %s projects!" % cnt |
2041 fulllog += log | |
2042 if RESPONSE is not None: | |
2043 RESPONSE.write(log) | |
2044 RESPONSE.flush() | |
2045 else: | |
2046 return fulllog | |
39 | 2047 |
33 | 2048 |
27 | 2049 def manage_addMPIWGProjectFolderForm(self): |
29 | 2050 """form for adding a MPIWGProjectFolder""" |
27 | 2051 pt = PageTemplateFile('zpt/project/manage_add_MPIWGProjectFolder', globals()).__of__(self) |
2052 return pt() | |
2053 | |
35 | 2054 def manage_addMPIWGProjectFolder(self, id, title, RESPONSE=None): |
29 | 2055 """add a MPIWGProjectFolder""" |
35 | 2056 newObj = MPIWGProjectFolder(id, title) |
27 | 2057 |
35 | 2058 self._setObject(id, newObj) |
27 | 2059 |
2060 if RESPONSE is not None: | |
2061 RESPONSE.redirect('manage_main') | |
2062 |