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