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