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