import os def liseScript(mainobj, idclicked="0"): """ liseScript """ pictid = int(idclicked) - 1 if pictid < 0: pictid = 0 session = mainobj.REQUEST.SESSION openchaplist = session.get("openchaplist", []) newopenchaplist = 0 if len(openchaplist) < 1: newopenchaplist = 1 # openchaplist = [] # newopenchaplist = 1 pagelist = mainobj.pagelist filelist = mainobj.filenames filelistindex = 0; # fetch the current picture pictfile = '' if IsStr(pagelist[pictid].picturelink): if len(pagelist[pictid].picturelink) > 0: pictfile = pagelist[pictid].picturelink else: if IsInt(pagelist[pictid].pictindex): filelistindex = int(pagelist[pictid].pictindex) pictfile = filelist[filelistindex] else: pictfile = 'this_is the_no_fucking_picture_error' else: if IsInt(pagelist[pictid].pictindex): filelistindex = int(pagelist[pictid].pictindex) pictfile = filelist[filelistindex] else: pictfile = 'this_is the_no_fucking_picture_error' mainobj.currpict = pictfile thelength = len(pagelist) counter = 0 currlevel = 0; # build the list which is used to open / close the chapters if pagelist[pictid].type == 'C': for i in pagelist: if newopenchaplist == 1: if i.level == 0: openchaplist.append(1) else: openchaplist.append(0) else: if counter == pictid: currlevel = pagelist[counter + 1].level if openchaplist[counter + 1] == 0: for j in range(counter + 1, thelength): if pagelist[j].level < currlevel: break; else: if pagelist[j].level == currlevel: openchaplist[j] = 1 else: if openchaplist[counter + 1] == 1: for j in range(counter + 1, thelength): if pagelist[j].level < currlevel: break; else: openchaplist[j] = 0 counter = counter + 1 bid = session.getBrowserIdManager().getBrowserId() outtext = "" counter = 0 for i in pagelist: if openchaplist[counter] == 1: for j in range(0, i.level): outtext = outtext + "   " outtext = outtext + "" + i.name + "
" counter = counter + 1 outtext = outtext + "

" # write back list of open pages to session session["openchaplist"] = openchaplist return outtext ######################################################################################## def IsInt(str): """ Is the given string an Integer? """ try: int(str) except ValueError: return 0 else: return 1 ######################################################################################## def IsStr(str): """ Is the given string really a string? """ try: str + '' except: return 0 else: return 1