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