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