comparison MPIWGRoot_deleted_methods.py @ 65:63184d71c014

lots of cleaning up.
author casties
date Fri, 03 May 2013 18:23:01 +0200
parents dc41deabc8f8
children
comparison
equal deleted inserted replaced
64:b5ff783027d6 65:63184d71c014
1
2 def sortWeight(x,y):
3 x1=int(getattr(x[1],'weight','0'))
4 y1=int(getattr(y[1],'weight','0'))
5 return cmp(x1,y1)
6
7
8
1 class MPIWGRoot_deleted: 9 class MPIWGRoot_deleted:
2 10
3 11
4 def removeStopWords(self,xo): 12 def removeStopWords(self,xo):
5 """remove stop words from xo""" 13 """remove stop words from xo"""
851 def getAttribute(self, field): 859 def getAttribute(self, field):
852 """get attrbiute""" 860 """get attrbiute"""
853 return getattr(self, field) 861 return getattr(self, field)
854 862
855 863
856 864
865
866 def redirectIndex_html(self,request):
867 #return request['URL1']+'/index_html'
868
869 return urllib.urlopen(request['URL1']+'/index_html').read()
870
871
872 def formatBibliography(self,here,found):
873 """format"""
874 return formatBibliography(here,found)
875
876 def getValue(self,fieldStr):
877 """Inhalt des Feldes"""
878
879 if type(fieldStr)==StringType:
880 field=fieldStr
881 else:
882 field=fieldStr[0]
883 try:
884 if field[len(field)-1]==";":
885 field=field[0:len(field)-1]
886 except:
887
888 """nothing"""
889 field=re.sub(r';([^\s])','; \g<1>',field)
890 return field.encode('utf-8')
891
892
893
894 def sortedNames(self,list):
895 """sort names"""
896
897 def sortLastName(x_c,y_c):
898 try:
899 x=urllib.unquote(x_c).encode('utf-8','ignore')
900 except:
901 x=urllib.unquote(x_c)
902
903 try:
904 y=urllib.unquote(y_c).encode('utf-8','ignore')
905 except:
906 x=urllib.unquote(y_c)
907
908
909
910 try:
911 last_x=x.split()[len(x.split())-1]
912 last_y=y.split()[len(y.split())-1]
913
914 except:
915
916 last_x=""
917 last_y=""
918
919
920
921 if last_x<last_y:
922 return 1
923 elif last_x>last_y:
924 return -1
925 else:
926 return 0
927
928 list.sort(sortLastName)
929 list.reverse()
930
931 return list
932
933 def createOrUpdateId_raw(self):
934 """create sequence to create ids for bibliography"""
935 debug=None
936 #suche groesste existierende id
937 founds=self.ZSQLQuery("select id from bibliography")
938
939 if founds:
940 ids=[int(x.id[1:]) for x in founds]
941 maximum=max(ids)
942
943 id_raw=self.ZSQLQuery("select nextval('id_raw')",debug=debug)
944
945 if id_raw:
946 self.ZSQLQuery("drop sequence id_raw",debug=debug)
947
948 self.ZSQLQuery("create sequence id_raw start %i"%(maximum+1),debug=debug)
949
950
951 def queryLink(self,link):
952 """append querystring to the link"""
953 return "%s?%s"%(link,self.REQUEST.get('QUERY_STRING',''))
954
955 def getKategory(self,url):
956 """kategorie"""
957 splitted=url.split("/")
958 return splitted[4]
959
960 def isType(self,object,meta_type):
961 """teste ob ein object vom meta_type ist."""
962 return (object.meta_type==meta_type)
963
964
965 # TODO: remove
966 def replaceNotEmpty(self,format,field):
967 """replace not empty"""
968 if field and (not field.lstrip()==''):
969 return format%field
970 #return self.decode(format%field)
971 else:
972 return ""
973
974
975 def urlQuote(self,str):
976 """quote"""
977 return urllib.quote(str)
978
979 def urlUnQuote(self,str):
980 """quote"""
981 return urllib.unquote(str)
982
983 def updateInstitutsbiliography(self):
984 """update the Institutsbibliogrpahy"""
985 self.upDateSQL('personalwww.xml')
986 return "<html><body>DONE</body></html>"
987
988
989
990
991
992
993 def getAllMembers(self):
994 #ret=[]
995
996 def sorter(x,y):
997 return cmp(x[0].lower(),y[0].lower())
998
999 results=self.MembersCatalog({'isPublished':True})
1000
1001 ret=[(unicodify(", ".join([proj.lastName, proj.firstName])), proj.getKey) for proj in results]
1002
1003 ret.sort(sorter)
1004 return ret
1005
1006
1007 def printAllMembers(self):
1008 """print"""
1009 members=self.getAllMembers()
1010 ret=""
1011 for x in members:
1012 ret+="<p>%s</p>"%x
1013 return ret
1014
1015
1016 def makeList(self,entry):
1017 """makes a list out of one entry or repeat a list"""
1018 if type(entry) is StringType:
1019 return [entry]
1020 else:
1021 return entry
1022
1023 def getTreeRSS(self,dep=None,date=None,onlyActive=1,onlyArchived=0):
1024 """generateTree"""
1025 rss="""<?xml version="1.0" encoding="utf-8"?>
1026 <rss version="2.0">
1027 <channel>"""
1028
1029 for obj in self.getTree(dep, date, onlyActive, onlyArchived):
1030 linkStr="""<link>http://www.mpiwg-berlin.mpg.de/en/research/projects/%s</link>"""
1031 rss+="""<item>"""
1032 rss+=linkStr%obj[3].getId()
1033 rss+="""</item>"""
1034 if hasattr(obj[3],'publicationList'):
1035 rss+="""<item>"""
1036 rss+=linkStr%(obj[3].getId()+"/publicationList");
1037 rss+="""</item>"""
1038 rss+="""</channel>
1039 </rss>"""
1040
1041 return rss
1042
1043
1044 def getRelativeUrlFromPerson(self,list):
1045 """get urls to person list"""
1046 ret=[]
1047 persons=list.split(";")
1048 for person in persons:
1049
1050 if len(person)>1: #nicht nur Trennzeichen
1051 splitted=person.split(",")
1052 if len(splitted)==1:
1053 splitted=person.split(" ")
1054 splittedNew=[re.sub(r'\s(.*)','$1',split) for split in splitted]
1055 if splittedNew[0]=='':
1056 del splittedNew[0]
1057 search=string.join(splittedNew,' AND ')
1058
1059 if not search=='':
1060
1061 try:
1062 proj=self.MembersCatalog({'title':search})
1063 except:
1064 proj=None
1065
1066 if proj:
1067 #ret.append("<a href=%s >%s</a>"%(proj[0].absolute_url,person.encode('utf-8')))
1068 ret.append("<a href=%s >%s</a>"%('members/'+proj[0].id+'/index.html',person))
1069 else:
1070 #ret.append("%s"%person.encode('utf-8'))
1071 ret.append("%s"%person)
1072 return string.join(ret,";")
1073
1074 def getMemberIdFromKey(self,key):
1075 """gibt die ensprechende id im members Ordner zum key"""
1076
1077 if key=="":
1078 return ""
1079 try:
1080 key=utf8ify(key)
1081 catalogged=self.MembersCatalog({'getKey':key})
1082 if len(catalogged)==0:
1083 return ""
1084 else:
1085 return catalogged[0].getObject().getId()
1086
1087 except:
1088 return ""
1089
1090 def subNavStatic(self,obj):
1091 """subnav" von self"""
1092 subs=self.ZopeFind(obj,obj_metatypes=['MPIWGTemplate','MPIWGLink'])
1093 subret=[]
1094
1095 for x in subs:
1096 if not(x[1].title==""):
1097 subret.append(x)
1098 subret.sort(sortWeight)
1099 return subret
1100
1101
1102 def isActive(self,name):
1103 """teste ob subnavigation aktiv"""
1104 for part in self.REQUEST['URL'].split("/"):
1105 if part==name:
1106 return True
1107 return False
1108
1109
1110 def getSectionStyle(self, name, style=""):
1111 """returns a string with the given style + '-sel' if the current section == name"""
1112 if self.getSection() == name:
1113 return style + '-sel'
1114 else:
1115 return style
1116
1117