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