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