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