Mercurial > hg > MPIWGWeb
comparison MPIWGRoot.py @ 51:d456fe185649
more work on projects. more cleanup.
author | casties |
---|---|
date | Tue, 30 Apr 2013 12:49:26 +0200 |
parents | e30a4bd074db |
children | 1ed79b33200c |
comparison
equal
deleted
inserted
replaced
50:e30a4bd074db | 51:d456fe185649 |
---|---|
119 bt['staticHTML'] = False | 119 bt['staticHTML'] = False |
120 | 120 |
121 return bt | 121 return bt |
122 | 122 |
123 | 123 |
124 def versionHeaderEN(self): | |
125 """version header text""" | |
126 | |
127 date= self.REQUEST.get('date',None) | |
128 if date: | |
129 txt="""<h2>This pages shows the project which existed at %s</h2>"""%str(date) | |
130 return txt | |
131 return "" | |
132 | |
133 def versionHeaderDE(self): | |
134 """version header text""" | |
135 date= self.REQUEST.get('date',None) | |
136 if date: | |
137 txt="""<h2>Auf dieser Seite finden Sie die Projekte mit Stand vom %s</h2>"""%str(date) | |
138 return "" | |
139 | |
140 | |
141 def createOrUpdateId_raw(self): | 124 def createOrUpdateId_raw(self): |
142 """create sequence to create ids for bibliography""" | 125 """create sequence to create ids for bibliography""" |
143 debug=None | 126 debug=None |
144 #suche groesste existierende id | 127 #suche groesste existierende id |
145 founds=self.ZSQLQuery("select id from bibliography") | 128 founds=self.ZSQLQuery("select id from bibliography") |
163 def getKategory(self,url): | 146 def getKategory(self,url): |
164 """kategorie""" | 147 """kategorie""" |
165 splitted=url.split("/") | 148 splitted=url.split("/") |
166 return splitted[4] | 149 return splitted[4] |
167 | 150 |
168 def generateUrlProject(self,url,project=None): | |
169 """erzeuge aus absoluter url, relative des Projektes""" | |
170 if project: | |
171 splitted=url.split("/") | |
172 length=len(splitted) | |
173 short=splitted[length-2:length] | |
174 | |
175 base=self.REQUEST['URL3']+"/"+"/".join(short) | |
176 | |
177 else: | |
178 findPart=url.find("/projects/") | |
179 base=self.REQUEST['URL1']+"/"+url[findPart:] | |
180 | |
181 | |
182 return base | |
183 | |
184 def isNewCapital(self,text=None,reset=None): | 151 def isNewCapital(self,text=None,reset=None): |
185 | 152 |
186 if text: | 153 if text: |
187 text=text.upper() | 154 text=text.upper() |
188 if reset: | 155 if reset: |
404 | 371 |
405 def urlUnQuote(self,str): | 372 def urlUnQuote(self,str): |
406 """quote""" | 373 """quote""" |
407 return urllib.unquote(str) | 374 return urllib.unquote(str) |
408 | 375 |
409 | |
410 | |
411 def getProjectsByFieldContent(self,fieldName,fieldContentsEntry, date=None): | |
412 """gib alle Projekte aus mit Value von field mit fieldName enthaelt ein Element der Liste fieldContents""" | |
413 def sort(x,y): | |
414 return cmp(x.WEB_title[0],y.WEB_title[0]) | |
415 | |
416 if type(fieldContentsEntry) is StringType: | |
417 fieldContentsTmp=[fieldContentsEntry] | |
418 else: | |
419 fieldContentsTmp=fieldContentsEntry | |
420 | |
421 fieldContents=[] | |
422 for x in fieldContentsTmp: | |
423 fieldContents.append(" AND ".join(x.split())) | |
424 projects=self.ProjectCatalog({fieldName:string.join(fieldContents,' AND')}) | |
425 #print projects | |
426 #ret=[x for x in projects] | |
427 ret=[] | |
428 for x in projects: | |
429 obj=x.getObject() | |
430 obj=obj.getActualVersion(date) | |
431 if obj and (not getattr(obj,'invisible',None)): | |
432 #if not (x in ret): | |
433 ret.append(x) | |
434 | |
435 ret.sort(sort) | |
436 return ret | |
437 | 376 |
438 def changeMPIWGRootForm(self): | 377 def changeMPIWGRootForm(self): |
439 """edit""" | 378 """edit""" |
440 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMPIWGRootForm')).__of__(self) | 379 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMPIWGRootForm')).__of__(self) |
441 return pt() | 380 return pt() |
531 RESPONSE.setHeader('Content-Type', "application/octet-stream") | 470 RESPONSE.setHeader('Content-Type', "application/octet-stream") |
532 | 471 |
533 return "\n".join(retList); | 472 return "\n".join(retList); |
534 | 473 |
535 | 474 |
536 | |
537 | |
538 def getProjectFields(self,fieldName,date=None,folder=None,sort=None): | |
539 """getListofFieldNames""" | |
540 ret=[] | |
541 | |
542 objects=self.ZopeFind(self.projects,obj_metatypes=['MPIWGProject'],search_sub=0) | |
543 | |
544 | |
545 for object in objects: | |
546 obj=object[1] | |
547 obj=obj.getActualVersion(date) | |
548 if obj and (not getattr(obj,'invisible',None)): | |
549 if fieldName=="WEB_title_or_short": | |
550 | |
551 if len(obj.getContent('xdata_07'))<3: # hack weil z.Z. manchmal noch ein Trennzeichen ; oder , im Feld statt leer | |
552 fieldNameTmp="WEB_title" | |
553 else: | |
554 fieldNameTmp="xdata_07" | |
555 else: | |
556 fieldNameTmp=fieldName | |
557 | |
558 ret.append((obj,obj.getContent(fieldNameTmp))) | |
559 | |
560 | |
561 if sort=="int": | |
562 ret.sort(sortI) | |
563 elif sort=="stopWords": | |
564 | |
565 ret.sort(sortStopWords(self)) | |
566 | |
567 else: | |
568 ret.sort(sortF) | |
569 | |
570 return ret | |
571 | |
572 def showNewProjects(self): | |
573 projects=[] | |
574 for objs in self.getProjectFields('WEB_title_or_short'): # Get all Projets | |
575 if objs[0].xdata_05 and (objs[0].xdata_05[0] == ""): | |
576 | |
577 projects.append(objs) | |
578 | |
579 return projects | |
580 | 475 |
581 | 476 |
582 def updatePublicationDB(self,personId=None): | 477 def updatePublicationDB(self,personId=None): |
583 """updates the publication db, i.e. copy year and type into the main table""" | 478 """updates the publication db, i.e. copy year and type into the main table""" |
584 | 479 |
812 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','updatePersonalwww_check.zpt')).__of__(self) | 707 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','updatePersonalwww_check.zpt')).__of__(self) |
813 return pt() | 708 return pt() |
814 | 709 |
815 | 710 |
816 | 711 |
817 def reindexCatalogs(self,RESPONSE=None): | |
818 """reindex members and project catalog""" | |
819 | |
820 | |
821 try: | |
822 | |
823 self.ProjectCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1']) | |
824 logger("MPIWG Root (reindexCatalog: projects)",logging.INFO,"DONE") | |
825 except: | |
826 logger("MPIWG Root (reindexCatalog: projects)",logging.WARNING," %s %s"%sys.exc_info()[:2]) | |
827 | |
828 try: | |
829 | |
830 self.MembersCatalog.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1']) | |
831 logger("MPIWG Root (reindexCatalog: members)",logging.INFO,"DONE") | |
832 except: | |
833 logger("MPIWG Root (reindexCatalog: members)",logging.WARNING," %s %s"%sys.exc_info()[:2]) | |
834 | |
835 | |
836 # | |
837 # try: | |
838 # | |
839 # self.fulltextProjectsMembers.manage_catalogReindex(self.REQUEST,RESPONSE,self.REQUEST['URL1']) | |
840 # logger("MPIWG Root (reindexCatalog: fulltextProjectsMembers)",logging.INFO,"DONE") | |
841 # except: | |
842 # logger("MPIWG Root (reindexCatalog: fulltextProjectsMembers)",logging.WARNING," %s %s"%sys.exc_info()[:2]) | |
843 # | |
844 # | |
845 # | |
846 # | |
847 | |
848 | |
849 if RESPONSE: | |
850 RESPONSE.redirect('manage_main') | |
851 | |
852 | |
853 | |
854 | 712 |
855 def getAllMembers(self): | 713 def getAllMembers(self): |
856 #ret=[] | 714 #ret=[] |
857 | 715 |
858 def sorter(x,y): | 716 def sorter(x,y): |
898 rss+=linkStr%(obj[3].getId()+"/publicationList"); | 756 rss+=linkStr%(obj[3].getId()+"/publicationList"); |
899 rss+="""</item>""" | 757 rss+="""</item>""" |
900 rss+="""</channel> | 758 rss+="""</channel> |
901 </rss>""" | 759 </rss>""" |
902 | 760 |
903 | |
904 return rss | 761 return rss |
905 | 762 |
906 def getTree(self,dep=None,date=None,onlyActive=0,onlyArchived=0): | |
907 """generate Tree from project list | |
908 als Liste, jeder Eintrag ist ein Tupel ,(Tiefe, ProjektNummer,ProjektObject | |
909 onlyActive = 0 : alle Projekte | |
910 onlyActive = 1 : nur active Projekte | |
911 onlyActive = 2: nur inactive Projekte | |
912 | |
913 onlyArchived=0: alle Projekte | |
914 onlyArchived= 1 : nur aktuelle Projekte | |
915 onlyArchived = 2: nur archivierte Projekte | |
916 | |
917 department fuer das Tree geholt werden soll | |
918 """ | |
919 logging.debug("MPIWGRoot.getTree()") | |
920 | |
921 returnListTmp=[] | |
922 returnList=[] | |
923 | |
924 for project in self.getProjectFields('xdata_05',sort="int",date=date): # get Projects sorted by xdata_05 | |
925 | |
926 for idNr in project[1].split(";"): # more than one number | |
927 if not idNr=="": | |
928 splittedId=idNr.split(".") | |
929 depth=len(splittedId) | |
930 nr=idNr | |
931 #title=project[0].WEB_title | |
932 title=[project[0].getContent('WEB_title')] | |
933 #print title | |
934 | |
935 if idNr[0]=="x": # kompatibilitaet mit alter Konvention, x vor der Nummer macht project inactive | |
936 project[0].setActiveFlag(False) | |
937 | |
938 if (not dep) or (splittedId[0]==dep): #falls dep gesetzt ist nur dieses hinzufuegen. | |
939 | |
940 if (onlyActive==0): | |
941 returnListTmp.append((depth,nr,title,project[0])) | |
942 elif (onlyActive==1) and project[0].isActiveProject(): #nur active projekte | |
943 returnListTmp.append((depth,nr,title,project[0])) | |
944 elif (onlyActive==2) and (not project[0].isActiveProject()): #nur active projekte | |
945 returnListTmp.append((depth,nr,title,project[0])) | |
946 | |
947 | |
948 #filter jetzt die Liste nach Archived oder nicht | |
949 for entry in returnListTmp: | |
950 if (onlyArchived==0): | |
951 returnList.append(entry) | |
952 elif (onlyArchived==1) and (not entry[3].isArchivedProject()): #nur active projekte | |
953 returnList.append(entry) | |
954 elif (onlyArchived==2) and (entry[3].isArchivedProject()): #nur active projekte | |
955 returnList.append(entry) | |
956 | |
957 | |
958 return returnList | |
959 | |
960 | |
961 | |
962 def changePosition(self,treeId,select,RESPONSE=None): | |
963 """Change Postion Entry""" | |
964 numbers=[] | |
965 | |
966 # Suche hoechste bisherige nummer | |
967 projects=self.getProjectFields('xdata_05') # get Projects sorted by xdata_05 | |
968 #print "pj",projects | |
969 for project in projects: #suche alle subtrees der treeId | |
970 #print treeId | |
971 | |
972 founds=re.match(treeId+"\.(.*)",project[1].split(";")[0]) | |
973 if founds: | |
974 #print "x",founds.group(0),len(founds.group(0).split(".")) | |
975 if len(founds.group(0).split("."))==len(treeId.split("."))+1: # nur ein punkt mehr, d.h. untere ebene | |
976 try: | |
977 numbers.append(int(founds.group(0).split(".")[len(founds.group(0).split("."))-1])) | |
978 except: | |
979 numbers.append(int(0)) | |
980 | |
981 try: | |
982 highest=max(numbers) | |
983 except: | |
984 highest=0 | |
985 projects=self.showNewProjects() | |
986 for i in self.makeList(select): | |
987 highest+=10 | |
988 projects[int(i)][0].xdata_05=treeId+"."+str(highest) | |
989 | |
990 | |
991 if RESPONSE is not None: | |
992 RESPONSE.redirect('showTree') | |
993 | |
994 def changeTree(self,RESPONSE=None): | |
995 """change the complete tree""" | |
996 form=self.REQUEST.form | |
997 hashList={} | |
998 onlyArchived=int(form.get("onlyArchived",0)) | |
999 onlyActive=int(form.get("onlyActive",0)) | |
1000 dep=form.get("dep",None) | |
1001 | |
1002 fields=self.getTree(dep=dep,onlyArchived=onlyArchived,onlyActive=onlyActive) | |
1003 | |
1004 logging.info("GOT TREE!----------------------------------------------------") | |
1005 for field in form.keys(): | |
1006 | |
1007 splitted=field.split('_') | |
1008 if (len(splitted)>1) and (splitted[1]=="runningNumber"): #feld hat die Form Nummer_name und runnignNumber | |
1009 | |
1010 | |
1011 nr=int(splitted[0]) # nummer des Datensatzes | |
1012 currentEntry = fields[nr] | |
1013 | |
1014 if form.has_key(str(nr)+'_active'): # active flag is set | |
1015 fields[nr][3].setActiveFlag(True) | |
1016 else: | |
1017 fields[nr][3].setActiveFlag(False) | |
1018 | |
1019 #nummer hat sich geaendert | |
1020 | |
1021 entryChanged = False; | |
1022 | |
1023 if isinstance(fields[nr][3].xdata_05,list): #for some reasons somtimes the content of the field is a list with one entry. | |
1024 fields[nr][3].xdata_05=fields[nr][3].xdata_05[0] | |
1025 | |
1026 if not (fields[nr][3].xdata_05==form[str(nr)+'_number']): | |
1027 logging.info("Changed!Number+++++++++++++++++++++++++++++++++") | |
1028 logging.info(repr(fields[nr][3].xdata_05)+" ---> "+ repr(form[str(nr)+'_number'])) | |
1029 fields[nr][3].xdata_05=form[str(nr)+'_number'] | |
1030 entryChanged = True | |
1031 | |
1032 #completed har sich geaendert | |
1033 | |
1034 td = fields[nr][3].transformDate # hole die funktion zum transformieren des datums | |
1035 | |
1036 if not (td(fields[nr][3].getCompletedAt())==td(form[str(nr)+'_completed'])): | |
1037 fields[nr][3].setCompletedAt(form[str(nr)+'_completed']) | |
1038 logging.info(repr(td(fields[nr][3].getCompletedAt()))+" ---> "+ repr(td(form[str(nr)+'_completed']))) | |
1039 logging.info("Changed!Completed+++++++++++++++++++++++++++++++++") | |
1040 entryChanged = True | |
1041 | |
1042 if not (td(fields[nr][3].getStartedAt())==td(form[str(nr)+'_started'])): | |
1043 fields[nr][3].setStartedAt(form[str(nr)+'_started']) | |
1044 | |
1045 logging.info(repr(td(fields[nr][3].getStartedAt()))+" ---> "+ repr(td(form[str(nr)+'_started']))) | |
1046 logging.info("Changed!Started+++++++++++++++++++++++++++++++++") | |
1047 entryChanged = True | |
1048 | |
1049 | |
1050 if entryChanged: | |
1051 logging.info("Changed!+++++++++++++++++++++++++++++++++") | |
1052 fields[nr][3].copyObjectToArchive() | |
1053 | |
1054 | |
1055 if RESPONSE is not None: | |
1056 RESPONSE.redirect('showTree') | |
1057 | |
1058 def getProjectWithId(self,id): | |
1059 fields=self.getProjectFields('xdata_05') | |
1060 for field in fields: | |
1061 if field[1]==id: | |
1062 return field[0] | |
1063 | |
1064 return None | |
1065 | |
1066 | |
1067 | |
1068 | 763 |
1069 def getRelativeUrlFromPerson(self,list): | 764 def getRelativeUrlFromPerson(self,list): |
1070 """get urls to person list""" | 765 """get urls to person list""" |
1071 ret=[] | 766 ret=[] |
1072 persons=list.split(";") | 767 persons=list.split(";") |