File:  [Repository] / MPIWGWeb / MPIWGProjects.py
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Feb 4 10:03:33 2004 UTC (20 years, 9 months ago) by dwinter
Branches: dwinter
CVS tags: first
first import product fuer www des insitutes

"""This files contains the class MPIWG Projects"""
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate

import MPIWGStaff
import string
import re

import xmlhelper # Methoden zur Verwaltung der projekt xmls
from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder

definedFields=['WEB_title','xdata_01','xdata_02','xdata_03','xdata_04','xdata_05','xdata_06','xdata_07','xdata_08','xdata_09','xdata_10','xdata_11','xdata_12','xdata_13','WEB_project_header','WEB_project_description','WEB_related_pub']

checkFields = ['xdata_01']

def sortF(x,y):

    return cmp(x[1],y[1])

class MPIWGRoot(Folder):
    """Stammordner für den Web-Server"""

    folders=['MPIWGProject','Folder']
    meta_type='MPIWGRoot'
    
    def __init__(self, id, title):
        """init"""
        self.id=id
        self.title=title

    def getProjectFields(self,fieldName,folder=None):
        """getListofFieldNames"""
        ret=[]
        #print "FN",fieldName
        if not folder:
            folder=self
        for object in folder.__dict__:

            obj=getattr(folder,object)
            if hasattr(obj,'meta_type'):
                
                if obj.meta_type=='MPIWGProject':
                    
                    ret.append((obj,obj.getContent(fieldName)))
                if obj.meta_type in self.folders:
                    
                    ret += self.getProjectFields(fieldName,obj)
        
        ret.sort(sortF)
        
        return ret

    manage_options = Folder.manage_options+(
        {'label':'Import Persons','action':'importNamesForm'},
        )
    
    def importNamesForm(self):
        """Form"""
        pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGNamesForm.zpt').__of__(self)
        return pt()

    def importNames(self,fileupload,folderName,RESPONSE=None):
        """import komma-sep list email,lastName,firstName"""
        project=getattr(self,folderName)
        
        for line in fileupload.readlines():
            print line
            splitted=line.split(",")
            if not (splitted[0]==""):
                newObj=MPIWGStaff.MPIWGStaff(splitted[0],splitted[1],splitted[2])
                try:
                    project._setObject(splitted[0],newObj)
                except:
                    print "not done:",splitted[0]
        if RESPONSE is not None:
            RESPONSE.redirect('manage_main')

    def givePersonList(self,name):
        """check if person is in personfolder and return list of person objects"""

       
            
        splitted=name.split(",") # version nachname, vorname...
        if len(splitted)>1:
            lastName=splitted[0] 
            firstName=splitted[1]
        else: 
            splitted=name.split(" ") #version vorname irgenwas nachnamae
        
            lastName=splitted[len(splitted)-1]
            firstName=string.join(splitted[0:len(splitted)-1])

        objs=[]

        print  self.members 
        for x in self.members.__dict__:
            obj=getattr(self.members,x)
            if hasattr(obj,'lastName') and hasattr(obj,'firstName'):
                
                if (re.match(".*"+obj.lastName+".*",lastName) or re.match(".*"+lastName+".*",obj.lastName)) and (re.match(obj.firstName+".*",firstName) or re.match(firstName+".*",obj.firstName)):
                    
                    objs.append((obj,lastName+", "+firstName))

        return objs


    def personCheck(self,names):
        """all persons for list"""
        print "names",names
        splitted=names.split(";")
        ret={}
        for name in splitted:

            if not (name==""):
                ret[name]=self.givePersonList(name)

        print "RET",ret
        return ret

    def giveCheckList(self,person,fieldname):
        """return checklist"""
        #print "GCL",fieldname
        if fieldname=='xdata_01':
            x=self.personCheck(person.getContent(fieldname))
            #print "GCLBACKX",x
            return x
        

    def isCheckField(self,fieldname):
        """return chechfield"""
        
        return (fieldname in checkFields)

    
    
        
def manage_addMPIWGRootForm(self):
    """form for adding the root"""
    pt=PageTemplateFile('Products/MPIWGWeb/zpt/addMPIWGRootForm.zpt').__of__(self)
    return pt()

def manage_addMPIWGRoot(self,id,title,RESPONSE=None):
    """add a root folder"""
    newObj=MPIWGRoot(id,title)
    self._setObject(id,newObj)

    if RESPONSE is not None:
        RESPONSE.redirect('manage_main')
        

class MPIWGProject(Folder):
    """Class for Projects"""

    meta_type='MPIWGProject'

  

    def generateTemplate(self,RESPONSE=None):
        """Erzeuge Template für defined fields not_used"""

        id="index_html"
        title=id
        if self._getOb('index_html'):
            self._delObject('index_html')

        
        newObj=ZopePageTemplate(id,'TEXT')
        self._setObject(id,newObj)
        #self.manage_addPageTemplate(id,title)
        if RESPONSE is not None:
            RESPONSE.redirect('manage_main')
            
    def __init__(self, id, argv):
        """initieriere classe"""
        
        self.id=id
        self.title=id
        for arg in definedFields:
            
            setattr(self,arg,argv[arg])
            """NP"""
    manage_options = Folder.manage_options+(
        {'label':'Load New File','action':'loadNewFileForm'},
        {'label':'Edit ProjectInfo','action':'editMPIWGProjectForm'},
        {'label':'Edit BasisInfo','action':'editMPIWGBasisForm'},
        {'label':'Edit Publications','action':'editMPIWGRelatedPublicationsForm'},
        )

    def getDataFields(self):
        """giveListofDatafields"""
        ret=[]
        for x in range(1,14):
            ret.append('xdata_%02i'%x)
        return ret
            
    def getDefinedFields(self):
        """show all defined fields"""
        
        return definedFields

    def getAttribute(self,field):
        """get attrbiute"""
        return getattr(self,field)

    def getContent(self,field):
        """Inhalt des Feldes"""
        
        text=u''
        #print "FIELD",field
        for x in getattr(self,field):
            #print "HIHIIII"
            
            try:
                text +=x
            except:
                try:
                    text =x
                except:
                    text="ERROR"
        #print "TEXT",text  
        return text
    
    def show_html(self):
        """simple index"""
        #return "HI"
        pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGProject_index.zpt').__of__(self)
        return pt()

    def editMPIWGProjectForm(self):
        """editform"""
        pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGProject.zpt').__of__(self)
        return pt()

    def editMPIWGBasisForm(self):
        """editform"""
        pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGBasis.zpt').__of__(self)
        return pt()
    def editMPIWGRelatedPublicationsForm(self):
        """Edit related Publications"""
        pt=PageTemplateFile('Products/MPIWGWeb/zpt/edit_MPIWGRelatedPublications.zpt').__of__(self)
        return pt()
        
    def editMPIWGProject(self,RESPONSE=None):
        """edit the project"""
        
        #return self.REQUEST
        for x in definedFields:
            if self.REQUEST.has_key(x):
                
                setattr(self,x,[self.REQUEST[x]])
            
        if RESPONSE is not None:
            RESPONSE.redirect('manage_main')

        
    def loadNewFileForm(self):
        """Neues XML-File einlesen"""
        pt=PageTemplateFile('Products/MPIWGWeb/zpt/MPIWGProject_newfile.zpt').__of__(self)
        return pt()

    def loadNewFile(self,RESPONSE=None):
        """einlesen des neuen files"""
        fileupload=self.REQUEST['fileupload']
        if fileupload:
            file_name=fileupload.filename
            filedata=fileupload.read()

            argv=xmlhelper.proj2hash(filedata)
            #print argv.keys()
            for arg in definedFields:
                
                #print arg,argv[arg],getattr(self,arg)
                try:
                    temp=argv[arg][0:]
                    #old=getattr(self,arg)
                    setattr(self,arg,temp)
                    #print old,getattr(self,arg)
                except:
                    """nothing"""
                    
        if RESPONSE is not None:
            RESPONSE.redirect('manage_main')

def manage_addMPIWGProjectForm(self):
    """form for adding the project"""
    pt=PageTemplateFile('Products/MPIWGWeb/zpt/addMPIWGProjectForm.zpt').__of__(self)
    return pt()

def manage_addMPIWGProject(self,id,RESPONSE=None):
    """method to add a project"""
    #print argv
    fileupload=self.REQUEST['fileupload']
    if fileupload:
        file_name=fileupload.filename
	filedata=fileupload.read()
        
        argv=xmlhelper.proj2hash(filedata)

        #print argv

    newObj=MPIWGProject(id,argv)

    self._setObject(id,newObj)


    if RESPONSE is not None:
        RESPONSE.redirect('manage_main')

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>