changeset 123:220f37701e8d

fix problem with empty responsible scientists field. existing non-empty responsibleScientistsList should clear out when editing.
author casties
date Thu, 30 May 2013 09:01:14 +0200
parents 4a54537ddcf7
children e06e6cc7f2d3 4a8a532a05ba
files MPIWGProjects.py
diffstat 1 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGProjects.py	Wed May 29 15:56:44 2013 +0200
+++ b/MPIWGProjects.py	Thu May 30 09:01:14 2013 +0200
@@ -522,6 +522,9 @@
         scientistsList = []
         for name in nameList:
             name = unicodify(name.strip())
+            if not name:
+                continue
+            
             logging.debug("setResponsibleScientistsList: name=%s"%repr(name))
             if name in nameDict:
                 # found in data
@@ -532,6 +535,8 @@
         
         logging.debug("setResponsibleScientistsList: nameDict=%s new list=%s"%(repr(nameDict),repr(scientistsList)))
         self.responsibleScientistsList = scientistsList
+        # force update of the Properties list in the ZopeDB
+        self._p_changed = 1
         
               
     def getInvolvedScholars(self):
@@ -1385,6 +1390,8 @@
        
         for name in names:
             name = name.strip()
+            if not name:
+                continue
             nameSplitted = name.split(" ")
             if len(nameSplitted) > 1:  # vor und nachname angegeben)
                 lastname = nameSplitted[-1]
@@ -1911,7 +1918,6 @@
         # go through all projects
         for p in self.objectValues(spec='MPIWGProject'):
             cnt += 1
-            memberlist = []
             logging.debug("updateAllProjectMembers: updating project %s" % p)
             p.updateProjectMembers(updateResponsibleScientistsList=updateResponsibleScientistsList)
 
@@ -1924,7 +1930,7 @@
         cnt = 0
         fulllog = ""
         # go through all projects
-        for (id, project) in self.ZopeFind(self, obj_metatypes=['MPIWGProject'], search_sub=1):
+        for id, project in self.ZopeFind(self, obj_metatypes=['MPIWGProject'], search_sub=1):
             log = ""
             cnt += 1
             #
@@ -1942,11 +1948,16 @@
                 newScientists = {}
                 names = project.identifyNames(project.getResponsibleScientists())
                 for name in names:
-                    logging.debug("updateAllProjectMembers: name=%s" % repr(name))
+                    msg = "%s: regenerating responsibleScientistsList: name=%s\n"%(project.getId(), repr(name))
+                    log += msg
+                    logging.debug(msg)
                     members = names[name]
                     if len(members) > 0:
                         # take the first matching name
-                        newScientists[name] = {'name': name, 'key' : members[0].key, 'username' : re.sub('@mpiwg-berlin\.mpg\.de', '', members[0].e_mail)}
+                        username = None
+                        if members[0].e_mail:
+                            username = re.sub('@mpiwg-berlin\.mpg\.de', '', members[0].e_mail)
+                        newScientists[name] = {'name': name, 'key' : members[0].key, 'username' : username}
                     
                 project.setResponsibleScientistsList(newScientists)
                 
@@ -2037,6 +2048,19 @@
             if RESPONSE is not None:
                 RESPONSE.write(log)
                            
+        #
+        # remove obsolete static class members (does this make sense?)
+        #
+        if hasattr(MPIWGProject, 'responsibleScientistsList'):
+            log += "MPIWGProject has class member responsibleScientistsList\n"
+            logging.debug("MPIWGProject has class member responsibleScientistsList\n")
+            del MPIWGProject.responsibleScientistsList
+            
+        if hasattr(MPIWGProject, 'projectThumb'):
+            log += "MPIWGProject has class member projectThumb\n"
+            logging.debug("MPIWGProject has class member projectThumb\n")
+            del MPIWGProject.projectThumb
+            
         log += "\n DONE! updated %s projects!" % cnt
         fulllog += log
         if RESPONSE is not None: