Mercurial > hg > documentViewer
comparison documentViewer.py @ 607:cb5a9c4f5e3a
CLOSED - # 268: display of subdocuments
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/268
author | casties |
---|---|
date | Fri, 14 Dec 2012 17:28:31 -0500 |
parents | ef1d0a1fc9fa |
children | 0c6056271654 |
comparison
equal
deleted
inserted
replaced
606:37ad612edf5a | 607:cb5a9c4f5e3a |
---|---|
158 from Products.zogiLib.zogiLib import zogiLib | 158 from Products.zogiLib.zogiLib import zogiLib |
159 zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book") | 159 zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book") |
160 templateFolder['zogilib'] = zogilib | 160 templateFolder['zogilib'] = zogilib |
161 #templateFolder._setObject('zogilib',zogilib) | 161 #templateFolder._setObject('zogilib',zogilib) |
162 except Exception, e: | 162 except Exception, e: |
163 logging.error("Unable to create zogiLib for zogilib: "+str(e)) | 163 logging.error("Unable to create zogiLib for 'zogilib': "+str(e)) |
164 | 164 |
165 try: | 165 try: |
166 # assume MetaDataFolder instance is called metadata | 166 # assume MetaDataFolder instance is called metadata |
167 self.metadataService = getattr(self, 'metadata') | 167 self.metadataService = getattr(self, 'metadata') |
168 except Exception, e: | 168 except Exception, e: |
635 # check numPages | 635 # check numPages |
636 if docinfo.get('numPages', 0) == 0: | 636 if docinfo.get('numPages', 0) == 0: |
637 if docinfo.get('numTextPages', 0) > 0: | 637 if docinfo.get('numTextPages', 0) > 0: |
638 # replace with numTextPages (text-only?) | 638 # replace with numTextPages (text-only?) |
639 docinfo['numPages'] = docinfo['numTextPages'] | 639 docinfo['numPages'] = docinfo['numTextPages'] |
640 | |
641 # min and max page no | |
642 docinfo['minPageNo'] = docinfo.get('minPageNo', 1) | |
643 docinfo['maxPageNo'] = docinfo.get('maxPageNo', docinfo['numPages']) | |
640 | 644 |
641 # normalize path | 645 # normalize path |
642 if 'imagePath' in docinfo and not docinfo['imagePath'].startswith('/'): | 646 if 'imagePath' in docinfo and not docinfo['imagePath'].startswith('/'): |
643 docinfo['imagePath'] = '/' + docinfo['imagePath'] | 647 docinfo['imagePath'] = '/' + docinfo['imagePath'] |
644 | 648 |
681 texttool = texttool[0] | 685 texttool = texttool[0] |
682 | 686 |
683 # image dir | 687 # image dir |
684 imageDir = getMDText(texttool.get('image', None)) | 688 imageDir = getMDText(texttool.get('image', None)) |
685 docPath = getMDText(docinfo.get('documentPath', None)) | 689 docPath = getMDText(docinfo.get('documentPath', None)) |
686 if imageDir and docPath: | 690 if imageDir: |
687 imageDir = os.path.join(docPath, imageDir) | 691 if imageDir.startswith('/'): |
688 imageDir = imageDir.replace('/mpiwg/online', '', 1) | 692 # absolute path |
689 docinfo['imagePath'] = imageDir | 693 imageDir = imageDir.replace('/mpiwg/online', '', 1) |
694 docinfo['imagePath'] = imageDir | |
695 | |
696 elif docPath: | |
697 # relative path | |
698 imageDir = os.path.join(docPath, imageDir) | |
699 imageDir = imageDir.replace('/mpiwg/online', '', 1) | |
700 docinfo['imagePath'] = imageDir | |
701 | |
702 # start and end page (for subdocuments of other documents) | |
703 imgStartNo = getMDText(texttool.get('image-start-no', None)) | |
704 minPageNo = getInt(imgStartNo, 1) | |
705 docinfo['minPageNo'] = minPageNo | |
706 | |
707 imgEndNo = getMDText(texttool.get('image-end-no', None)) | |
708 if imgEndNo: | |
709 docinfo['maxPageNo'] = getInt(imgEndNo) | |
690 | 710 |
691 # old style text URL | 711 # old style text URL |
692 textUrl = getMDText(texttool.get('text', None)) | 712 textUrl = getMDText(texttool.get('text', None)) |
693 if textUrl and docPath: | 713 if textUrl and docPath: |
694 if urlparse.urlparse(textUrl)[0] == "": #keine url | 714 if urlparse.urlparse(textUrl)[0] == "": #keine url |
722 | 742 |
723 # odd pages are left | 743 # odd pages are left |
724 docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left')) | 744 docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left')) |
725 | 745 |
726 # number of title page (default 1) | 746 # number of title page (default 1) |
727 docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1)) | 747 docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', minPageNo)) |
728 | 748 |
729 # old presentation stuff | 749 # old presentation stuff |
730 presentation = getMDText(texttool.get('presentation', None)) | 750 presentation = getMDText(texttool.get('presentation', None)) |
731 if presentation and docPath: | 751 if presentation and docPath: |
732 if presentation.startswith('http:'): | 752 if presentation.startswith('http:'): |
862 pageinfo['viewLayers'] = [viewLayer] | 882 pageinfo['viewLayers'] = [viewLayer] |
863 | 883 |
864 pageinfo['viewLayer'] = viewLayer | 884 pageinfo['viewLayer'] = viewLayer |
865 pageinfo['tocMode'] = tocMode | 885 pageinfo['tocMode'] = tocMode |
866 | 886 |
887 minPageNo = docinfo.get('minPageNo', 1) | |
888 | |
867 # pf takes precedence over pn | 889 # pf takes precedence over pn |
868 if pf: | 890 if pf: |
869 pageinfo['pf'] = pf | 891 pageinfo['pf'] = pf |
870 pn = getPnForPf(docinfo, pf) | 892 pn = getPnForPf(docinfo, pf) |
871 # replace pf in request params (used for creating new URLs) | 893 # replace pf in request params (used for creating new URLs) |
872 self.REQUEST.form.pop('pf', None) | 894 self.REQUEST.form.pop('pf', None) |
873 self.REQUEST.form['pn'] = pn | 895 self.REQUEST.form['pn'] = pn |
874 else: | 896 else: |
875 pn = getInt(pn, 1) | 897 pn = getInt(pn, minPageNo) |
876 pf = getPfForPn(docinfo, pn) | 898 pf = getPfForPn(docinfo, pn) |
877 pageinfo['pf'] = pf | 899 pageinfo['pf'] = pf |
878 | 900 |
879 pageinfo['pn'] = pn | 901 pageinfo['pn'] = pn |
880 rows = int(rows or self.thumbrows) | 902 rows = int(rows or self.thumbrows) |
881 pageinfo['rows'] = rows | 903 pageinfo['rows'] = rows |
882 cols = int(cols or self.thumbcols) | 904 cols = int(cols or self.thumbcols) |
883 pageinfo['cols'] = cols | 905 pageinfo['cols'] = cols |
884 grpsize = cols * rows | 906 grpsize = cols * rows |
885 pageinfo['groupsize'] = grpsize | 907 pageinfo['groupsize'] = grpsize |
886 # is start is empty use one around pn | 908 # if start is empty use one around pn |
887 start = getInt(start, default=(math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1))) | 909 grouppn = math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1) |
888 # int(current / grpsize) * grpsize +1)) | 910 # but not smaller than minPageNo |
911 start = getInt(start, max(grouppn, minPageNo)) | |
889 pageinfo['start'] = start | 912 pageinfo['start'] = start |
890 # get number of pages | 913 # get number of pages |
891 np = int(docinfo.get('numPages', 0)) | 914 numPages = int(docinfo.get('numPages', 0)) |
892 if np == 0: | 915 if numPages == 0: |
893 # try numTextPages | 916 # try numTextPages |
894 np = docinfo.get('numTextPages', 0) | 917 numPages = docinfo.get('numTextPages', 0) |
895 if np != 0: | 918 if numPages != 0: |
896 docinfo['numPages'] = np | 919 docinfo['numPages'] = numPages |
920 | |
921 maxPageNo = docinfo.get('maxPageNo', numPages) | |
922 logging.debug("minPageNo=%s maxPageNo=%s start=%s numPages=%s"%(minPageNo,maxPageNo,start,numPages)) | |
923 np = maxPageNo | |
897 | 924 |
898 # cache table of contents | 925 # cache table of contents |
899 pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30)) | 926 pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30)) |
900 pageinfo['numgroups'] = int(np / grpsize) | 927 pageinfo['numgroups'] = int(np / grpsize) |
901 if np % grpsize > 0: | 928 if np % grpsize > 0: |
904 pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl' | 931 pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl' |
905 oddScanLeft = docinfo.get('oddPage', 'left') != 'right' | 932 oddScanLeft = docinfo.get('oddPage', 'left') != 'right' |
906 # add zeroth page for two columns | 933 # add zeroth page for two columns |
907 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) | 934 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) |
908 pageinfo['pageZero'] = pageZero | 935 pageinfo['pageZero'] = pageZero |
909 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) | 936 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=minPageNo, maxIdx=np) |
910 # more page parameters | 937 # more page parameters |
911 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') | 938 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
912 if docinfo.get('pageNumbers'): | 939 if docinfo.get('pageNumbers'): |
913 # get original page numbers | 940 # get original page numbers |
914 pageNumber = docinfo['pageNumbers'].get(pn, None) | 941 pageNumber = docinfo['pageNumbers'].get(pn, None) |
936 return pageinfo | 963 return pageinfo |
937 | 964 |
938 | 965 |
939 def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): | 966 def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): |
940 """returns dict with array of page information for one screenfull of thumbnails""" | 967 """returns dict with array of page information for one screenfull of thumbnails""" |
968 logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx)) | |
941 batch = {} | 969 batch = {} |
942 grpsize = rows * cols | 970 grpsize = rows * cols |
943 if maxIdx == 0: | 971 if maxIdx == 0: |
944 maxIdx = start + grpsize | 972 maxIdx = start + grpsize |
945 | 973 |
946 nb = int(math.ceil(maxIdx / float(grpsize))) | 974 np = maxIdx - minIdx + 1 |
975 nb = int(math.ceil(np / float(grpsize))) | |
947 # list of all batch start and end points | 976 # list of all batch start and end points |
948 batches = [] | 977 batches = [] |
949 if pageZero: | 978 if pageZero: |
950 ofs = 0 | 979 ofs = minIdx - 1 |
951 else: | 980 else: |
952 ofs = 1 | 981 ofs = minIdx |
953 | 982 |
954 for i in range(nb): | 983 for i in range(nb): |
955 s = i * grpsize + ofs | 984 s = i * grpsize + ofs |
956 e = min((i + 1) * grpsize + ofs - 1, maxIdx) | 985 e = min((i + 1) * grpsize + ofs - 1, maxIdx) |
957 batches.append({'start':s, 'end':e}) | 986 batches.append({'start':s, 'end':e}) |
958 | 987 |
959 batch['batches'] = batches | 988 batch['batches'] = batches |
960 | 989 |
961 pages = [] | 990 pages = [] |
962 if pageZero and start == 1: | 991 if pageZero and start == minIdx: |
963 # correct beginning | 992 # correct beginning |
964 idx = 0 | 993 idx = minIdx - 1 |
965 else: | 994 else: |
966 idx = start | 995 idx = start |
967 | 996 |
968 for r in range(rows): | 997 for r in range(rows): |
969 row = [] | 998 row = [] |
979 else: | 1008 else: |
980 row.insert(0, page) | 1009 row.insert(0, page) |
981 | 1010 |
982 pages.append(row) | 1011 pages.append(row) |
983 | 1012 |
984 if start > 1: | 1013 if start > minIdx: |
985 batch['prevStart'] = max(start - grpsize, 1) | 1014 batch['prevStart'] = max(start - grpsize, minIdx) |
986 else: | 1015 else: |
987 batch['prevStart'] = None | 1016 batch['prevStart'] = None |
988 | 1017 |
989 if start + grpsize <= maxIdx: | 1018 if start + grpsize <= maxIdx: |
990 batch['nextStart'] = start + grpsize | 1019 batch['nextStart'] = start + grpsize |