Mercurial > hg > MPIWGWeb
annotate MPIWGProjects.py @ 130:06020bd06a7d
add center.wide option.
author | casties |
---|---|
date | Thu, 30 May 2013 22:13:20 +0200 |
parents | 220f37701e8d |
children | 4a8a532a05ba |
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()) | |
123
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
525 if not name: |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
526 continue |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
527 |
35 | 528 logging.debug("setResponsibleScientistsList: name=%s"%repr(name)) |
529 if name in nameDict: | |
530 # found in data | |
531 data = nameDict[name] | |
532 scientistsList.append({'name': name, 'key': data['key'], 'username': data['username']}) | |
533 else: | |
534 scientistsList.append({'name': name}) | |
535 | |
536 logging.debug("setResponsibleScientistsList: nameDict=%s new list=%s"%(repr(nameDict),repr(scientistsList))) | |
537 self.responsibleScientistsList = scientistsList | |
123
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
538 # force update of the Properties list in the ZopeDB |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
539 self._p_changed = 1 |
35 | 540 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
541 |
39 | 542 def getInvolvedScholars(self): |
543 """returns the other involved scholars""" | |
544 t = getattr(self, 'xdata_08', None) | |
545 if isinstance(t, list): | |
546 # compat with old lists | |
547 return t[0] | |
548 else: | |
549 return t | |
550 | |
551 | |
552 def getCooperationPartners(self): | |
553 """returns the cooperation partners""" | |
554 t = getattr(self, 'xdata_12', None) | |
555 if isinstance(t, list): | |
556 # compat with old lists | |
557 return t[0] | |
558 else: | |
559 return t | |
560 | |
61 | 561 |
96
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
562 def getMPIWGProject(self): |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
563 """Return this project for acquisition.""" |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
564 return self |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
565 |
2dd8e3be4a8e
add project image link. fix edit image template bug.
casties
parents:
95
diff
changeset
|
566 |
61 | 567 def getMPIWGProjectUrl(self): |
568 """Return this project for acquisition.""" | |
569 return self.absolute_url() | |
570 | |
39 | 571 |
80 | 572 getUrl = MPIWGHelper.getUrl |
27 | 573 |
574 | |
65 | 575 def getThumbUrl(self, default=None): |
24 | 576 """returns the URL of the project thumbnail image""" |
97 | 577 thumb = getattr(self, 'projectThumb', None) |
36 | 578 if thumb is None: |
52 | 579 # get thumb from list (thumb is last image) |
36 | 580 imgs = self.getImageList() |
581 if len(imgs) > 0: | |
52 | 582 thumb = imgs[-1] |
36 | 583 self.projectThumb = thumb |
584 | |
585 if thumb is None: | |
52 | 586 return default |
36 | 587 |
588 return thumb.absolute_url() | |
589 | |
24 | 590 |
39 | 591 def getDepartment(self): |
592 """returns the department of this project""" | |
593 num = self.getNumber() | |
594 pp = num.find('.') | |
595 if pp > 0: | |
596 num = num[:pp] | |
597 | |
80 | 598 return self.en.getMPIWGRoot().getDepartment(projectNumber=num) |
39 | 599 |
600 | |
601 def getDepartmentId(self): | |
602 """returns the id of the department of this project""" | |
603 dep = self.getDepartment() | |
604 if dep is not None: | |
605 return dep.getId() | |
606 | |
607 return None | |
608 | |
609 | |
102 | 610 def getDescription(self, filter=None, length=0): |
39 | 611 """returns the project description""" |
49 | 612 text = getattr(self, 'WEB_project_description', None) |
613 if isinstance(text, list): | |
39 | 614 # compat with old lists |
49 | 615 text = text[0] |
616 | |
102 | 617 if filter == 'plaintext': |
618 # filter out any tags, keep only text | |
619 try: | |
620 xmltext = utf8ify("<div>%s</div>"%text) | |
621 dom = ET.fromstring(xmltext) | |
622 plaintext = "" | |
623 for elem in dom.iter(): | |
624 if elem.tag == 'style': | |
625 # ignore tag | |
626 continue | |
627 | |
628 if elem.text: | |
629 plaintext += elem.text | |
630 if elem.tail: | |
631 plaintext += elem.tail | |
632 | |
633 if length > 0 and len(plaintext) > length: | |
634 break | |
635 | |
636 text = plaintext | |
637 except Exception, e: | |
638 logging.warn("getDesciption: error parsing description! Returning everything. %s"%e) | |
639 | |
640 if length > 0 and len(text) > length: | |
641 # try to not break words | |
642 if text[length] not in [' ', '.', '?', '!']: | |
643 # search the last blank | |
644 length = text.rfind(' ', 0, length) | |
645 | |
646 return text[:length] + '...' | |
647 | |
49 | 648 return text |
649 | |
39 | 650 |
651 def getSuperProjects(self): | |
652 """returns a list of ancestor projects to the root""" | |
653 tree = self.getProjectTree() | |
654 return tree.getAncestorsOf(self.getNumber()) | |
655 | |
656 | |
657 def getSubProjects(self, active=1): | |
658 """returns a list of child projects""" | |
659 tree = self.getProjectTree() | |
660 return [p for p in tree.getChildrenOf(self.getNumber()) if p.checkActive(active)] | |
661 | |
662 | |
663 def getRelatedDigitalSources(self): | |
664 """returns the related digital sources""" | |
665 t = getattr(self, 'xdata_11', None) | |
666 if isinstance(t, list): | |
667 # compat with old lists | |
668 return t[0] | |
669 else: | |
670 return t | |
43 | 671 |
39 | 672 |
673 def getFundingInstitutions(self): | |
674 """returns the funding institutions""" | |
675 t = getattr(self, 'xdata_13', None) | |
676 if isinstance(t, list): | |
677 # compat with old lists | |
678 return t[0] | |
679 else: | |
680 return t | |
681 | |
24 | 682 |
63 | 683 def _moveObjectPlace(self, objectList, objectId, direction): |
60 | 684 """Move object with objectId from objectList in direction |
685 by changing its place attribute.""" | |
686 if not objectId or not direction: | |
687 return | |
688 | |
689 for idx in range(len(objectList)): | |
690 object = objectList[idx] | |
61 | 691 if object.getId() == objectId: |
60 | 692 if direction == 'up': |
693 if idx > 0: | |
694 # move up | |
695 objectList[idx -1].place += 1 | |
696 objectList[idx].place -= 1 | |
697 | |
698 elif direction == 'down': | |
699 if idx < len(objectList) - 1: | |
700 # move down | |
701 objectList[idx + 1].place -= 1 | |
702 objectList[idx].place += 1 | |
703 | |
704 return | |
705 | |
63 | 706 |
707 def getImageList(self): | |
708 """returns the sorted list of images for this project""" | |
709 items = self.objectValues(spec='MPIWGProject_image') | |
710 # sort by place | |
711 return sorted(items, key=lambda x:int(getattr(x, 'place', 0))) | |
712 | |
713 | |
714 def addImage(self, fileHd, caption, RESPONSE=None, filename=None): | |
715 """add an MPIWG_Project_image""" | |
716 | |
717 if not filename: | |
718 filename = fileHd.filename | |
719 | |
720 if not fileHd: | |
721 fileHd = file(os.path.join(package_home(globals()), 'blank.gif')) | |
722 | |
723 newImage = MPIWGProject_image(filename, filename, fileHd) | |
724 | |
725 self._setObject(filename, newImage) | |
726 obj = getattr(self, filename) | |
727 obj.caption = caption[:] | |
728 obj.enabled = True; | |
729 obj.place = self._getLastImageNumber() + 1 | |
730 obj.id = filename | |
731 | |
732 # invalidate thumbnail | |
733 self.projectThumb = None | |
734 | |
735 if RESPONSE is not None: | |
736 self.redirect(RESPONSE, 'manageImages') | |
737 | |
738 | |
739 def _getLastImageNumber(self): | |
740 items = self.getImageList() | |
741 if not items: | |
742 return 0 | |
743 else: | |
744 return getattr(items[-1], 'place', 0) | |
745 | |
746 | |
61 | 747 def manageImages(self, name=None, op=None): |
60 | 748 """manage images""" |
63 | 749 self._moveObjectPlace(self.getImageList(), name, op) |
60 | 750 |
51 | 751 # invalidate thumbnail |
752 self.projectThumb = None | |
60 | 753 |
754 pt = self.editImagesForm | |
50 | 755 return pt() |
756 | |
60 | 757 |
63 | 758 def deleteImage(self, id, RESPONSE=None): |
759 """delete Image id""" | |
760 try: | |
761 self.manage_delObjects([id]) | |
762 except: | |
763 logging.error("ERROR MPIWG: %s %s" % sys.exc_info()[0:2]) | |
764 | |
765 # invalidate thumbnail | |
766 self.projectThumb = None | |
767 | |
768 if RESPONSE: | |
769 self.redirect(RESPONSE, 'manageImages') | |
50 | 770 |
63 | 771 |
772 def getPublicationList(self): | |
773 """returns the list of related publications""" | |
774 items = self.objectValues(spec='MPIWGProject_publication') | |
775 # sort by place | |
776 items.sort(key=lambda x:int(getattr(x, 'place', 0))) | |
777 return items | |
778 | |
50 | 779 |
64 | 780 def addPublication(self, text=None, link=None, RESPONSE=None): |
50 | 781 """add an MPIWG_Publication""" |
64 | 782 if text or link: |
783 number = self._getLastPublicationNumber() + 1 | |
50 | 784 name = "publication_" + str(number) |
64 | 785 while hasattr(self, name): |
786 number += 1 | |
787 name = "publication_" + str(number) | |
788 | |
789 newPublication = MPIWGProject_publication(name) | |
50 | 790 |
64 | 791 self._setObject(name, newPublication) |
792 obj = getattr(self, name) | |
793 obj.text = text | |
794 obj.link = link | |
795 obj.enabled = True; | |
796 obj.place = self._getLastPublicationNumber() + 1 | |
797 obj.id = name | |
798 # hasLinkToBookPage updates bookid if available | |
799 if obj.hasLinkToBookPage() and not text: | |
800 # take title from book page | |
801 try: | |
802 book = self.en.books[obj.bookId] | |
803 obj.text = book.getInfo('title') | |
804 except: | |
805 pass | |
50 | 806 |
807 if RESPONSE is not None: | |
808 self.redirect(RESPONSE, 'managePublications') | |
809 | |
60 | 810 |
63 | 811 def _getLastPublicationNumber(self): |
812 items = self.getPublicationList() | |
813 if not items: | |
814 return 0 | |
815 else: | |
816 return getattr(items[-1], 'place', 0) | |
817 | |
818 | |
819 def managePublications(self, name=None, op=None): | |
820 """manage publications""" | |
821 self._moveObjectPlace(self.getPublicationList(), name, op) | |
822 | |
823 pt = self.editPublicationsForm | |
824 return pt() | |
50 | 825 |
63 | 826 |
827 def deletePublication(self, id, RESPONSE=None): | |
828 """delete Publication id""" | |
829 self.manage_delObjects([id]) | |
830 if RESPONSE: | |
831 self.redirect(RESPONSE, 'managePublications') | |
832 | |
833 | |
834 def getRelatedProjectList(self): | |
835 """returns the list of related projects""" | |
836 items = self.objectValues(spec='MPIWGProject_relatedProject') | |
837 # sort by place | |
838 items.sort(key=lambda x:int(getattr(x, 'place', 0))) | |
839 return items | |
840 | |
60 | 841 |
50 | 842 def addRelatedProject(self, link, RESPONSE=None): |
60 | 843 """add a MPIWGProject_relatedProject""" |
63 | 844 number = self._getLastRelatedProjectNumber() + 1 |
61 | 845 name = "related_project_" + str(number) |
50 | 846 while hasattr(self, name): |
847 number += 1 | |
61 | 848 name = "related_project_" + str(number) |
50 | 849 |
850 # hole die id des projektes | |
851 splitted = link.split("/") | |
852 | |
853 # teste ob es das project gibt | |
854 if len(splitted) < 1: | |
855 self.redirect(RESPONSE, 'errorRelatedProjects?link=' + link) | |
856 | |
857 objid = splitted[-1] | |
858 object = getattr(self.projects, objid, None) | |
859 | |
860 if object == None: | |
861 self.redirect(RESPONSE, 'errorRelatedProjects?link=' + link) | |
862 return | |
863 | |
864 newPublication = MPIWGProject_relatedProject(name) | |
865 | |
866 self._setObject(name, newPublication) | |
867 obj = getattr(self, name) | |
868 obj.orginallink = link[0:] | |
869 obj.objid = objid[0:] | |
870 logging.debug("add relobj:objid" + repr(obj.objid)) | |
60 | 871 obj.projectWEB_title = object.getProjectTitle() |
50 | 872 logging.debug("add relobj:webtitle" + repr(obj.projectWEB_title)) |
873 obj.enabled = True; | |
63 | 874 obj.place = self._getLastRelatedProjectNumber() + 1 |
50 | 875 obj.id = name |
876 if RESPONSE is not None: | |
877 self.redirect(RESPONSE, 'manageRelatedProjects') | |
878 | |
879 | |
63 | 880 def _getLastRelatedProjectNumber(self): |
61 | 881 items = self.getRelatedProjectList() |
882 if not items: | |
50 | 883 return 0 |
884 else: | |
61 | 885 return getattr(items[-1], 'place', 0) |
60 | 886 |
50 | 887 |
63 | 888 def manageRelatedProjects(self, name=None, op=None): |
889 """manage related projects""" | |
890 self._moveObjectPlace(self.getRelatedProjectList(), name, op) | |
891 | |
892 pt = self.editRelatedProjectsForm | |
893 return pt() | |
894 | |
895 | |
896 def deleteRelatedProject(self, id, RESPONSE=None): | |
897 """delete Publication id""" | |
898 self.manage_delObjects([id]) | |
899 if RESPONSE: | |
900 self.redirect(RESPONSE, 'manageRelatedProjects') | |
901 | |
60 | 902 |
63 | 903 def errorRelatedProjects(self, link): |
904 """error creating a related project""" | |
905 pt = self.editRelatedProjectsError | |
906 return pt(link=link) | |
907 | |
908 | |
81 | 909 def getInfoBlockList(self): |
910 """returns the list of related projects""" | |
911 items = self.objectValues(spec='MPIWGProject_InfoBlock') | |
912 # sort by place | |
913 items.sort(key=lambda x:int(getattr(x, 'place', 0))) | |
914 return items | |
915 | |
916 | |
917 def addInfoBlock(self, block_title=None, item_text=None, item_link=None, RESPONSE=None): | |
918 """add a MPIWGProject_InfoBlock""" | |
919 if block_title: | |
920 number = self._getLastInfoBlockNumber() + 1 | |
921 name = "infoblock_" + str(number) | |
922 while hasattr(self, name): | |
923 number += 1 | |
924 name = "infoblock_" + str(number) | |
925 | |
926 newBlock = MPIWGProject_InfoBlock(name, block_title) | |
927 # add block to project | |
928 self._setObject(name, newBlock) | |
929 obj = getattr(self, name) | |
930 obj.place = self._getLastInfoBlockNumber() + 1 | |
931 if item_text: | |
932 obj.addItem(text=item_text, link=item_link) | |
933 | |
934 if RESPONSE is not None: | |
935 self.redirect(RESPONSE, 'manageInfoBlocks') | |
936 | |
937 | |
938 def _getLastInfoBlockNumber(self): | |
939 items = self.getInfoBlockList() | |
940 if not items: | |
941 return 0 | |
942 else: | |
943 return getattr(items[-1], 'place', 0) | |
944 | |
945 | |
946 def manageInfoBlocks(self, name=None, op=None): | |
947 """manage related projects""" | |
948 self._moveObjectPlace(self.getInfoBlockList(), name, op) | |
949 | |
950 pt = self.editInfoBlocksForm | |
951 return pt() | |
952 | |
953 | |
954 def deleteInfoBlock(self, id, RESPONSE=None): | |
955 """delete Publication id""" | |
956 self.manage_delObjects([id]) | |
957 if RESPONSE: | |
958 self.redirect(RESPONSE, 'manageInfoBlocks') | |
959 | |
960 | |
63 | 961 def getAdditionalPublicationList(self): |
962 """hole publications aus der datenbank""" | |
963 query="select * from pubmanbiblio_projects where lower(key_main) = lower(%s) order by priority DESC" | |
964 return self.executeZSQL(query,[self.getId()]) | |
965 | |
966 | |
967 def hasAdditionalPublications(self): | |
968 """test if extended publication list exists""" | |
969 query="select count(*) from pubmanbiblio_projects where lower(key_main) = lower(%s)" | |
970 res= self.executeZSQL(query,[self.getId()]) | |
971 if res[0].count > 0: | |
972 return True | |
973 else: | |
974 return False | |
50 | 975 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
976 |
63 | 977 def addAdditionalPublicationsFromPubman(self,REQUEST): |
978 """addPublications from pubman""" | |
979 data=REQUEST.form | |
980 if data.get("method",None) is None: | |
981 pt = self.editAddAdditionalPublications | |
982 return pt() | |
983 | |
984 if data.get("method") == "search": | |
985 entries= self.mpiwgPubman.search(data) | |
986 pt = self.editAddAdditionalPublications | |
987 return pt(values=entries) | |
988 | |
989 if data.get("method") == "add": | |
990 return self.addEntriesToAdditionalPublicationList(data) | |
991 #pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt/staff/pubman','add_publications.zpt')).__of__(self) | |
992 | |
993 | |
994 def addEntriesToAdditionalPublicationList(self,data): | |
995 """fuege eintrage aus data zur publications liste. | |
996 | |
997 @param data Map mit escidocID --> value | |
998 value muss "add" sein damit hinzugefuegt wird""" | |
999 for key in data.keys(): | |
1000 if key.startswith('escidoc:'): | |
1001 query="INSERT INTO pubmanbiblio_projects (key_main,escidocId) values (%s,%s)" | |
1002 if data.get(key)=="add": | |
1003 self.executeZSQL(query,[self.getId(),key]) | |
1004 | |
1005 if hasattr(self,'REQUEST'): | |
1006 return self.REQUEST.response.redirect("changeAdditionalPublications") | |
1007 | |
1008 | |
1009 def changeAdditionalPublications(self,REQUEST): | |
1010 """change published publications""" | |
1011 data=REQUEST.form | |
1012 if data.get("method","change"): | |
1013 for key in data.keys(): | |
1014 splitted=key.split("__") #format escidoc_id__p fuer priority, nur escidocid | |
1015 value=data[key] | |
1016 if len(splitted)==1: | |
1017 self.deleteFromAdditionalPublicationList(key); | |
44 | 1018 |
63 | 1019 elif(splitted[1]) == "p": |
1020 self.setAdditionalPublicationPriority(splitted[0],value); | |
1021 | |
1022 pt = self.editAdditionalPublicationsForm | |
1023 return pt() | |
1024 | |
1025 | |
1026 def deleteFromAdditionalPublicationList(self,escidocid): | |
1027 """Loessche publication with escidoc id from publication list""" | |
1028 query ="DELETE FROM pubmanbiblio_projects WHERE escidocid=%s and key_main=%s" | |
1029 self.executeZSQL(query,[escidocid,self.getId()]); | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1030 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1031 |
63 | 1032 def setAdditionalPublicationPriority(self,escidocid,value): |
1033 query="update pubmanbiblio_projects set priority=%s where escidocid=%s and key_main=%s" | |
1034 try: | |
1035 value = int(value) | |
1036 self.executeZSQL(query,[value,escidocid,self.getId()]); | |
1037 except: | |
1038 logging.error("couldn't change:") | |
1039 logging.error(escidocid) | |
1040 logging.error(value) | |
44 | 1041 |
50 | 1042 |
35 | 1043 def getActualVersion(self, date=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1044 """actuelle version""" |
35 | 1045 def sortProjectsByTime(x, y): |
1046 return cmp(x[1].archiveTime, y[1].archiveTime) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1047 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1048 if not date: |
44 | 1049 if self.isCurrentVersion(): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1050 return self |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1051 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1052 return None |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1053 |
35 | 1054 # suche ob aeltere versionen vorhanden sind |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1055 |
35 | 1056 finds = self.ZopeFind(self, obj_metatypes=['MPIWGProject']) |
1057 if not finds: # wenn nicht dann teste ob die aktuelle version schon existiert hat. | |
1058 ad = getattr(self, 'creationTime', '20050101000000') | |
1059 if int(date) > int(ad): | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1060 return self |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1061 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1062 return None |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1063 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1064 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1065 finds.sort(sortProjectsByTime) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1066 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1067 for find in finds: |
35 | 1068 # gehe durch die alten Projekte und finde das entprechende |
1069 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
|
1070 return find[1] |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1071 |
35 | 1072 # kein passendes gefunden, dann teste ob das aktuelle in frage kommt |
1073 ad = getattr(self, 'creationTime', '20050101000000') | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1074 |
35 | 1075 if int(date) > int(ad): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1076 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1077 return self |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1078 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1079 return None |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1080 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1081 |
44 | 1082 def isCurrentVersion(self): |
1083 """Return if project is the current version.""" | |
1084 currentTime = time.localtime() | |
1085 # print getattr(self,'archiveTime',currentTime) | |
1086 return (getattr(self, 'archiveTime', currentTime) >= currentTime) | |
1087 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1088 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1089 def copyObjectToArchive(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1090 """kopiere aktuelles objekt ins archiv""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1091 logging.info("copytoarchive 1") |
35 | 1092 cb = self.aq_parent.manage_copyObjects(self.getId()) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1093 logging.info("copytoarchive 2") |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1094 self.manage_pasteObjects(cb) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1095 logging.info("copytoarchive 3") |
35 | 1096 actualTime = time.localtime() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1097 |
35 | 1098 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
|
1099 logging.info("copytoarchive 4") |
35 | 1100 obj = getattr(self, self.getId() + "_" + time.strftime("%Y%m%d%H%M%S", actualTime)) |
1101 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
|
1102 logging.info("copytoarchive 5") |
35 | 1103 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
|
1104 logging.info("copytoarchive 6") |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1105 obj.manage_delObjects(ids) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1106 logging.info("copytoarchive 7") |
60 | 1107 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1108 |
35 | 1109 def setArchiveTime(self, time): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1110 """set Archive Time""" |
35 | 1111 self.archiveTime = time[0:] |
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 delArchiveTime(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1115 """delete archive time""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1116 del self.archiveTime |
60 | 1117 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1118 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1119 def isActiveProject(self): |
39 | 1120 """check if the project is still active, default is true.""" |
35 | 1121 return getattr(self, 'isActiveFlag', True) |
60 | 1122 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1123 |
27 | 1124 def checkActive(self, active): |
1125 """returns if the project state matches the active state. | |
1126 active = 0 : all projects | |
1127 active = 1 : active projects | |
1128 active = 2 : inactive projects | |
1129 """ | |
35 | 1130 act = getattr(self, 'isActiveFlag', True) |
27 | 1131 return (active == 1 and act) or (active == 0) or (active == 2 and not act) |
60 | 1132 |
27 | 1133 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1134 def isArchivedProject(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1135 """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
|
1136 completed = getattr(self, 'completedAt', '') |
35 | 1137 # completed leer |
1138 if completed == "" : | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1139 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1140 if completed == 0: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1141 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1142 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1143 return True |
60 | 1144 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1145 |
27 | 1146 def checkArchived(self, archived): |
1147 """returns if the project state matches the archived state. | |
1148 archived = 0 : all projects | |
1149 archived = 1 : current projects | |
1150 archived = 2 : archived projects | |
1151 """ | |
1152 arch = self.isArchivedProject() | |
1153 return (archived == 1 and not arch) or (archived == 0) or (archived == 2 and arch) | |
60 | 1154 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1155 |
35 | 1156 def setActiveFlag(self, status=True): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1157 """set the active flag""" |
35 | 1158 self.isActiveFlag = status |
60 | 1159 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1160 |
35 | 1161 def setCompletedAt(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1162 """set the date of completion, date should be in the form DD.MM.YYYY or MM.YYYY or YYYY""" |
35 | 1163 # logging.info("DATE:"+repr(date)) |
1164 transformedDate = self.transformDate(date); | |
1165 # logging.info("transformed"+repr(transformedDate)) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1166 if transformedDate is not None: |
35 | 1167 setattr(self, "completedAt", transformedDate) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1168 return True; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1169 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1170 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1171 |
35 | 1172 def setStartedAt(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1173 """set the date of start, date should be in the form DD.MM.YYYY or MM.YYYY or YYYY""" |
35 | 1174 # logging.info("DATE:"+repr(date)) |
1175 transformedDate = self.transformDate(date); | |
1176 # logging.info("transformed"+repr(transformedDate)) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1177 if transformedDate is not None: |
35 | 1178 setattr(self, "startedAt", transformedDate) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1179 return True; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1180 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1181 return False; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1182 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1183 def getCompletedAt(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1184 """gibt das transformierte Datum zurueck, an dem das Projekt beendet wurde.""" |
35 | 1185 date = getattr(self, 'completedAt', '') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1186 if date: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1187 return self.reTransformDate(date); |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1188 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1189 return "" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1190 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1191 def getStartedAt(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1192 """gibt das transformierte Datum zurueck, an dem Projekt begonnen wurde.""" |
35 | 1193 date = getattr(self, 'startedAt', '') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1194 if date: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1195 return self.reTransformDate(date); |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1196 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1197 return ''; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1198 |
35 | 1199 def reTransformDate(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1200 """transformiert , transformdate zurueck""" |
35 | 1201 year = int(date / 10000) |
1202 month = int((date - year * 10000) / 100) | |
1203 day = int((date - year * 10000 - month * 100)) | |
1204 if (day == 0) and (month == 0): | |
1205 return """%s""" % year; | |
1206 if day == 0 : | |
1207 return """%s.%s""" % (month, year); | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1208 |
35 | 1209 return """%s.%s.%s""" % (day, month, year); |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1210 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1211 |
35 | 1212 def transformDate(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1213 """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
|
1214 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
|
1215 |
35 | 1216 if (date == None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1217 return None; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1218 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1219 |
35 | 1220 if (date.lstrip().rstrip() == "") : |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1221 return ""; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1222 |
35 | 1223 splitted = date.split(".") |
1224 length = len(splitted) | |
1225 year = 0 | |
1226 month = 0 | |
1227 day = 0 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1228 if length > 3: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1229 return ""; |
35 | 1230 if length == 3: |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1231 day = int(splitted[0]) |
35 | 1232 if length > 1: |
1233 month = int(splitted[length - 2]) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1234 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1235 if length > 0: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1236 try: |
35 | 1237 year = int(splitted[length - 1]) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1238 except: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1239 pass |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1240 |
35 | 1241 # # logging.info("month:"+(month)) |
1242 if not (0 <= month < 13): | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1243 return None; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1244 |
35 | 1245 if not(0 <= day < 32): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1246 return None; |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1247 |
35 | 1248 if (year > 0) and (year < 1900): # jahr nicht vierstellig eingegeben |
1249 year = 2000 + year; | |
1250 return year * 10000 + month * 100 + day | |
0
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 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1253 |
35 | 1254 def checkDate(self, date): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1255 """teste ob zum Zeitpunkt date eine andere version existierte""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1256 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1257 |
35 | 1258 def sortProjectsByTime(x, y): |
1259 return cmp(x[1].archiveTime, y[1].archiveTime) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1260 |
35 | 1261 # suche ob aeltere versionen vorhanden sind |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1262 |
35 | 1263 finds = self.ZopeFind(self, obj_metatypes=['MPIWGProject']) |
1264 if not finds: # wenn nicht dann teste ob die aktuelle version schon existiert hat. | |
1265 ad = getattr(self, 'creationTime', '20050101000000') | |
1266 if int(date) > int(ad): | |
1267 return self.REQUEST['URL1'] + "/" + self.getId() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1268 else: |
35 | 1269 return self.REQUEST['URL1'] + "/no_project" |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1270 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1271 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1272 finds.sort(sortProjectsByTime) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1273 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1274 for find in finds: |
35 | 1275 # gehe durch die alten Projekte und finde das entprechende |
1276 if (int(find[1].archiveTime) > int(date)) and (int(date) > int(getattr(find[1], 'creationTime', '20050101000000'))): | |
1277 return self.REQUEST['URL1'] + "/" + find[1].getId() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1278 |
35 | 1279 # kein passendes gefunden, dann teste ob das aktuelle in frage kommt |
1280 ad = getattr(self, 'creationTime', '20050101000000') | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1281 |
60 | 1282 if int(date) > int(ad): |
35 | 1283 return self.REQUEST['URL1'] + "/" + self.getId() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1284 else: |
35 | 1285 return self.REQUEST['URL1'] + "/no_project" |
60 | 1286 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1287 |
97 | 1288 def saveFromPreview(self, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1289 """save content aus preview""" |
35 | 1290 self.WEB_project_description = self.previewTemplate.WEB_project_description[0:] |
97 | 1291 #self.REQUEST.RESPONSE.redirect("./index.html") |
1292 if RESPONSE is not None: | |
1293 return self.editDescription() | |
63 | 1294 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1295 |
97 | 1296 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
|
1297 """save Edited content""" |
35 | 1298 # 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
|
1299 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1300 if preview: |
35 | 1301 kupu = preview |
97 | 1302 |
35 | 1303 # find content of body tags |
1304 start = kupu.find("<body>") | |
1305 end = kupu.find("</body>") | |
1306 newcontent = kupu[start + 6:end] | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1307 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1308 if preview: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1309 return self.preview(newcontent) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1310 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1311 self.copyObjectToArchive() |
35 | 1312 self.WEB_project_description = newcontent[0:] |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1313 |
97 | 1314 #self.REQUEST.RESPONSE.redirect("./index.html") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1315 |
97 | 1316 if RESPONSE is not None: |
1317 return self.editDescription() | |
1318 | |
60 | 1319 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1320 def getBreadcrumbs(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1321 """return list of breadcrumbs from here to the root""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1322 crumbs = [] |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1323 # skip direct parent Folder /projects/ |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1324 parent = self.aq_parent.aq_parent |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1325 # get parents breadcrumbs |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1326 if hasattr(parent, 'getBreadcrumbs'): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1327 crumbs = parent.getBreadcrumbs() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1328 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1329 # try to get acquisition URL from parent |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1330 if hasattr(parent, 'absolute_url'): |
35 | 1331 baseUrl = "%s/%s/" % (parent.absolute_url(), 'projects') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1332 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1333 baseUrl = "/en/research/projects/" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1334 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1335 # add in the internal project hierarchy |
52 | 1336 tree = self.getProjectTree() |
1337 ap = tree.getAncestorsOf(self.getNumber()) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1338 # start with grandparents |
52 | 1339 for p in ap: |
1340 label = shortenString(p.getLabel(), 13) | |
1341 crumbs.append((label, p.getUrl(baseUrl=baseUrl), p)) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1342 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1343 # add this project |
52 | 1344 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
|
1345 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1346 return crumbs |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1347 |
52 | 1348 # TODO: is this used? |
35 | 1349 def preview(self, description): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1350 """preview""" |
35 | 1351 # logging.debug("preview description=%s"%description) |
1352 tmpPro = getattr(self, "previewTemplate", None) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1353 if not tmpPro: |
35 | 1354 tmpPro = MPIWGProject("previewTemplate") |
1355 self._setObject("previewTemplate", tmpPro) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1356 for field in definedFields: |
35 | 1357 setattr(tmpPro, field, getattr(self, field)) |
1358 tmpPro.WEB_project_description = description[0:] | |
1359 tmpPro.invisible = True | |
97 | 1360 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
|
1361 return pt() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1362 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1363 |
35 | 1364 def isResponsibleScientist(self, key): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1365 """teste ob eine Person in der Liste der respl. scientists auftaucht""" |
35 | 1366 for resp in self.getResponsibleScientistsList(): |
60 | 1367 logging.debug("resp=%s key=%s"%(repr(resp),repr(key))) |
63 | 1368 # TODO: we need to get ASCII keys!! |
80 | 1369 if utf8ify(resp.get('key', '')).lower() == utf8ify(key).lower(): |
35 | 1370 return True |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1371 |
35 | 1372 return False |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1373 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1374 |
35 | 1375 def identifyNames(self, nameList): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1376 """Bekommt eine Komma oder Semikolon getrennte Liste mit Name der Form Vorname MittelName(n) Nachname |
33 | 1377 und ordnet diese dann Mitarbeiter IDs zu. |
1378 | |
1379 Returns a dict with full names as keys and a row of person objects from the database as values. | |
1380 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1381 @param nameList |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1382 """ |
35 | 1383 if nameList.find(";") > -1: # rate Trenner ist ; |
1384 names = nameList.split(";") | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1385 else: |
35 | 1386 names = nameList.split(",") |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1387 |
35 | 1388 # #nameList=nameList.replace(";",",") # falls ; als Trenner ersetze |
1389 returnNamesDict = {} | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1390 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1391 for name in names: |
35 | 1392 name = name.strip() |
123
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1393 if not name: |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1394 continue |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1395 nameSplitted = name.split(" ") |
35 | 1396 if len(nameSplitted) > 1: # vor und nachname angegeben) |
1397 lastname = nameSplitted[-1] | |
1398 firstname = nameSplitted[0] | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1399 else: |
35 | 1400 firstname = "" |
1401 lastname = nameSplitted[0] | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1402 |
35 | 1403 # finde Mitarbeiter mit den entsprechenden Name |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1404 |
35 | 1405 # firstname=self.myCapitalize(firstname).encode('utf-8') |
1406 # lastname=self.myCapitalize(lastname).encode('utf-8') | |
1407 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
|
1408 try: |
35 | 1409 # cataloggedNames=self.MembersCatalog(firstName=firstname,lastName=lastname) |
33 | 1410 # TODO: I think this does not work without firstname |
1411 # try to find names in members db by searching for sub-words | |
1412 cataloggedNames = self.executeZSQL("select * from personal_www where first_name ~* ('\m'||%s||'\M') and last_name ~* ('\m'||%s||'\M')", (firstname, lastname)) | |
1413 if len(cataloggedNames) == 0: | |
1414 # PostgreSQL has a bug with \m and words ending in non-ASCII :-( | |
1415 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
|
1416 except: |
35 | 1417 cataloggedNames = [] |
1418 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
|
1419 |
35 | 1420 if len(cataloggedNames) > 0: |
1421 returnNamesDict[name] = cataloggedNames | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1422 else: |
35 | 1423 returnNamesDict[name] = [] |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1424 |
50 | 1425 logging.debug("identified names: %s" % repr(returnNamesDict)) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1426 return returnNamesDict |
33 | 1427 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1428 |
49 | 1429 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
|
1430 """edit the project and archive the old version""" |
49 | 1431 logging.debug("editMPIWGProject(fromEdit=%s, createNewVersion=%s)"%(fromEdit,createNewVersion)) |
1432 if createNewVersion: | |
1433 self.copyObjectToArchive() # archive the object | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1434 |
35 | 1435 formdata = self.REQUEST.form |
1436 | |
1437 # set all definedFields | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1438 for x in definedFields: |
35 | 1439 if formdata.has_key(x): |
50 | 1440 setattr(self, x, unicodify(formdata[x])) |
99 | 1441 if x == 'xdata_05': |
1442 # changing project number invalidates project tree | |
1443 self.resetProjectTree() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1444 |
35 | 1445 completedAt = formdata.get('completedAt') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1446 if not self.setCompletedAt(completedAt): |
35 | 1447 RESPONSE.redirect('./editMPIWGBasisEditor?error=dateWrong') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1448 |
35 | 1449 startedAt = formdata.get('startedAt') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1450 if not self.setStartedAt(startedAt): |
35 | 1451 RESPONSE.redirect('./editMPIWGBasisEditor?error=dateWrong') |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1452 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1453 if self.REQUEST.has_key('active'): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1454 self.setActiveFlag(True) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1455 else: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1456 self.setActiveFlag(False) |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1457 |
35 | 1458 # make dict of responsible scientists |
1459 checkedScientists = {} | |
1460 names = {} | |
1461 keys = {} | |
43 | 1462 for key in formdata: |
35 | 1463 # gehe durch das Formular |
1464 keyParts = key.split("_") | |
1465 if keyParts[0] == "responsibleScientist": | |
1466 # wenn es ein Feld der Form reponsibleScientist_nr_KEY gibt | |
1467 nr = keyParts[2] | |
1468 if keyParts[1] == "name": | |
50 | 1469 names[nr] = unicodify(formdata[key]) |
35 | 1470 elif keyParts[1] == "key": |
1471 keys[nr] = formdata[key] | |
1472 | |
43 | 1473 for nr in names: |
35 | 1474 name = names[nr] |
1475 key = keys.get(nr, None) | |
1476 username = None | |
1477 if key: | |
1478 # get username from db | |
80 | 1479 member = self.en.getMPIWGRoot().getStaffFolder().getMember(key=key) |
40 | 1480 if member is not None: |
1481 username = member.getUsername() | |
35 | 1482 |
1483 # schreibe keys und namen in die Liste | |
1484 checkedScientists[names[nr]] = {'name' : name, 'key' : key, 'username' : username} | |
1485 | |
44 | 1486 # update responsibleScientistsList |
35 | 1487 self.setResponsibleScientistsList(checkedScientists) |
39 | 1488 self.updateProjectMembers() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1489 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1490 if fromEdit and (RESPONSE is not None): |
35 | 1491 return self.editBasic() |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1492 |
60 | 1493 if RESPONSE is not None: |
1494 RESPONSE.redirect('manage_main') | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1495 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1496 |
60 | 1497 def getContent(self, field, filter=None): |
1498 """Inhalt des Feldes""" | |
1499 val = getattr(self, field, '') | |
1500 if isinstance(val, list): | |
1501 val = val[0] | |
1502 | |
1503 return val | |
1504 | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1505 |
35 | 1506 def loadNewFile(self, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1507 """einlesen des neuen files""" |
35 | 1508 fileupload = self.REQUEST['fileupload'] |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1509 if fileupload: |
35 | 1510 file_name = fileupload.filename |
1511 filedata = fileupload.read() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1512 |
35 | 1513 argv = xmlhelper.proj2hash(filedata) |
1514 # print argv.keys() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1515 for arg in definedFields: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1516 |
35 | 1517 # print arg,argv[arg],getattr(self,arg) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1518 try: |
35 | 1519 temp = argv[arg][0:] |
1520 # old=getattr(self,arg) | |
1521 setattr(self, arg, temp) | |
1522 # print old,getattr(self,arg) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1523 except: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1524 """nothing""" |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1525 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1526 if RESPONSE is not None: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1527 RESPONSE.redirect('manage_main') |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1528 |
60 | 1529 |
35 | 1530 def tagTheProject(self, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1531 """TAG""" |
35 | 1532 id = self.getId(); |
1533 tmpl = getattr(self.thesaurus, "main.html") | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1534 if RESPONSE: |
35 | 1535 RESPONSE.redirect("./thesaurus/main.html?project=" + id) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1536 return |
36 | 1537 |
1538 | |
81 | 1539 def moveObjectDigitallibraryToInfoBlock(self): |
1540 """Move text from 'Object Digitallibrary' to InfoBlock.""" | |
1541 text = self.getRelatedDigitalSources() | |
1542 if text: | |
1543 logging.debug("Moving 'Object Digitallibrary' to InfoBlock: %s"%repr(text)) | |
1544 self.addInfoBlock(block_title='Related digital sources', item_text=text, item_link=None) | |
1545 delattr(self, 'xdata_11') | |
1546 | |
1547 | |
50 | 1548 def hasRelatedPublicationsOldVersion(self): |
52 | 1549 """teste ob es related publications gibt""" |
50 | 1550 ret = True; |
61 | 1551 if (getattr(self, 'WEB_related_pub', '') == ''): |
50 | 1552 ret = False; # nichts im alten feld |
1553 logging.debug("webrel:" + repr(ret)) | |
1554 if (getattr(self, 'WEB_related_pub_copied', False)): | |
1555 ret = False; # alte daten sind schon kopiert worden | |
1556 | |
1557 logging.debug("webrel_copied:" + repr(ret)) | |
1558 publications = self.ZopeFind(self, obj_metatypes=['MPIWGProject_publication']); | |
1559 | |
1560 if(len(publications) > 0): | |
1561 ret = False; # es gibt publicationen in der neuen liste | |
60 | 1562 |
50 | 1563 logging.debug("len(publ)" + repr(ret)) |
1564 | |
1565 return ret; | |
1566 | |
1567 | |
52 | 1568 def copyPublicationsToList(self, RESPONSE=None): |
1569 """copy publications in to list""" | |
60 | 1570 publicationTxt = getattr(self, 'WEB_related_pub', '') |
1571 if isinstance(publicationTxt, list): | |
1572 publicationTxt = publicationTxt[0] | |
52 | 1573 |
1574 pubSplits = publicationTxt.split("<p>") | |
1575 | |
1576 for pubSplit in pubSplits: | |
1577 pubSplit = pubSplit.replace("</p>", "") | |
1578 self.addPublication(pubSplit) | |
1579 | |
1580 setattr(self, "WEB_related_pub_copied", True); | |
1581 | |
1582 if RESPONSE: | |
1583 self.redirect(RESPONSE, 'managePublications') | |
1584 | |
1585 | |
50 | 1586 def hasInlineImage(self): |
1587 """Return the number of inline images in the description.""" | |
1588 text = self.getDescription() | |
1589 cnt = text.count('<p class="picture">') | |
1590 return cnt | |
1591 | |
1592 | |
1593 def copyImageToMargin(self, RESPONSE=None): | |
1594 """copy inline images to marginal images""" | |
1595 # getImages from WEB_project_description | |
1596 description = self.getDescription() | |
1597 | |
1598 text2 = description | |
1599 splitted = text2.split("""<p class="picture">""") | |
1600 | |
1601 imageURLs = [] | |
1602 imageCaptions = [] | |
1603 for split in splitted[1:]: | |
1604 tmp = split.split("</p>") | |
1605 # return repr(splitted[1]) | |
1606 | |
1607 try: | |
1608 imageURLs.append(tmp[0].split("\"")[1].encode('utf-8')) | |
1609 except: | |
1610 | |
1611 try: | |
1612 imageURLs.append(tmp[0].split("src=")[1].split(" ")[0].encode('utf-8')) | |
1613 except: | |
1614 imageURLs.append("") | |
1615 | |
1616 split2 = "</p>".join(tmp[1:]) | |
1617 splitted = split2.split("""<p class="picturetitle">""") | |
1618 if len(splitted) > 1: | |
1619 tmp = splitted[1].split("</p>") | |
1620 imageCaptions.append(tmp[0].encode('utf-8')) | |
1621 | |
1622 else: | |
1623 # keine caption | |
1624 imageCaptions.append("") | |
1625 | |
1626 # eintragen: | |
1627 for imageURL in imageURLs: | |
1628 if not imageURL: | |
1629 # no URL - no image | |
1630 continue | |
1631 | |
1632 filename = imageURL.split("/")[-1] | |
1633 # lege neues images object an, mit leerem bild | |
1634 | |
1635 if filename in self: | |
1636 # existiert das bild schon, dann neuen filenamen | |
1637 filename = "project_image_" + filename | |
1638 if filename in self: | |
1639 # exists too - assume its already converted | |
1640 logging.warn("copyImageToMargin: image %s exists - skipping!"%filename) | |
1641 continue | |
1642 | |
1643 self.addImage(None, imageCaptions[imageURLs.index(imageURL)], filename=filename) | |
1644 # hole die bilddaten aus der url | |
1645 url = self.absolute_url() + "/" + imageURL | |
1646 # url=self.absolute_url()+"/"+filename | |
1647 | |
1648 try: # relative url | |
1649 data = urllib.urlopen(url).read() | |
1650 except: | |
1651 try: # absolute | |
1652 data = urllib.urlopen(self.imageURL).read() | |
1653 except: | |
1654 logging.error("copyImageToMargin: can't open: %s" % url) | |
1655 | |
1656 obj = getattr(self, filename) | |
1657 obj.update_data(data) | |
1658 | |
1659 # clean description | |
1660 logging.debug("copyImageToMargin: description:%s"%repr(description)) | |
1661 dom = ET.fromstring(utf8ify("<html>%s</html>"%description)) | |
1662 for e in dom.findall(".//p[@class='picture']"): | |
1663 # remove contents | |
1664 e.clear() | |
1665 # remove tag | |
1666 e.tag = None | |
1667 | |
1668 for e in dom.findall(".//p[@class='picturetitle']"): | |
1669 # remove contents | |
1670 e.clear() | |
1671 # remove tag | |
1672 e.tag = None | |
1673 | |
1674 # remove html tag | |
1675 dom.tag = None | |
1676 # set as new description | |
1677 description = unicodify(serialize(dom)) | |
1678 logging.debug("copyImageToMargin: new description:%s"%repr(description)) | |
1679 setattr(self, 'WEB_project_description', description) | |
1680 | |
1681 if RESPONSE: | |
1682 self.redirect(RESPONSE, 'manageImages') | |
1683 | |
1684 | |
36 | 1685 def updateProjectMembers(self, updateResponsibleScientistsList=False): |
60 | 1686 """Update project-member table.""" |
1687 # projects are identified by id | |
1688 pid = self.getId() | |
1689 | |
36 | 1690 # clear projects_members table |
60 | 1691 self.executeZSQL("delete from projects_members where project_id = %s", [pid]) |
36 | 1692 |
60 | 1693 for m in self.getResponsibleScientistsList(): |
42 | 1694 memberKey = m.get('key', None) |
36 | 1695 if not memberKey or not isinstance(memberKey, basestring): |
1696 logging.error("updateProjectMembers: not a valid member key: %s" % repr(memberKey)) | |
1697 continue | |
1698 | |
60 | 1699 # fill projects_members table |
1700 self.executeZSQL("insert into projects_members (project_id, member_key) values (%s, %s)", (pid, memberKey)) | |
56 | 1701 |
1702 | |
60 | 1703 |
56 | 1704 |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1705 def manage_addMPIWGProjectForm(self): |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1706 """form for adding the project""" |
35 | 1707 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
|
1708 return pt() |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1709 |
35 | 1710 def manage_addMPIWGProject(self, id, RESPONSE=None): |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1711 """method to add a project""" |
35 | 1712 # print argv |
1713 fileupload = self.REQUEST.get('fileupload', None) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1714 if fileupload: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1715 |
35 | 1716 file_name = fileupload.filename |
1717 filedata = fileupload.read() | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1718 |
35 | 1719 argv = xmlhelper.proj2hash(filedata) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1720 |
35 | 1721 # print argv |
1722 newObj = MPIWGProject(id, argv) | |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1723 else: |
35 | 1724 newObj = MPIWGProject(id) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1725 |
35 | 1726 self._setObject(id, newObj) |
0
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1727 |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1728 if RESPONSE is not None: |
bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
casties
parents:
diff
changeset
|
1729 RESPONSE.redirect('manage_main') |
27 | 1730 |
1731 | |
33 | 1732 class MPIWGProjectFolder(ZDBInterfaceFolder): |
27 | 1733 """Folder of project objects""" |
1734 | |
35 | 1735 meta_type = "MPIWGProjectFolder" |
1736 security = ClassSecurityInfo() | |
1737 | |
27 | 1738 # cached HashTree with project hierarchy |
1739 _v_projectTree = None | |
53 | 1740 |
34 | 1741 def getProjectTree(self): |
43 | 1742 """Return the project hierarchy tree (and cache it). |
34 | 1743 |
43 | 1744 Returns HashTree instance.""" |
27 | 1745 tree = self._v_projectTree |
1746 if tree is None: | |
43 | 1747 tree = HashTree(keySeparator='.', keyFn=getInt) |
27 | 1748 for p in self.objectValues(spec='MPIWGProject'): |
51 | 1749 # add all projects |
27 | 1750 tree.add(p.getNumber(), p) |
1751 | |
1752 self._v_projectTree = tree | |
35 | 1753 # logging.debug("getProjectTree: tree=%s"%(tree.root.getSubtreeAsText())) |
27 | 1754 |
1755 return tree | |
1756 | |
1757 | |
105
246d87d33f25
CLOSED - # 79: sortierung der liste der projekte pro abteilung
casties
parents:
102
diff
changeset
|
1758 def getProjectsAsList(self, start=None, active=1, archived=1, depthFirst=True): |
43 | 1759 """Return flattened list of projects, starting from start. |
33 | 1760 |
27 | 1761 active = 0 : all projects |
1762 active = 1 : active projects | |
1763 active = 2 : inactive projects | |
1764 archived = 0 : all projects | |
1765 archived = 1 : current projects | |
1766 archived = 2 : archived projects | |
1767 """ | |
35 | 1768 # logging.debug("getProjectsAsList(start=%s,active=%s,archived=%s)"%(repr(start),active,archived)) |
34 | 1769 tree = self.getProjectTree() |
27 | 1770 node = tree.getNode(start) |
1771 if node is None: | |
1772 return [] | |
1773 | |
105
246d87d33f25
CLOSED - # 79: sortierung der liste der projekte pro abteilung
casties
parents:
102
diff
changeset
|
1774 pl = node.getSubtreeAsList(depthFirst=depthFirst) |
114
1acfcaaa5ca3
fixed HashTree.getSubTreeAsList when using breadth first.
casties
parents:
108
diff
changeset
|
1775 #logging.debug("getProjectsAsList: node=(%s,%s) pl=%s"%(node.key,node.value,[p.getNumber() for p in pl])) |
27 | 1776 # return filtered list |
1777 return [p for p in pl if (p.checkActive(active) and p.checkArchived(archived))] | |
33 | 1778 |
39 | 1779 |
1780 def getProject(self, projectNumber=None): | |
43 | 1781 """Return the matching project""" |
39 | 1782 tree = self.getProjectTree() |
1783 if projectNumber is not None: | |
1784 return tree.get(projectNumber) | |
1785 | |
1786 return None | |
1787 | |
33 | 1788 |
1789 def getProjectsOfMember(self, key, active=1, archived=1): | |
43 | 1790 """Return a list of all projects of a member. |
33 | 1791 |
1792 @param key: member's key | |
1793 active = 0 : all projects | |
1794 active = 1 : active projects | |
1795 active = 2 : inactive projects | |
1796 archived = 0 : all projects | |
1797 archived = 1 : current projects | |
1798 archived = 2 : archived projects | |
1799 """ | |
1800 projects = [] | |
1801 # search project numbers | |
1802 res = self.executeZSQL("select * from projects_members where lower(member_key) = %s", [key.lower()]) | |
77 | 1803 # find projects in folder |
33 | 1804 for r in res: |
77 | 1805 p = self.get(r.project_id, None) |
43 | 1806 # check if active |
33 | 1807 if p is not None and p.checkActive(active) and p.checkArchived(archived): |
1808 projects.append(p) | |
77 | 1809 |
1810 # sort by project number | |
79 | 1811 projects.sort(key=lambda p:[getInt(n) for n in p.getNumber().split('.')]) |
77 | 1812 return projects |
1813 | |
1814 | |
79 | 1815 def getMembersWithProjects(self, onlyActive=True): |
77 | 1816 """Return a list of all members that have projects. |
1817 | |
79 | 1818 @param onlyActive: only active members |
1819 | |
1820 Returns a list of member objects. | |
77 | 1821 """ |
79 | 1822 members = [] |
1823 sf = self.en.getStaffFolder() | |
78 | 1824 res = self.executeZSQL("select distinct member_key from projects_members") |
79 | 1825 if onlyActive: |
1826 for r in res: | |
1827 m = sf.getMember(key=r.member_key) | |
1828 if m is not None and m.isActive(): | |
1829 members.append(m) | |
1830 | |
1831 else: | |
1832 # not only active | |
1833 members = [sf.getMember(key=r.member_key) for r in res] | |
1834 | |
1835 return members | |
27 | 1836 |
1837 | |
99 | 1838 def resetProjectTree(self): |
1839 """Reset the project tree.""" | |
1840 self._v_projectTree = None | |
1841 | |
1842 | |
51 | 1843 security.declareProtected('View management screens', 'changeProjectTree') |
1844 def changeProjectTree(self, RESPONSE=None): | |
1845 """change the complete tree""" | |
1846 form=self.REQUEST.form | |
1847 onlyArchived=int(form.get("onlyArchived",0)) | |
1848 onlyActive=int(form.get("onlyActive",0)) | |
1849 dep=form.get("dep",None) | |
1850 | |
1851 fields = self.getProjectsAsList(start=dep, archived=onlyArchived, active=onlyActive) | |
1852 | |
1853 logging.info("GOT TREE!----------------------------------------------------") | |
1854 for field in form.keys(): | |
1855 | |
1856 splitted=field.split('_') | |
1857 if (len(splitted)>1) and (splitted[1]=="runningNumber"): | |
1858 #feld hat die Form Nummer_name und runnignNumber | |
1859 nr=int(splitted[0]) # nummer des Datensatzes | |
1860 project = fields[nr] | |
1861 | |
1862 # | |
1863 # change active | |
1864 # | |
1865 if form.has_key('%s_active'%nr): # active flag is set | |
1866 project.setActiveFlag(True) | |
1867 else: | |
1868 project.setActiveFlag(False) | |
1869 | |
1870 # | |
1871 # nummer hat sich geaendert | |
1872 # | |
1873 entryChanged = False; | |
1874 pronum = project.getNumber() | |
1875 formnum = form['%s_number'%nr] | |
1876 | |
1877 if not (pronum == formnum): | |
1878 logging.debug("Changed!Number+++++++++++++++++++++++++++++++++") | |
1879 logging.debug(repr(fields[nr].xdata_05)+" ---> "+ repr(form[str(nr)+'_number'])) | |
1880 entryChanged = True | |
1881 | |
1882 # | |
1883 # completed hat sich geaendert | |
1884 # | |
1885 td = project.transformDate # hole die funktion zum transformieren des datums | |
1886 formstarted = form[str(nr)+'_started'] | |
1887 formcompleted = form[str(nr)+'_completed'] | |
1888 | |
1889 if not (td(project.getCompletedAt()) == td(formcompleted)): | |
1890 logging.info(repr(td(project.getCompletedAt()))+" ---> "+ repr(td(form[str(nr)+'_completed']))) | |
1891 logging.info("Changed!Completed+++++++++++++++++++++++++++++++++") | |
1892 entryChanged = True | |
1893 | |
1894 if not (td(project.getStartedAt()) == td(formstarted)): | |
1895 logging.info(repr(td(project.getStartedAt()))+" ---> "+ repr(td(form[str(nr)+'_started']))) | |
1896 logging.info("Changed!Started+++++++++++++++++++++++++++++++++") | |
1897 entryChanged = True | |
1898 | |
1899 if entryChanged: | |
1900 logging.info("Changed!+++++++++++++++++++++++++++++++++") | |
1901 project.copyObjectToArchive() | |
1902 project.xdata_05 = formnum | |
1903 project.setCompletedAt(formcompleted) | |
1904 project.setStartedAt(formstarted) | |
1905 # reset tree | |
1906 self._v_projectTree = None | |
1907 | |
1908 if RESPONSE is not None: | |
1909 RESPONSE.redirect(self.en.MPIWGrootURL()+'/admin/showTree') | |
1910 | |
52 | 1911 |
35 | 1912 security.declareProtected('View management screens', 'updateAllProjectMembers') |
33 | 1913 def updateAllProjectMembers(self, updateResponsibleScientistsList=False): |
43 | 1914 """Re-create responsibleScientistsLists and projects_members table from all current projects.""" |
33 | 1915 # empty table |
1916 self.executeZSQL('truncate table projects_members') | |
1917 cnt = 0 | |
1918 # go through all projects | |
1919 for p in self.objectValues(spec='MPIWGProject'): | |
1920 cnt += 1 | |
35 | 1921 logging.debug("updateAllProjectMembers: updating project %s" % p) |
36 | 1922 p.updateProjectMembers(updateResponsibleScientistsList=updateResponsibleScientistsList) |
33 | 1923 |
35 | 1924 return "updated %s projects!" % cnt |
33 | 1925 |
40 | 1926 |
39 | 1927 security.declareProtected('View management screens', 'updateAllProjects') |
50 | 1928 def updateAllProjects(self, updateResponsibleScientistsList=False, RESPONSE=None): |
43 | 1929 """Patch all current projects for legacy problems.""" |
39 | 1930 cnt = 0 |
50 | 1931 fulllog = "" |
39 | 1932 # go through all projects |
123
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1933 for id, project in self.ZopeFind(self, obj_metatypes=['MPIWGProject'], search_sub=1): |
50 | 1934 log = "" |
39 | 1935 cnt += 1 |
1936 # | |
1937 # hasRelatedPublicationsOldVersion | |
1938 # | |
1939 if project.hasRelatedPublicationsOldVersion(): | |
49 | 1940 log += "%s: update relatedPublicationsOldVersion!\n"%project.getId() |
39 | 1941 logging.debug("updateAllProjects(%s): update relatedPublicationsOldVersion!"%project.getId()) |
1942 project.copyPublicationsToList() | |
1943 | |
1944 # | |
60 | 1945 # create responsibleScientistsList automatically |
39 | 1946 # |
60 | 1947 if updateResponsibleScientistsList: |
39 | 1948 newScientists = {} |
65 | 1949 names = project.identifyNames(project.getResponsibleScientists()) |
60 | 1950 for name in names: |
123
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1951 msg = "%s: regenerating responsibleScientistsList: name=%s\n"%(project.getId(), repr(name)) |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1952 log += msg |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1953 logging.debug(msg) |
60 | 1954 members = names[name] |
1955 if len(members) > 0: | |
1956 # take the first matching name | |
123
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1957 username = None |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1958 if members[0].e_mail: |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1959 username = re.sub('@mpiwg-berlin\.mpg\.de', '', members[0].e_mail) |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
1960 newScientists[name] = {'name': name, 'key' : members[0].key, 'username' : username} |
39 | 1961 |
1962 project.setResponsibleScientistsList(newScientists) | |
60 | 1963 |
1964 else: | |
1965 # | |
1966 # old format responsibleScientistsList | |
1967 # | |
1968 memberlist = project.getResponsibleScientistsList() | |
1969 if len(memberlist) > 0 and isinstance(memberlist[0], tuple): | |
1970 log += "%s: updating memberlist!\n"%project.getId() | |
1971 logging.debug("updateAllProjects(%s): updating memberlist" % project.getId()) | |
1972 newScientists = {} | |
1973 for m in memberlist: | |
1974 name = m[0] | |
1975 key = m[1] | |
1976 username = None | |
1977 if key: | |
1978 if isinstance(key, list): | |
1979 key = key[0] | |
1980 | |
1981 # get username from db | |
80 | 1982 member = self.en.getMPIWGRoot().getStaffFolder().getMember(key=key) |
60 | 1983 if member is not None: |
1984 username = member.getUsername() | |
1985 | |
1986 newScientists[name] = {'name': name, 'key' : key, 'username' : username} | |
1987 | |
1988 # set new list | |
1989 project.setResponsibleScientistsList(newScientists) | |
39 | 1990 |
1991 # | |
49 | 1992 # old inline images |
1993 # | |
1994 if project.hasInlineImage(): | |
1995 log += "%s: has inlineImage!\n"%project.getId() | |
1996 logging.debug("updateAllProjects(%s): has inlineImage!"%project.getId()) | |
1997 try: | |
1998 project.copyImageToMargin() | |
1999 except Exception, e: | |
2000 log += "%s: ERROR in copyImageToMargin!\n"%project.getId() | |
2001 logging.debug("updateAllProjects(%s): ERROR in copyImageToMargin: %s"%(project.getId(), e)) | |
2002 | |
2003 | |
2004 # | |
39 | 2005 # remove old attributes |
2006 # | |
2007 if hasattr(project, 'definedFields'): | |
49 | 2008 log += "%s: has definedFields!\n"%project.getId() |
39 | 2009 logging.debug("updateAllProjects(%s): has definedFields!"%project.getId()) |
2010 delattr(project, 'definedFields') | |
61 | 2011 |
45 | 2012 # |
61 | 2013 # update related publications |
45 | 2014 # |
61 | 2015 for pub in project.getPublicationList(): |
62 | 2016 if not pub.text: |
2017 msg = "%s: publication has no text: %s!\n"%(project.getId(), pub) | |
2018 log += msg | |
2019 logging.warn(msg) | |
2020 if not pub.link: | |
2021 msg = "%s: publication has no link either! Deleting: %s!\n"%(project.getId(), pub) | |
2022 log += msg | |
2023 logging.error(msg) | |
2024 project.deletePublication(pub.getId()) | |
2025 | |
2026 else: | |
2027 # hasLinkToBookPage updates the bookId | |
2028 pub.hasLinkToBookPage() | |
61 | 2029 |
81 | 2030 |
2031 # | |
2032 # update RelatedDigitalSources | |
2033 # | |
2034 project.moveObjectDigitallibraryToInfoBlock() | |
2035 | |
50 | 2036 # |
2037 # unicodify | |
2038 # | |
2039 for field in ('WEB_title', 'xdata_01', 'xdata_07', 'xdata_08', 'xdata_11', 'xdata_12', 'xdata_13', | |
2040 'WEB_project_description', 'WEB_related_pub'): | |
2041 text = getattr(project, field, None) | |
2042 if isinstance(text, str): | |
2043 log += "%s: has non-unicode field %s\n"%(project.getId(), field) | |
2044 logging.debug("updateAllProjects(%s): has has non-unicode field %s\n"%(project.getId(), field)) | |
2045 setattr(project, field, unicodify(text)) | |
2046 | |
2047 fulllog += log | |
2048 if RESPONSE is not None: | |
2049 RESPONSE.write(log) | |
62 | 2050 |
123
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2051 # |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2052 # remove obsolete static class members (does this make sense?) |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2053 # |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2054 if hasattr(MPIWGProject, 'responsibleScientistsList'): |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2055 log += "MPIWGProject has class member responsibleScientistsList\n" |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2056 logging.debug("MPIWGProject has class member responsibleScientistsList\n") |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2057 del MPIWGProject.responsibleScientistsList |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2058 |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2059 if hasattr(MPIWGProject, 'projectThumb'): |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2060 log += "MPIWGProject has class member projectThumb\n" |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2061 logging.debug("MPIWGProject has class member projectThumb\n") |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2062 del MPIWGProject.projectThumb |
220f37701e8d
fix problem with empty responsible scientists field.
casties
parents:
114
diff
changeset
|
2063 |
50 | 2064 log += "\n DONE! updated %s projects!" % cnt |
2065 fulllog += log | |
2066 if RESPONSE is not None: | |
2067 RESPONSE.write(log) | |
2068 RESPONSE.flush() | |
2069 else: | |
2070 return fulllog | |
39 | 2071 |
33 | 2072 |
27 | 2073 def manage_addMPIWGProjectFolderForm(self): |
29 | 2074 """form for adding a MPIWGProjectFolder""" |
27 | 2075 pt = PageTemplateFile('zpt/project/manage_add_MPIWGProjectFolder', globals()).__of__(self) |
2076 return pt() | |
2077 | |
35 | 2078 def manage_addMPIWGProjectFolder(self, id, title, RESPONSE=None): |
29 | 2079 """add a MPIWGProjectFolder""" |
35 | 2080 newObj = MPIWGProjectFolder(id, title) |
27 | 2081 |
35 | 2082 self._setObject(id, newObj) |
27 | 2083 |
2084 if RESPONSE is not None: | |
2085 RESPONSE.redirect('manage_main') | |
2086 |