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