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